Esempio n. 1
0
def test_file_move_with_last_folder_creation_failure(
        samba_mock: SMBConnectionMock, tmpdir):
    connection = pyndows.connect("TestComputer", "127.0.0.1", 80, "TestDomain",
                                 "TestUser", "TestPassword")
    with open(os.path.join(tmpdir, "local_file"), mode="w") as distant_file:
        distant_file.write("Test Content Move")

    samba_mock.path("TestShare", "/Folder1/Folder2").mkdir(parents=True)

    def raise_failure(*args):
        raise OperationFailure("Unable to create directory", [])

    samba_mock.add_callback("createDirectory", raise_failure)
    with pytest.raises(pyndows.PyndowsException) as exception_info:
        pyndows.move(
            connection,
            "TestShare",
            "/Folder1/Folder2/Folder3/TestFilePath",
            os.path.join(tmpdir, "local_file"),
        )

    assert (
        str(exception_info.value) ==
        r"Unable to write \\TestComputer\TestShare/Folder1/Folder2/Folder3/TestFilePath.tmp"
    )
Esempio n. 2
0
def test_connection_failure(samba_mock: SMBConnectionMock):
    samba_mock.add_callback("connect", lambda *args: False)
    with pytest.raises(pyndows.PyndowsException) as exception_info:
        pyndows.connect("TestComputer", "127.0.0.1", 80, "TestDomain",
                        "TestUser", "TestPassword")
    assert (
        str(exception_info.value) ==
        r"Impossible to connect to TestComputer (127.0.0.1:80), check connectivity or TestDomain\TestUser rights."
    )
Esempio n. 3
0
def test_smbtimeout_failure_during_storefile(samba_mock: SMBConnectionMock,
                                             tmpdir):
    connection = pyndows.connect("TestComputer", "127.0.0.1", 80, "TestDomain",
                                 "TestUser", "TestPassword")
    with open(os.path.join(tmpdir, "local_file"), mode="w") as distant_file:
        distant_file.write("Test Content Move")

    def raise_failure(*args):
        raise SMBTimeout()

    samba_mock.add_callback("storeFile", raise_failure)
    with pytest.raises(SMBTimeout):
        pyndows.move(connection, "TestShare", "/TestFilePath",
                     os.path.join(tmpdir, "local_file"))
Esempio n. 4
0
def test_store_file_operation_failure_during_file_move(
        samba_mock: SMBConnectionMock, tmpdir):
    connection = pyndows.connect("TestComputer", "127.0.0.1", 80, "TestDomain",
                                 "TestUser", "TestPassword")
    with open(os.path.join(tmpdir, "local_file"), mode="w") as distant_file:
        distant_file.write("Test Content Move")

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

    samba_mock.add_callback("storeFile", raise_failure)
    with pytest.raises(pyndows.PyndowsException) as exception_info:
        pyndows.move(connection, "TestShare", "/TestFilePath",
                     os.path.join(tmpdir, "local_file"))

    assert (str(exception_info.value) ==
            r"Unable to write \\TestComputer\TestShare/TestFilePath.tmp")
Esempio n. 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"
    )
Esempio n. 6
0
def test_fail_health_check(samba_mock: SMBConnectionMock, mock_pyndows_health_datetime):
    connection = pyndows.connect(
        "TestComputer", "127.0.0.1", 80, "TestDomain", "TestUser", "TestPassword"
    )

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

    samba_mock.add_callback("echo", raise_exception)
    assert pyndows.check("tests", connection) == (
        "fail",
        {
            "tests:echo": {
                "componentType": "TestComputer",
                "status": "fail",
                "time": "2018-10-11T15:05:05.663979",
                "output": f"Mock for echo failure.{os.linesep}",
            }
        },
    )