def test_should_use_http_loader(self, load_sync_patch): def cb(a, b, callback, *args, **kwargs): callback('foobar') return None load_sync_patch.side_effect = cb conf = Config(TC_AWS_ENABLE_HTTP_LOADER=True) presigning_loader.load(Context(config=conf), 'http://foo.bar') self.assertTrue(load_sync_patch.called)
def test_can_validate_buckets(self): conf = Config( TC_AWS_ALLOWED_BUCKETS=['whitelist_bucket'], TC_AWS_LOADER_BUCKET=None, ) image = yield presigning_loader.load(Context(config=conf), '/'.join([s3_bucket, IMAGE_PATH])) self.assertIsNone(image)
def test_can_load_image(self): client = botocore.session.get_session().create_client('s3') client.create_bucket(Bucket=s3_bucket) client.put_object( Bucket=s3_bucket, Key=''.join(['root_path', IMAGE_PATH]), Body=IMAGE_BYTES, ContentType='image/jpeg', ) conf = Config( TC_AWS_LOADER_BUCKET=s3_bucket, TC_AWS_LOADER_ROOT_PATH='root_path', ) image = yield presigning_loader.load(Context(config=conf), IMAGE_PATH) self.assertEqual(image.buffer, IMAGE_BYTES)
def should_redirect_to_http(self, topic, load_sync_patch): def callback(*args): pass presigning_loader.load(topic, 'http://foo.bar', callback) expect(load_sync_patch.called).to_be_true()
def should_load_from_s3(self, topic): image = yield presigning_loader.load( topic, '/'.join([s3_bucket, IMAGE_PATH])) expect(image).to_equal(None)
def should_load_from_s3(self, topic): image = yield presigning_loader.load( topic, '/'.join(['root_path', IMAGE_PATH])) expect(image).to_equal(IMAGE_BYTES)
def should_load_from_s3(self, topic): image = yield presigning_loader.load(topic, '/'.join([s3_bucket, IMAGE_PATH])) expect(image).to_equal(None)
def should_load_from_s3(self, topic): image = yield presigning_loader.load(topic, '/'.join(['root_path', IMAGE_PATH])) expect(image).to_equal(IMAGE_BYTES)
def should_redirect_to_http(self, topic, load_sync_patch): def callback(*args): pass presigning_loader.load(topic, "http://foo.bar", callback) expect(load_sync_patch.called).to_be_true()