Example #1
0
    def test_can_get_actual_id_when_stored_with_large_id(self):
        path = '/image/e5bcf126-791b-4375-9f73-925ab8b9fb5g'

        self.put(path, {'Content-Type': 'image/jpeg'}, valid_image())
        response = self.get(path + '123456', {'Accept': 'image/jpeg'})

        expect(response.code).to_equal(200)

        expect(response.body).to_be_similar_to(valid_image())
Example #2
0
    def test_can_retrieve_existing_image(self):
        response = self.post(self.base_uri, {'Content-Type': 'image/jpeg'}, valid_image())
        expect(response.code).to_equal(201)

        location = response.headers['Location']
        response = self.get(location, {'Accept': 'image/jpeg'})
        expect(response.code).to_equal(200)
        expect(response.body).to_be_similar_to(valid_image())
        expect(response.headers['Content-Type']).to_equal('image/jpeg')
Example #3
0
    def test_can_get_actual_id_when_stored_with_large_id(self):
        path = '/image/e5bcf126-791b-4375-9f73-925ab8b9fb5g'

        self.put(path, {'Content-Type': 'image/jpeg'}, valid_image())
        response = self.get(path + '123456', {'Accept': 'image/jpeg'})

        expect(response.code).to_equal(200)

        expect(response.body).to_be_similar_to(valid_image())
Example #4
0
    def test_can_retrieve_existing_image(self):
        response = self.post(self.base_uri, {'Content-Type': 'image/jpeg'},
                             valid_image())
        expect(response.code).to_equal(201)

        location = response.headers['Location']
        response = self.get(location, {'Accept': 'image/jpeg'})
        expect(response.code).to_equal(200)
        expect(response.body).to_be_similar_to(valid_image())
        expect(response.headers['Content-Type']).to_equal('image/jpeg')
Example #5
0
    async def test_can_retrieve_existing_image(self):
        response = await self.async_post(self.base_uri,
                                         {"Content-Type": "image/jpeg"},
                                         valid_image())
        expect(response.code).to_equal(201)

        location = response.headers["Location"]
        response = await self.async_get(location, {"Accept": "image/jpeg"})
        expect(response.code).to_equal(200)
        expect(response.body).to_be_similar_to(valid_image())
        expect(response.headers["Content-Type"]).to_equal("image/jpeg")
Example #6
0
    async def test_can_get_actual_id_when_stored_with_large_id(self):
        path = "/image/e5bcf126-791b-4375-9f73-925ab8b9fb5g"

        await self.async_put(path, {"Content-Type": "image/jpeg"},
                             valid_image())
        response = await self.async_get(path + "123456",
                                        {"Accept": "image/jpeg"})

        expect(response.code).to_equal(200)

        expect(response.body).to_be_similar_to(valid_image())
Example #7
0
    def test_cant_get_truncated_id_when_stored_with_large_id(self):
        image_id = 'e5bcf126-791b-4375-9f73-925ab8b9fb5f'
        path = '/image/%s' % image_id

        response = self.put(path, {'Content-Type': 'image/jpeg'}, valid_image())
        expect(response.code).to_equal(204)

        response = self.get(path[:7 + 32], {'Accept': 'image/jpeg'})
        expect(response.code).to_equal(404)
Example #8
0
    def test_cant_get_truncated_id_when_stored_with_large_id(self):
        image_id = 'e5bcf126-791b-4375-9f73-925ab8b9fb5f'
        path = '/image/%s' % image_id

        response = self.put(path, {'Content-Type': 'image/jpeg'},
                            valid_image())
        expect(response.code).to_equal(204)

        response = self.get(path[:7 + 32], {'Accept': 'image/jpeg'})
        expect(response.code).to_equal(404)
Example #9
0
    def test_modifying_existing_image_to_heavy_image_fails(self):
        response = self.post(self.base_uri, {'Content-Type': 'image/jpeg'}, valid_image())
        location = response.headers['Location']

        response = self.put(location, {'Content-Type': 'image/jpeg'}, too_heavy_image())
        expect(response.code).to_equal(412)

        expected_path = self.get_path_from_location(location)
        expected_path = self.upload_storage.path_on_filesystem(expected_path)
        expect(expected_path).to_exist()
        expect(expected_path).to_be_the_same_as(valid_image_path)
Example #10
0
    async def test_cant_get_truncated_id_when_stored_with_large_id(self):
        image_id = "e5bcf126-791b-4375-9f73-925ab8b9fb5f"
        path = f"/image/{image_id}"

        response = await self.async_put(path, {"Content-Type": "image/jpeg"},
                                        valid_image())
        expect(response.code).to_equal(204)

        response = await self.async_get(path[:7 + 32],
                                        {"Accept": "image/jpeg"})
        expect(response.code).to_equal(404)
