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" )
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" )
def add_with_delay(delay: int): time.sleep(delay) pyndows.move( connection, "TestShare", "TestFilePath", os.path.join(temp_dir, "local_file"), )
def add_with_delay(delay: int): time.sleep(delay) pyndows.move( connection, "TestShare", "/TestFilePath", os.path.join(tmpdir, "local_file"), write_to_new_folder_after=0, )
def test_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") pyndows.move(connection, "TestShare", "/TestFilePath", os.path.join(tmpdir, "local_file")) assert (samba_mock.path( "TestShare", "/TestFilePath").read_text() == "Test Content Move")
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"))
def test_file_move(samba_mock: SMBConnectionMock): connection = pyndows.connect("TestComputer", "127.0.0.1", 80, "TestDomain", "TestUser", "TestPassword") with tempfile.TemporaryDirectory() as temp_dir: with open(os.path.join(temp_dir, "local_file"), mode="w") as distant_file: distant_file.write("Test Content Move") pyndows.move( connection, "TestShare", "TestFilePath", os.path.join(temp_dir, "local_file"), ) assert (samba_mock.stored_files[( "TestShare", "TestFilePath")] == "Test Content Move")
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")
def test_file_move_with_last_folder_creation(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) pyndows.move( connection, "TestShare", "/Folder1/Folder2/Folder3/TestFilePath", os.path.join(tmpdir, "local_file"), ) assert (samba_mock.path( "TestShare", "/Folder1/Folder2/Folder3/TestFilePath").read_text() == "Test Content Move")
def test_store_file_operation_failure_during_file_move( samba_mock: SMBConnectionMock): connection = pyndows.connect("TestComputer", "127.0.0.1", 80, "TestDomain", "TestUser", "TestPassword") with tempfile.TemporaryDirectory() as temp_dir: with open(os.path.join(temp_dir, "local_file"), mode="w") as distant_file: distant_file.write("Test Content Move") samba_mock.storeFile_failure = True with pytest.raises(Exception) as exception_info: pyndows.move( connection, "TestShare", "TestFilePath", os.path.join(temp_dir, "local_file"), ) assert (str(exception_info.value) == r"Unable to write \\TestComputer\TestShareTestFilePath.tmp")