Exemple #1
0
def test_create_and_fill_bucket_failure(make_stubber, make_unique_name,
                                        monkeypatch):
    s3_stubber = make_stubber(batch_versioning.s3.meta.client)
    bucket_name = make_unique_name('bucket')
    monkeypatch.setattr(versioning, 'create_versioned_bucket',
                        lambda x, y: batch_versioning.s3.Bucket(bucket_name))
    obj_prefix = 'test-prefix'

    s3_stubber.stub_put_object(bucket_name,
                               f"{obj_prefix}stanza-0",
                               error_code='TestException')

    with pytest.raises(ClientError) as exc_info:
        batch_versioning.create_and_fill_bucket(__file__, bucket_name,
                                                obj_prefix)
    assert exc_info.value.response['Error']['Code'] == 'TestException'
Exemple #2
0
def test_create_and_fill_bucket(make_stubber, make_unique_name, monkeypatch):
    s3_stubber = make_stubber(batch_versioning.s3.meta.client)
    bucket_name = make_unique_name('bucket')
    monkeypatch.setattr(versioning, 'create_versioned_bucket',
                        lambda x, y: batch_versioning.s3.Bucket(bucket_name))
    obj_prefix = 'test-prefix'

    with open(__file__) as file:
        stanzas = file.read().split('\n\n')

    for index in range(len(stanzas)):
        s3_stubber.stub_put_object(bucket_name, f"{obj_prefix}stanza-{index}")

    bucket, stanza_objects = \
        batch_versioning.create_and_fill_bucket(__file__, bucket_name, obj_prefix)
    assert bucket.name == bucket_name
    assert len(stanza_objects) == len(stanzas)