Ejemplo n.º 1
0
def test_unsafe_operations(boto3):
    s3_client = boto3.client.return_value
    repo = MinioRepo(CONNECTION_DATA)

    # testing unsafe clear method
    s3_client.list_objects.return_value = {
        'Contents': [{
            'Key': 'a'
        }, {
            'Key': 'b'
        }],
        'IsTruncated': False
    }
    # deleted 2 objects
    assert repo._unsafe_method__clear() == 2
    s3_client.list_objects.assert_called_once_with(
        Bucket=CONNECTION_DATA['bucket'])
    # deleted only objects from the response
    assert s3_client.delete_object.call_count == 2
    assert s3_client.delete_object.call_args_list == [
        mock.call(Bucket=CONNECTION_DATA['bucket'], Key='a'),
        mock.call(Bucket=CONNECTION_DATA['bucket'], Key='b')
    ]
    boto3.reset_mock()
    # testing unsafe is empty
    assert not repo.is_empty()
    s3_client.list_objects.assert_called_once_with(
        Bucket=CONNECTION_DATA['bucket'])
    boto3.reset_mock()

    s3_client.list_objects.return_value['Contents'] = []
    assert repo.is_empty()
    s3_client.list_objects.assert_called_once_with(
        Bucket=CONNECTION_DATA['bucket'])
    boto3.reset_mock()
Ejemplo n.º 2
0
def test_unsafe_operations_not_allowed(boto3):
    repo = MinioRepo(CONNECTION_DATA)
    with pytest.raises(RuntimeError):
        repo._unsafe_method__clear()