diff options
author | Romain Porte <microjoe@microjoe.org> | 2017-11-11 18:29:55 +0100 |
---|---|---|
committer | Boris Bobrov <breton@cynicmansion.ru> | 2017-11-11 20:41:58 +0300 |
commit | f2b32fbf6a331ecdcabbb31f891687de498eaab3 (patch) | |
tree | 0f91a132661f32a77f0df938ec4a3b2328091132 /mediagoblin/tests/test_api.py | |
parent | f2b4760bd50d4ad6ec5899e90f655c2f4cf0884a (diff) | |
download | mediagoblin-f2b32fbf6a331ecdcabbb31f891687de498eaab3.tar.lz mediagoblin-f2b32fbf6a331ecdcabbb31f891687de498eaab3.tar.xz mediagoblin-f2b32fbf6a331ecdcabbb31f891687de498eaab3.zip |
Added tests for custom file name using API
This adds a new test and verify that the old test has the
"unknown.<extension>" format. As funny as it seems, the "image/jpeg"
Content-Type will generate a ".jpe" extension but I was expecting a more
common ".jpg" extension. This may be a bug, but this is not the subject
of this patch.
Diffstat (limited to 'mediagoblin/tests/test_api.py')
-rw-r--r-- | mediagoblin/tests/test_api.py | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/mediagoblin/tests/test_api.py b/mediagoblin/tests/test_api.py index 90873cb9..c05a58bc 100644 --- a/mediagoblin/tests/test_api.py +++ b/mediagoblin/tests/test_api.py @@ -61,7 +61,7 @@ class TestAPI(object): return response, json.loads(response.body.decode()) - def _upload_image(self, test_app, image): + def _upload_image(self, test_app, image, custom_filename=None): """ Uploads and image to MediaGoblin via pump.io API """ data = open(image, "rb").read() headers = { @@ -69,6 +69,8 @@ class TestAPI(object): "Content-Length": str(len(data)) } + if custom_filename is not None: + headers["X-File-Name"] = custom_filename with self.mock_oauth(): response = test_app.post( @@ -126,8 +128,34 @@ class TestAPI(object): assert image["objectType"] == "image" # Check that we got the response we're expecting - response, _ = self._post_image_to_feed(test_app, image) + response, data = self._post_image_to_feed(test_app, image) assert response.status_code == 200 + assert data["object"]["fullImage"]["url"].endswith("unknown.jpe") + assert data["object"]["image"]["url"].endswith("unknown.thumbnail.jpe") + + def test_can_post_image_custom_filename(self, test_app): + """ Tests that an image can be posted to the API with custom filename """ + # First request we need to do is to upload the image + response, image = self._upload_image(test_app, GOOD_JPG, + custom_filename="hello.jpg") + + # I should have got certain things back + assert response.status_code == 200 + + assert "id" in image + assert "fullImage" in image + assert "url" in image["fullImage"] + assert "url" in image + assert "author" in image + assert "published" in image + assert "updated" in image + assert image["objectType"] == "image" + + # Check that we got the response we're expecting + response, data = self._post_image_to_feed(test_app, image) + assert response.status_code == 200 + assert data["object"]["fullImage"]["url"].endswith("hello.jpg") + assert data["object"]["image"]["url"].endswith("hello.thumbnail.jpg") def test_unable_to_upload_as_someone_else(self, test_app): """ Test that can't upload as someoen else """ |