Example #1
0
def test_move_one_object_in_root(mock_bucket, capsys):
    mock_bucket.return_value = bucket_contents()

    move_object(
        origin_files=["empty.txt"],
        destination_path="source2",
        rename=None,
        permission=access_types.ACLTypes.public_read,
        threads=1,
    )

    list_keys(
        limit=0,
        prefix="source2/",
        delimiter="",
        max_keys=1,
        all=False,
        http_prefix=False,
        key_methods=object_methods.ObjectMethods.key,
    )

    assert mock_bucket.called == True
    captured = capsys.readouterr()
    print(captured.out)
    assert captured.out == "source2/empty.txt\n"
Example #2
0
def test_move_and_rename_one_object_many_sublevels(mock_bucket, capsys):
    mock_bucket.return_value = bucket_contents()

    move_object(
        origin_files=["delimiter/delimiter/empty2.txt"],
        destination_path=
        "",  # destination_path should be overriden when renaming
        rename="new_empty.txt",
        threads=1,
        permission=access_types.ACLTypes.public_read,
    )

    list_keys(
        limit=0,
        prefix="delimiter/",
        delimiter="",
        max_keys=1,
        all=False,
        http_prefix=False,
        key_methods=object_methods.ObjectMethods.key,
    )

    assert mock_bucket.called == True
    captured = capsys.readouterr()
    assert captured.out == "delimiter/delimiter/new_empty.txt\n"
Example #3
0
def test_change_permissions_authenticated_read(mock_bucket, capsys):
    mock_bucket.return_value = bucket_contents()

    change_permissions(
        args=["source/empty.txt"],
        prefix_threads=1,
        changer_threads=1,
        permissions=access_types.ACLTypes.authenticated_read,
    )

    list_keys(
        limit=0,
        prefix="source/empty.txt",
        delimiter="",
        max_keys=1,
        all=False,
        http_prefix=False,
        key_methods="acl",
    )

    assert mock_bucket.called == True
    captured = capsys.readouterr()
    captured_dict = ast.literal_eval(captured.out)
    assert (
        captured_dict[1].get("Grantee").get("URI")
        == "http://acs.amazonaws.com/groups/global/AuthenticatedUsers"
    )
Example #4
0
def test_change_permissions_private(mock_bucket, capsys):
    mock_bucket.return_value = bucket_contents()

    change_permissions(
        args=["source/empty.txt"],
        prefix_threads=1,
        changer_threads=1,
        permissions=access_types.ACLTypes.private,
    )

    list_keys(
        limit=0,
        prefix="source/empty.txt",
        delimiter="",
        max_keys=1,
        all=False,
        http_prefix=False,
        key_methods="acl",
    )

    assert mock_bucket.called == True
    captured = capsys.readouterr()
    captured_dict = ast.literal_eval(captured.out)
    assert len(captured_dict) == 1
    assert captured_dict[0].get("Grantee").get("Type") == "CanonicalUser"
    assert captured_dict[0].get("Permission") == "FULL_CONTROL"
Example #5
0
def test_list_keys_limit0_no_key(mock_bucket, capsys):
    mock_bucket.return_value = bucket_contents()
    list_keys(
        limit=0,
        prefix="nothing_here/",
        delimiter="",
        max_keys=1,
        all=False,
        http_prefix=False,
        key_methods="key",
    )

    assert mock_bucket.called == True
    captured = capsys.readouterr()
    assert captured.out == ""
Example #6
0
def test_list_keys_limit1(mock_bucket, capsys):
    mock_bucket.return_value = bucket_contents()

    list_keys(
        limit=1,
        prefix="source/",
        delimiter="",
        max_keys=1,
        all=True,
        http_prefix=False,
    )

    assert mock_bucket.called == True
    captured = capsys.readouterr()
    assert captured.out == "source/empty.txt\n"
Example #7
0
def test_list_keys_limit0_size(mock_bucket, capsys):
    mock_bucket.return_value = bucket_contents()

    list_keys(
        limit=0,
        prefix="listkeys/",
        delimiter="",
        max_keys=1,
        all=False,
        http_prefix=False,
        key_methods="size",
    )

    assert mock_bucket.called == True
    captured = capsys.readouterr()
    assert captured.out == "listkeys/empty.txt -> 0.0Mb\n"
Example #8
0
def test_list_keys_limit1_http_prefix(mock_bucket, capsys):
    os.environ[
        "HTTP_PREFIX"] = "https://http_prefix.com/"  # Can't add a @fixture >(
    mock_bucket.return_value = bucket_contents()

    list_keys(
        limit=1,
        prefix="source/",
        delimiter="",
        max_keys=1,
        all=False,
        http_prefix=True,
    )

    assert mock_bucket.called == True
    captured = capsys.readouterr()
    assert captured.out == "https://http_prefix.com/source/empty.txt\n"
Example #9
0
def test_list_keys_limit0_last_modified(mock_bucket, capsys):
    """How could I fix the date?"""
    mock_bucket.return_value = bucket_contents()

    list_keys(
        limit=0,
        prefix="listkeys/",
        delimiter="",
        max_keys=1,
        all=False,
        http_prefix=False,
        key_methods="last_modified",
    )

    assert mock_bucket.called == True
    captured = capsys.readouterr()
    captured_datetime = datetime.fromisoformat(captured.out.strip())
    assert type(captured_datetime) is datetime
Example #10
0
def test_list_keys_limit0_all(mock_bucket, capsys):
    mock_bucket.return_value = bucket_contents()
    list_keys(
        limit=0,
        prefix="source/",  # This does NOTHING here!!
        delimiter="",
        max_keys=10,
        all=True,
        http_prefix=False,
    )

    assert mock_bucket.called == True
    captured = capsys.readouterr()

    objects = captured.out.split("\n")

    assert objects[0] == "delimiter/delimiter/empty2.txt"
    assert objects[-2] == "source/subdir/empty4.txt"  # objects[-1] == ""
