示例#1
0
    def test_toomanyinvalidation_errors_cause_retry(self, MockClient):
        error = CloudFrontServerError(400, 'Bad Request')
        error.error_code = 'TooManyInvalidationsInProgress'

        cloudfront = Mock()
        cloudfront.create_invalidation_request.side_effect = error

        config = Client().config()
        client = Mock()
        client.config.return_value = config
        client.get_cloudfront.return_value = cloudfront
        MockClient.return_value = client

        session = Client().session()
        transaction_id = TaskTransaction.new_id()
        image = Image(filename='abad1dea')
        image.created_at = '2001-01-01 00:00:00'
        session.add(image)
        session.flush()

        invalidate = NeverCalledDirectlyInvalidate()
        invalidate.retry = Mock()
        invalidate(transaction_id, image.image_id)

        invalidate.retry.assert_called_with(exc=error)
示例#2
0
    def test_images_for_album_id_sorts_by_photographed_then_added_date(self):
        session = Client().session()
        album = Album(name="my pix")
        session.add(album)
        session.flush()

        han = Image(photographed_at="2012-05-13 03:00:00", album_id=album.album_id, filename="han")
        han.created_at = "2014-11-22 13:15:00"
        greedo = Image(photographed_at="2014-12-28 15:24:00", album_id=album.album_id, filename="greedo")
        greedo.created_at = "2014-08-01 08:00:00"
        artoo = Image(photographed_at=None, album_id=album.album_id, filename="R2D2")
        artoo.created_at = "1977-05-13 01:00:00"
        session.add(han)
        session.add(greedo)
        session.add(artoo)
        session.flush()

        # Sorting should be done by the date the image was shot, or the date
        # it was added if it has no photographed_at. Han shot first, so he
        # should show up before Greedo. Artoo never shot at all, so use his
        # created_at (which refers to the *record*, not the image) instead.
        images = Album.images_for_album_id(album.album_id)
        eq_(["R2D2", "han", "greedo"], map(lambda x: x.filename, images))
示例#3
0
    def test_invalidate_an_image__with_a_resize_suffix(self):
        cloudfront = Mock()
        Client().get_cloudfront = Mock()
        Client().get_cloudfront.return_value = cloudfront

        transaction_id = TaskTransaction.new_id()
        image = Image(filename='f131d')
        image.created_at = '2001-05-09 13:00:00'
        session = Client().session()
        session.add(image)
        session.flush()

        Invalidate().run(transaction_id, image.image_id, suffix="teensy")

        cloudfront.create_invalidation_request.assert_called_with(
            'FETCHISNTGOINGTOHAPPEN', ['f131d_teensy'])
示例#4
0
    def test_invalidate_an_image(self):
        cloudfront = Mock()
        Client().get_cloudfront = Mock()
        Client().get_cloudfront.return_value = cloudfront

        transaction_id = TaskTransaction.new_id()
        image = Image(filename='c1a115')
        image.created_at = '2001-05-09 13:00:00'
        session = Client().session()
        session.add(image)
        session.flush()

        Invalidate().run(transaction_id, image.image_id)

        cloudfront.create_invalidation_request.assert_called_with(
            'JEEZAMANDA', ['c1a115'])
示例#5
0
    def test_invalidation_of_new_images_is_a_noop(self, mock_time, MockClient):
        now = time.strptime('2011-05-09 15:01:01', '%Y-%m-%d %H:%M:%S')
        mock_time.strftime = time.strftime
        mock_time.gmtime.return_value = now

        get_cloudfront = Mock()
        get_cloudfront.side_effect = AssertionError('should not have called me!')
        Client().get_cloudfront = get_cloudfront

        transaction_id = TaskTransaction.new_id()
        image = Image(filename='c1a115')
        # created 1 hour before "now"
        image.created_at = '2011-05-09 13:00:00'
        session = Client().session()
        session.add(image)
        session.flush()

        Invalidate().run(transaction_id, image.image_id)
示例#6
0
    def test_unknown_cloudfront_errors_reraise(self, MockClient):
        error = CloudFrontServerError(400, 'Bad Request')
        error.error_code = 'CloudFrontHatesYouToday'

        cloudfront = Mock()
        cloudfront.create_invalidation_request.side_effect = error

        config = Client().config()
        client = Mock()
        client.config.return_value = config
        client.get_cloudfront.return_value = cloudfront
        MockClient.return_value = client

        transaction_id = TaskTransaction.new_id()
        session = Client().session()
        image = Image(filename='abad1dea')
        image.created_at = '2001-01-01 00:00:00'
        session.add(image)
        session.flush()

        Invalidate()(transaction_id, image.image_id)