Example #11
0
    def test_modifying_existing_image_to_heavy_image_fails(self):
        response = self.post(self.base_uri, {'Content-Type': 'image/jpeg'},
                             valid_image())
        location = response.headers['Location']

        response = self.put(location, {'Content-Type': 'image/jpeg'},
                            too_heavy_image())
        expect(response.code).to_equal(412)

        expected_path = self.get_path_from_location(location)
        expected_path = self.upload_storage.path_on_filesystem(expected_path)
        expect(expected_path).to_exist()
        expect(expected_path).to_be_the_same_as(valid_image_path)
Example #12
0
    def test_can_post_image_without_filename(self):
        filename = self.default_filename + '.jpg'
        response = self.post(self.base_uri, {'Content-Type': 'image/jpeg'}, valid_image())

        expect(response.code).to_equal(201)

        expect(response.headers).to_include('Location')
        expect(response.headers['Location']).to_match(self.base_uri + r'/[^\/]{32}/' + filename)

        expected_path = self.get_path_from_location(response.headers['Location'])
        expected_path = self.upload_storage.path_on_filesystem(expected_path)
        expect(expected_path).to_exist()
        expect(expected_path).to_be_the_same_as(valid_image_path)
Example #13
0
    def test_can_delete_existing_image(self):
        filename = self.default_filename + '.jpg'
        response = self.post(self.base_uri, {'Content-Type': 'image/jpeg'}, valid_image())
        expect(response.code).to_equal(201)

        location = response.headers['Location']
        image_id = re.compile(self.base_uri + r'/([^\/]{32})/' + filename).search(location).group(1)
        image_location = self.upload_storage.path_on_filesystem(image_id)
        expect(image_location).to_exist()

        response = self.delete(location, {})
        expect(response.code).to_equal(204)

        expect(image_location).not_to_exist()
Example #14
0
    def test_can_post_from_html_form(self):
        filename = 'crocodile2.jpg'
        image = ('media', filename, valid_image())
        response = self.post_files(self.base_uri, {'Slug': 'another_filename.jpg'}, (image, ))

        expect(response.code).to_equal(201)

        expect(response.headers).to_include('Location')
        expect(response.headers['Location']).to_match(self.base_uri + r'/[^\/]{32}/' + filename)

        expected_path = self.get_path_from_location(response.headers['Location'])
        expected_path = self.upload_storage.path_on_filesystem(expected_path)
        expect(expected_path).to_exist()
        expect(expected_path).to_be_the_same_as(valid_image_path)
Example #15
0
    async def test_modifying_existing_image_to_heavy_image_fails(self):
        response = await self.async_post(self.base_uri,
                                         {"Content-Type": "image/jpeg"},
                                         valid_image())
        location = response.headers["Location"]

        response = await self.async_put(location,
                                        {"Content-Type": "image/jpeg"},
                                        too_heavy_image())
        expect(response.code).to_equal(412)

        expected_path = self.get_path_from_location(location)
        expected_path = self.upload_storage.path_on_filesystem(expected_path)
        expect(expected_path).to_exist()
        expect(expected_path).to_be_the_same_as(VALID_IMAGE_PATH)
Example #16
0
    def test_can_modify_existing_image(self):
        filename = self.default_filename + '.jpg'
        response = self.post(self.base_uri, {'Content-Type': 'image/jpeg'}, valid_image())
        location = response.headers['Location']
        response = self.put(location, {'Content-Type': 'image/jpeg'}, too_small_image())

        expect(response.code).to_equal(204)

        id_should_exist = re.compile(self.base_uri + r'/([^\/]{32})/' + filename).search(location).group(1)
        expected_path = self.upload_storage.path_on_filesystem(id_should_exist)
        expect(expected_path).to_exist()
        expect(expected_path).to_be_the_same_as(too_small_image_path)

        id_shouldnt_exist = re.compile(self.base_uri + r'/(.*)').search(location).group(1)
        expected_path = self.upload_storage.path_on_filesystem(id_shouldnt_exist)
        expect(expected_path).not_to_exist()
Example #17
0
    def test_can_delete_existing_image(self):
        filename = self.default_filename + '.jpg'
        response = self.post(self.base_uri, {'Content-Type': 'image/jpeg'},
                             valid_image())
        expect(response.code).to_equal(201)

        location = response.headers['Location']
        image_id = re.compile(self.base_uri + r'/([^\/]{32})/' +
                              filename).search(location).group(1)
        image_location = self.upload_storage.path_on_filesystem(image_id)
        expect(image_location).to_exist()

        response = self.delete(location, {})
        expect(response.code).to_equal(204)

        expect(image_location).not_to_exist()
Example #18
0
    def test_can_post_image_without_filename(self):
        filename = self.default_filename + '.jpg'
        response = self.post(self.base_uri, {'Content-Type': 'image/jpeg'},
                             valid_image())

        expect(response.code).to_equal(201)

        expect(response.headers).to_include('Location')
        expect(
            response.headers['Location']).to_match(self.base_uri +
                                                   r'/[^\/]{32}/' + filename)

        expected_path = self.get_path_from_location(
            response.headers['Location'])
        expected_path = self.upload_storage.path_on_filesystem(expected_path)
        expect(expected_path).to_exist()
        expect(expected_path).to_be_the_same_as(valid_image_path)