Example #11
0
def test_list_keys_limit0_acl(mock_bucket, capsys):
    mock_bucket.return_value = bucket_contents()

    list_keys(
        limit=0,
        prefix="listkeys/",
        delimiter="",
        max_keys=1,
        all=False,
        http_prefix=False,
        key_methods="acl",
    )

    assert mock_bucket.called == True
    captured = capsys.readouterr()
    assert (
        captured.out ==
        "[{'Grantee': {'ID': '75aa57f09aa0c8caeab4f8c24e99d10f8e7faeebf76c078efc7c6caea54ba06a', 'Type': 'CanonicalUser'}, 'Permission': 'FULL_CONTROL'}, {'Grantee': {'Type': 'Group', 'URI': 'http://acs.amazonaws.com/groups/global/AllUsers'}, 'Permission': 'READ'}]\n"
    )
Example #12
0
def test_list_keys_limit0_owner(mock_bucket, capsys):
    mock_bucket.return_value = bucket_contents()

    list_keys(
        limit=0,
        prefix="listkeys/",
        delimiter="",
        max_keys=1,
        all=False,
        http_prefix=False,
        key_methods="owner",
    )

    assert mock_bucket.called == True
    captured = capsys.readouterr()
    assert (
        captured.out ==
        "{'DisplayName': 'webfile', 'ID': '75aa57f09aa0c8caeab4f8c24e99d10f8e7faeebf76c078efc7c6caea54ba06a'}\n"
    )
Example #13
0
def test_list_keys_limit0_all_http_prefix(mock_bucket, capsys):
    os.environ[
        "HTTP_PREFIX"] = "https://http_prefix.com/"  # Can't add a @fixture >(
    mock_bucket.return_value = bucket_contents()

    list_keys(
        limit=0,
        prefix="source/",
        delimiter="",
        max_keys=1,
        all=True,
        http_prefix=True,
    )

    assert mock_bucket.called == True
    captured = capsys.readouterr()
    objects = captured.out.split("\n")
    assert len(objects) == 8
    assert objects[
        0] == "https://http_prefix.com/delimiter/delimiter/empty2.txt"
Example #14
0
def test_change_permissions_public_read_write(mock_bucket, capsys):
    mock_bucket.return_value = bucket_contents()

    change_permissions(
        args=["source/empty.txt"],
        prefix_threads=1,
        changer_threads=1,
        permissions=access_types.ACLTypes.public_read_write,
    )

    list_keys(
        limit=0,
        prefix="source/empty.txt",
        delimiter="",
        max_keys=1,
        all=False,
        http_prefix=False,
        key_methods="acl",
    )

    assert mock_bucket.called == True
    captured = capsys.readouterr()
    assert "<Element " in captured.out
Example #15
0
def test_upload_from_file(mock_bucket, tmp_path, capsys):
    mock_bucket.return_value = bucket_contents()
    upload_file = create_upload_list_for_testing(tmp_path)

    upload(
        files=None,
        upload_from_file=upload_file,
        upload_path="test_upload_from_file",
        permissions="public-read",
        threads=3,
    )

    list_keys(
        prefix="test_upload_from_file",
        delimiter="",
        max_keys=10,
        key_methods="key",
        all=False,
        http_prefix=False,
        limit=10,
    )

    captured = capsys.readouterr()

    expected_output = """test_upload_from_file/file 0.txt
test_upload_from_file/file 1.txt
test_upload_from_file/file 2.txt
test_upload_from_file/file 3.txt
test_upload_from_file/file 4.txt
test_upload_from_file/file 5.txt
test_upload_from_file/file 6.txt
test_upload_from_file/file 7.txt
test_upload_from_file/file 8.txt
test_upload_from_file/file 9.txt
"""
    assert captured.out == expected_output
Example #16
0
def test_upload_multiple_files(mock_bucket, tmp_path, capsys):
    mock_bucket.return_value = bucket_contents()
    files_to_upload = create_files(tmp_path, multiple=True)

    upload(
        files=files_to_upload,
        upload_path="test_upload_multiple_files",
        permissions="public-read",
        threads=1,
    )

    list_keys(
        prefix="test_upload_multiple_files",
        delimiter="",
        max_keys=10,
        key_methods="key",
        all=False,
        http_prefix=False,
        limit=10,
    )

    captured = capsys.readouterr()

    expected_output = """test_upload_multiple_files/test_upload_file 0.txt
test_upload_multiple_files/test_upload_file 1.txt
test_upload_multiple_files/test_upload_file 2.txt
test_upload_multiple_files/test_upload_file 3.txt
test_upload_multiple_files/test_upload_file 4.txt
test_upload_multiple_files/test_upload_file 5.txt
test_upload_multiple_files/test_upload_file 6.txt
test_upload_multiple_files/test_upload_file 7.txt
test_upload_multiple_files/test_upload_file 8.txt
test_upload_multiple_files/test_upload_file 9.txt
"""

    assert captured.out == expected_output
Example #17
0
def test_upload_one_file(mock_bucket, tmp_path, capsys):
    mock_bucket.return_value = bucket_contents()
    file_to_upload = create_files(tmp_path, multiple=False)

    upload(
        files=[file_to_upload],
        upload_path="test_upload_one_file",
        permissions="public-read",
        threads=1,
    )

    list_keys(
        prefix="test_upload_one_file",
        delimiter="",
        max_keys=1,
        key_methods="key",
        all=False,
        http_prefix=False,
        limit=1,
    )

    captured = capsys.readouterr()

    assert captured.out == "test_upload_one_file/test_upload_file.txt\n"