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

    pyndows.move(
        connection, "TestShare", "/TestFilePath", os.path.join(tmpdir, "local_file")
    )

    pyndows.get(
        connection,
        "TestShare",
        "/TestFilePath",
        os.path.join(tmpdir, "local_file_retrieved"),
    )

    with gzip.open(os.path.join(tmpdir, "local_file_retrieved")) as local_file:
        assert local_file.read() == b"Test Content Move"

    assert (
        gzip.decompress(samba_mock.path("TestShare", "/TestFilePath").read_bytes())
        == b"Test Content Move"
    )
Exemple #2
0
def test_operation_failure_during_file_retrieval(samba_mock: SMBConnectionMock,
                                                 tmpdir):
    connection = pyndows.connect("TestComputer", "127.0.0.1", 80, "TestDomain",
                                 "TestUser", "TestPassword")
    with pytest.raises(pyndows.PyndowsException) as exception_info:
        pyndows.get(connection, "TestShare", "/TestFilePath",
                    os.path.join(tmpdir, "local_file"))
    assert (str(exception_info.value) ==
            r"Unable to retrieve \\TestComputer\TestShare/TestFilePath file")
Exemple #3
0
def test_file_retrieval(samba_mock: SMBConnectionMock, tmpdir):
    connection = pyndows.connect("TestComputer", "127.0.0.1", 80, "TestDomain",
                                 "TestUser", "TestPassword")
    samba_mock.path("TestShare", "/TestFilePath").write_text("Test Content")

    pyndows.get(connection, "TestShare", "/TestFilePath",
                os.path.join(tmpdir, "local_file"))
    with open(os.path.join(tmpdir, "local_file")) as local_file:
        assert local_file.read() == "Test Content"
Exemple #4
0
def test_file_retrieval_using_str_content(samba_mock: SMBConnectionMock):
    connection = pyndows.connect("TestComputer", "127.0.0.1", 80, "TestDomain",
                                 "TestUser", "TestPassword")
    with tempfile.TemporaryDirectory() as temp_dir:
        samba_mock.files_to_retrieve[("TestShare", "TestFilePath")] = "data"

        pyndows.get(
            connection,
            "TestShare",
            "TestFilePath",
            os.path.join(temp_dir, "local_file_retrieved"),
        )
        with open(os.path.join(temp_dir, "local_file_retrieved"),
                  "rt") as local_file:
            assert local_file.read() == "data"
Exemple #5
0
def test_operation_failure_during_file_retrieval(
        samba_mock: SMBConnectionMock):
    connection = pyndows.connect("TestComputer", "127.0.0.1", 80, "TestDomain",
                                 "TestUser", "TestPassword")
    with tempfile.TemporaryDirectory() as temp_dir:
        with pytest.raises(Exception) as exception_info:
            pyndows.get(
                connection,
                "TestShare",
                "TestFilePath",
                os.path.join(temp_dir, "local_file"),
            )
        assert (str(
            exception_info.value
        ) == r"Unable to retrieve \\TestComputer\TestShareTestFilePath file")
Exemple #6
0
def test_file_retrieval_using_path(samba_mock: SMBConnectionMock, tmpdir):
    connection = pyndows.connect(
        "TestComputer", "127.0.0.1", 80, "TestDomain", "TestUser", "TestPassword"
    )
    samba_mock.path("TestShare", "/TestFilePath").write_bytes(
        gzip.compress(b"Test Content")
    )

    pyndows.get(
        connection,
        "TestShare",
        "/TestFilePath",
        os.path.join(tmpdir, "local_file_retrieved"),
    )
    with gzip.open(os.path.join(tmpdir, "local_file_retrieved")) as local_file:
        assert local_file.read() == b"Test Content"
Exemple #7
0
def test_file_retrieval_using_bytes_content(samba_mock: SMBConnectionMock):
    connection = pyndows.connect("TestComputer", "127.0.0.1", 80, "TestDomain",
                                 "TestUser", "TestPassword")
    with tempfile.TemporaryDirectory() as temp_dir:
        bytes_content_file_path = os.path.join(temp_dir, "local_file")
        with gzip.open(bytes_content_file_path, mode="w") as distant_file:
            distant_file.write(b"Test Content")
        samba_mock.files_to_retrieve[("TestShare", "TestFilePath")] = open(
            bytes_content_file_path, "rb").read()

        pyndows.get(
            connection,
            "TestShare",
            "TestFilePath",
            os.path.join(temp_dir, "local_file_retrieved"),
        )
        with gzip.open(os.path.join(temp_dir,
                                    "local_file_retrieved")) as local_file:
            assert local_file.read() == b"Test Content"