Example #19
0
    async def test_can_delete_existing_image(self):
        filename = self.default_filename + ".jpg"
        response = await self.async_post(self.base_uri,
                                         {"Content-Type": "image/jpeg"},
                                         valid_image())
        expect(response.code).to_equal(201)

        location = response.headers["Location"]
        image_id = (re.compile(self.base_uri + r"/([^\/]{32})/" +
                               filename).search(location).group(1))
        image_location = self.upload_storage.path_on_filesystem(image_id)
        expect(image_location).to_exist()

        response = await self.async_delete(location, {})
        expect(response.code).to_equal(204)

        expect(image_location).not_to_exist()
Example #20
0
    async def test_can_post_image_without_filename(self):
        filename = self.default_filename + ".jpg"
        response = await self.async_post(self.base_uri,
                                         {"Content-Type": "image/jpeg"},
                                         valid_image())

        expect(response.code).to_equal(201)

        expect(response.headers).to_include("Location")
        expect(
            response.headers["Location"]).to_match(self.base_uri +
                                                   r"/[^\/]{32}/" + filename)

        expected_path = self.get_path_from_location(
            response.headers["Location"])
        expected_path = self.upload_storage.path_on_filesystem(expected_path)
        expect(expected_path).to_exist()
        expect(expected_path).to_be_the_same_as(VALID_IMAGE_PATH)
Example #21
0
    def test_can_post_from_html_form(self):
        filename = 'crocodile2.jpg'
        image = ('media', filename, valid_image())
        response = self.post_files(self.base_uri,
                                   {'Slug': 'another_filename.jpg'}, (image, ))

        expect(response.code).to_equal(201)

        expect(response.headers).to_include('Location')
        expect(
            response.headers['Location']).to_match(self.base_uri +
                                                   r'/[^\/]{32}/' + filename)

        expected_path = self.get_path_from_location(
            response.headers['Location'])
        expected_path = self.upload_storage.path_on_filesystem(expected_path)
        expect(expected_path).to_exist()
        expect(expected_path).to_be_the_same_as(valid_image_path)
Example #22
0
    async def test_can_post_from_html_form(self):
        filename = "crocodile2.jpg"
        image = ("media", filename, valid_image())
        response = await self.async_post_files(
            self.base_uri, {"Slug": b"another_filename.jpg"}, (image, ))

        expect(response.code).to_equal(201)

        expect(response.headers).to_include("Location")
        expect(
            response.headers["Location"]).to_match(self.base_uri +
                                                   r"/[^\/]{32}/" + filename)

        expected_path = self.get_path_from_location(
            response.headers["Location"])
        expected_path = self.upload_storage.path_on_filesystem(expected_path)
        expect(expected_path).to_exist()
        expect(expected_path).to_be_the_same_as(VALID_IMAGE_PATH)
Example #23
0
    def test_can_modify_existing_image(self):
        filename = self.default_filename + '.jpg'
        response = self.post(self.base_uri, {'Content-Type': 'image/jpeg'},
                             valid_image())
        location = response.headers['Location']
        response = self.put(location, {'Content-Type': 'image/jpeg'},
                            too_small_image())

        expect(response.code).to_equal(204)

        id_should_exist = re.compile(self.base_uri + r'/([^\/]{32})/' +
                                     filename).search(location).group(1)
        expected_path = self.upload_storage.path_on_filesystem(id_should_exist)
        expect(expected_path).to_exist()
        expect(expected_path).to_be_the_same_as(too_small_image_path)

        id_shouldnt_exist = re.compile(self.base_uri +
                                       r'/(.*)').search(location).group(1)
        expected_path = self.upload_storage.path_on_filesystem(
            id_shouldnt_exist)
        expect(expected_path).not_to_exist()
Example #24
0
    async def test_can_modify_existing_image(self):
        filename = self.default_filename + ".jpg"
        response = await self.async_post(self.base_uri,
                                         {"Content-Type": "image/jpeg"},
                                         valid_image())
        location = response.headers["Location"]
        response = await self.async_put(location,
                                        {"Content-Type": "image/jpeg"},
                                        too_small_image())

        expect(response.code).to_equal(204)

        id_should_exist = (re.compile(self.base_uri + r"/([^\/]{32})/" +
                                      filename).search(location).group(1))
        expected_path = self.upload_storage.path_on_filesystem(id_should_exist)
        expect(expected_path).to_exist()
        expect(expected_path).to_be_the_same_as(TOO_SMALL_IMAGE_PATH)

        id_shouldnt_exist = (re.compile(self.base_uri +
                                        r"/(.*)").search(location).group(1))
        expected_path = self.upload_storage.path_on_filesystem(
            id_shouldnt_exist)
        expect(expected_path).not_to_exist()