예제 #1
0
def test_resolve_bucket_name_dynamic(freeze_time, date, name_template,
                                     expected_name):
    freeze_time(date)
    storage = plugin.DynamicS3Storage(
        'bucket_template={},bucket_secret=secret'.format(name_template))
    name, token = storage._get_current_bucket_name().rsplit('-', 1)
    assert name == expected_name
    assert token == hmac.new(b'secret', expected_name, hashlib.md5).hexdigest()
예제 #2
0
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