def topic(self, callback):
            self.conn = S3Connection()
            self.conn.create_bucket(s3_bucket)

            config = Config(TC_AWS_RESULT_STORAGE_BUCKET=s3_bucket)
            ctx = Context(config=config, server=get_server('ACME-SEC'))
            ctx.request = Request
            ctx.request.url = 'my-image.jpg'

            storage = Storage(ctx)

            storage.put(IMAGE_BYTES, callback=callback)
        def topic(self, callback):
            self.conn = S3Connection()
            self.conn.create_bucket(s3_bucket)

            config = Config(TC_AWS_RESULT_STORAGE_BUCKET=s3_bucket, TC_AWS_STORE_METADATA=True)
            ctx = Context(config=config, server=get_server('ACME-SEC'))
            ctx.headers = {'Content-Type': 'image/webp', 'Some-Other-Header': 'doge-header'}
            ctx.request = Request
            ctx.request.url = 'my-image-meta.jpg'

            storage = Storage(ctx)
            storage.put(IMAGE_BYTES)

            file_abspath = storage._normalize_path(ctx.request.url)
            storage.storage.get(file_abspath, callback=callback)
Exemplo n.º 3
0
        def topic(self):
            self.conn = S3Connection()
            self.conn.create_bucket(s3_bucket)

            config = Config(RESULT_STORAGE_BUCKET=s3_bucket, RESULT_STORAGE_S3_STORE_METADATA=True)
            ctx = Context(config=config, server=get_server('ACME-SEC'))
            ctx.request_handler = RequestHandler()
            ctx.request = Request
            ctx.request.url = 'my-image-meta.jpg'

            storage = Storage(ctx)
            storage.put(IMAGE_BYTES)

            file_abspath = storage.normalize_path(ctx.request.url)
            file_key = storage.storage.get_key(file_abspath)
            return file_key.content_type, file_key.metadata, file_key.read()
Exemplo n.º 4
0
        def topic(self):
            self.conn = S3Connection()
            self.conn.create_bucket(s3_bucket)

            config = Config(RESULT_STORAGE_BUCKET=s3_bucket,
                            RESULT_STORAGE_S3_STORE_METADATA=True)
            ctx = Context(config=config, server=get_server('ACME-SEC'))
            ctx.headers = {
                'Content-Type': 'image/webp',
                'Some-Other-Header': 'doge-header'
            }
            ctx.request = Request
            ctx.request.url = 'my-image-meta.jpg'

            storage = Storage(ctx)
            storage.put(IMAGE_BYTES)

            file_abspath = storage.normalize_path(ctx.request.url)
            file_key = storage.storage.get_key(file_abspath)
            return file_key.content_type, file_key.metadata, file_key.read()
Exemplo n.º 5
0
    def test_can_get_image(self):
        config = Config(TC_AWS_RESULT_STORAGE_BUCKET=s3_bucket)
        ctx = Context(config=config, server=get_server('ACME-SEC'))
        ctx.request = Request
        ctx.request.url = 'my-image-2.jpg'

        storage = Storage(ctx)
        yield storage.put(IMAGE_BYTES)

        topic = yield storage.get()

        self.assertEqual(topic.buffer, IMAGE_BYTES)
Exemplo n.º 6
0
        def topic(self):
            self.conn = S3Connection()
            self.conn.create_bucket(s3_bucket)

            config = Config(RESULT_STORAGE_BUCKET=s3_bucket)
            ctx = Context(config=config, server=get_server('ACME-SEC'))
            ctx.request = Request
            ctx.request.url = 'my-image.jpg'

            storage = Storage(ctx)
            path = storage.put(IMAGE_BYTES)

            return path
Exemplo n.º 7
0
        def topic(self):
            self.conn = S3Connection()
            self.conn.create_bucket(s3_bucket)

            config = Config(RESULT_STORAGE_BUCKET=s3_bucket)
            ctx = Context(config=config, server=get_server('ACME-SEC'))
            ctx.request = Request
            ctx.request.url = 'my-image.jpg'

            storage = Storage(ctx)
            path = storage.put(IMAGE_BYTES)

            return path
Exemplo n.º 8
0
    def test_can_store_image(self):
        config = Config(TC_AWS_RESULT_STORAGE_BUCKET=s3_bucket)
        ctx = Context(config=config, server=get_server('ACME-SEC'))
        ctx.request = Request
        ctx.request.url = 'foo/my-image.jpg'

        storage = Storage(ctx)

        yield storage.put(IMAGE_BYTES)

        client = botocore.session.get_session().create_client('s3')
        response = client.get_object(Bucket=s3_bucket, Key="foo/my-image.jpg")

        self.assertEqual(response['Body'].read(), IMAGE_BYTES)
Exemplo n.º 9
0
    def test_can_store_image_randomly(self):
        config = Config(TC_AWS_RESULT_STORAGE_BUCKET=s3_bucket,
                        TC_AWS_RANDOMIZE_KEYS=True)
        ctx = Context(config=config, server=get_server('ACME-SEC'))
        ctx.request = Request
        ctx.request.url = 'foo/my-image.jpg'

        storage = Storage(ctx)

        yield storage.put(IMAGE_BYTES)

        expected_path = '/'.join([
            sha1("foo/my-image.jpg".encode('utf-8')).hexdigest(),
            'foo/my-image.jpg'
        ])

        client = botocore.session.get_session().create_client('s3')
        response = client.get_object(Bucket=s3_bucket, Key=expected_path)

        self.assertEqual(response['Body'].read(), IMAGE_BYTES)
Exemplo n.º 10
0
    def test_can_get_image_with_metadata(self):
        config = Config(TC_AWS_RESULT_STORAGE_BUCKET=s3_bucket,
                        TC_AWS_STORE_METADATA=True)
        ctx = Context(config=config, server=get_server('ACME-SEC'))
        ctx.headers = {
            'Content-Type': 'image/webp',
            'Some-Other-Header': 'doge-header'
        }
        ctx.request = Request
        ctx.request.url = 'my-image-meta.jpg'

        storage = Storage(ctx)
        yield storage.put(IMAGE_BYTES)

        file_abspath = storage._normalize_path(ctx.request.url)
        topic = yield storage.get(file_abspath)

        self.assertIn('Some-Other-Header', topic.metadata['Metadata'])
        self.assertEqual(topic.metadata['Metadata']['Content-Type'],
                         'image/webp')
        self.assertEqual(topic.buffer, IMAGE_BYTES)