def test_dynamic_bucket_creation_task(freeze_time, mocker, date, name_template, bucket_created, expected_name, expected_error): freeze_time(date) if '<' in name_template: storage = plugin.DynamicS3Storage('bucket_template={},bucket_secret=secret'.format(name_template)) else: storage = plugin.S3Storage('bucket={}'.format(name_template)) mocker.patch('indico_storage_s3.task.config', MockConfig()) mocker.patch('indico_storage_s3.task.get_storage', return_value=storage) create_bucket_call = mocker.patch.object(plugin.DynamicS3Storage, '_create_bucket') if expected_error: with pytest.raises(expected_error): create_bucket() else: create_bucket() if bucket_created: token = hmac.new(b'secret', expected_name, hashlib.md5).hexdigest() create_bucket_call.assert_called_with('{}-{}'.format(expected_name, token)) else: assert not create_bucket_call.called
def test_resolve_bucket_name_static(): storage = plugin.S3Storage('bucket=test') assert storage._get_current_bucket_name() == 'test'