Beispiel #1
0
def test_file_rename_file_does_not_exist(samba_mock: SMBConnectionMock):
    connection = pyndows.connect("TestComputer", "127.0.0.1", 80, "TestDomain",
                                 "TestUser", "TestPassword")

    with pytest.raises(FileNotFoundError) as exception_info:
        pyndows.rename(connection, "TestShare\\", "file_to_rename_2",
                       "file_new_name")

    assert (str(exception_info.value) ==
            r"\\TestComputer\TestShare\file_to_rename_2 doesn't exist")
Beispiel #2
0
def test_file_rename(samba_mock: SMBConnectionMock):
    connection = pyndows.connect("TestComputer", "127.0.0.1", 80, "TestDomain",
                                 "TestUser", "TestPassword")

    samba_mock.stored_files[("TestShare/", "file_to_rename")] = "Test Rename"

    pyndows.rename(connection, "TestShare/", "file_to_rename", "file_new_name")

    assert ("TestShare/", "file_to_rename") not in samba_mock.stored_files
    assert samba_mock.stored_files[("TestShare/",
                                    "file_new_name")] == "Test Rename"
Beispiel #3
0
def test_file_rename(samba_mock: SMBConnectionMock):
    connection = pyndows.connect("TestComputer", "127.0.0.1", 80, "TestDomain",
                                 "TestUser", "TestPassword")

    samba_mock.path("TestShare", "/file_to_rename").write_text("Test Rename")

    pyndows.rename(connection, "TestShare", "/file_to_rename",
                   "/file_new_name")

    assert not samba_mock.path("TestShare", "/file_to_rename").exists()
    assert samba_mock.path("TestShare",
                           "/file_new_name").read_text() == "Test Rename"
Beispiel #4
0
def test_rename_operation_failure_during_file_rename(
        samba_mock: SMBConnectionMock):
    connection = pyndows.connect("TestComputer", "127.0.0.1", 80, "TestDomain",
                                 "TestUser", "TestPassword")

    samba_mock.stored_files[("TestShare/", "file_to_rename")] = "Test Rename"

    samba_mock.rename_failure = True
    with pytest.raises(Exception) as exception_info:
        pyndows.rename(connection, "TestShare/", "file_to_rename",
                       "file_new_name")

    assert (
        str(exception_info.value) ==
        r"Unable to rename \\TestComputer\TestShare/file_to_rename into \\TestComputer\TestShare/file_new_name"
    )
Beispiel #5
0
def test_rename_operation_failure_during_file_rename(
        samba_mock: SMBConnectionMock):
    connection = pyndows.connect("TestComputer", "127.0.0.1", 80, "TestDomain",
                                 "TestUser", "TestPassword")

    samba_mock.path("TestShare", "/file_to_rename").write_text("Test Rename")

    def raise_failure(*args):
        raise OperationFailure("Mock for rename failure.", [])

    samba_mock.add_callback("rename", raise_failure)
    with pytest.raises(pyndows.PyndowsException) as exception_info:
        pyndows.rename(connection, "TestShare", "/file_to_rename",
                       "/file_new_name")

    assert (
        str(exception_info.value) ==
        r"Unable to rename \\TestComputer\TestShare/file_to_rename into \\TestComputer\TestShare/file_new_name"
    )