def test_conditional_upload(self):
     """Test conditional ASCII mode upload."""
     local_source = '__test_source'
     data = ascii_data()
     self.generate_ascii_file(data, local_source)
     # Target is newer, so don't upload
     host = test_base.ftp_host_factory(
            ftp_host_class=FailingUploadAndDownloadFTPHost)
     flag = host.upload_if_newer(local_source, '/home/newer')
     self.assertEqual(flag, False)
     # Target is older, so upload
     host = test_base.ftp_host_factory()
     flag = host.upload_if_newer(local_source, '/home/older')
     self.assertEqual(flag, True)
     # Check uploaded content
     # The data which was uploaded has its line endings converted
     #  so the conversion must also be applied to 'data'.
     data = data.replace('\n', '\r\n')
     remote_file_content = mock_ftplib.content_of('older')
     self.assertEqual(data, remote_file_content)
     # Target doesn't exist, so upload
     host = test_base.ftp_host_factory()
     flag = host.upload_if_newer(local_source, '/home/notthere')
     self.assertEqual(flag, True)
     remote_file_content = mock_ftplib.content_of('notthere')
     self.assertEqual(data, remote_file_content)
     # Clean up
     os.unlink(local_source)
Beispiel #2
0
 def test_conditional_upload(self):
     """Test conditional ASCII mode upload."""
     local_source = '__test_source'
     data = ascii_data()
     self.generate_ascii_file(data, local_source)
     # Target is newer, so don't upload
     host = test_base.ftp_host_factory(
         ftp_host_class=FailingUploadAndDownloadFTPHost)
     flag = host.upload_if_newer(local_source, '/home/newer')
     self.assertEqual(flag, False)
     # Target is older, so upload
     host = test_base.ftp_host_factory()
     flag = host.upload_if_newer(local_source, '/home/older')
     self.assertEqual(flag, True)
     # Check uploaded content
     # The data which was uploaded has its line endings converted
     #  so the conversion must also be applied to 'data'.
     data = data.replace('\n', '\r\n')
     remote_file_content = mock_ftplib.content_of('older')
     self.assertEqual(data, remote_file_content)
     # Target doesn't exist, so upload
     host = test_base.ftp_host_factory()
     flag = host.upload_if_newer(local_source, '/home/notthere')
     self.assertEqual(flag, True)
     remote_file_content = mock_ftplib.content_of('notthere')
     self.assertEqual(data, remote_file_content)
     # Clean up
     os.unlink(local_source)
Beispiel #3
0
 def compare_and_delete_downloaded_data(self, filename):
     """Compare content of downloaded file with its source, then
     delete the local target file."""
     data = open(filename, 'rb').read()
     remote_file_content = mock_ftplib.content_of('newer')
     self.assertEqual(data, remote_file_content)
     # Clean up
     os.unlink(filename)
 def compare_and_delete_downloaded_data(self, filename):
     """Compare content of downloaded file with its source, then
     delete the local target file."""
     data = open(filename, 'rb').read()
     remote_file_content = mock_ftplib.content_of('newer')
     self.assertEqual(data, remote_file_content)
     # Clean up
     os.unlink(filename)
Beispiel #5
0
 def test_ascii_write(self):
     """Write ASCII text with `write`."""
     host = test_base.ftp_host_factory()
     data = ' \nline 2\nline 3'
     output = host.file('dummy', 'w')
     output.write(data)
     output.close()
     child_data = mock_ftplib.content_of('dummy')
     expected_data = ' \r\nline 2\r\nline 3'
     self.assertEqual(child_data, expected_data)
Beispiel #6
0
 def test_binary_write(self):
     """Write binary data with `write`."""
     host = test_base.ftp_host_factory()
     data = '\000a\001b\r\n\002c\003\n\004\r\005'
     output = host.file('dummy', 'wb')
     output.write(data)
     output.close()
     child_data = mock_ftplib.content_of('dummy')
     expected_data = data
     self.assertEqual(child_data, expected_data)
 def test_ascii_write(self):
     """Write ASCII text with `write`."""
     host = test_base.ftp_host_factory()
     data = ' \nline 2\nline 3'
     output = host.file('dummy', 'w')
     output.write(data)
     output.close()
     child_data = mock_ftplib.content_of('dummy')
     expected_data = ' \r\nline 2\r\nline 3'
     self.assertEqual(child_data, expected_data)
 def test_binary_write(self):
     """Write binary data with `write`."""
     host = test_base.ftp_host_factory()
     data = '\000a\001b\r\n\002c\003\n\004\r\005'
     output = host.file('dummy', 'wb')
     output.write(data)
     output.close()
     child_data = mock_ftplib.content_of('dummy')
     expected_data = data
     self.assertEqual(child_data, expected_data)
Beispiel #9
0
 def test_binary_download(self):
     """Test binary mode download."""
     local_target = '__test_target'
     host = test_base.ftp_host_factory(
         session_factory=BinaryDownloadMockSession)
     # Download
     host.download('dummy', local_target, 'b')
     # Read file and compare
     data = open(local_target, 'rb').read()
     remote_file_content = mock_ftplib.content_of('dummy')
     self.assertEqual(data, remote_file_content)
     # Clean up
     os.unlink(local_target)
Beispiel #10
0
 def test_binary_download(self):
     """Test binary mode download."""
     local_target = '__test_target'
     host = test_base.ftp_host_factory(
            session_factory=BinaryDownloadMockSession)
     # Download
     host.download('dummy', local_target, 'b')
     # Read file and compare
     data = open(local_target, 'rb').read()
     remote_file_content = mock_ftplib.content_of('dummy')
     self.assertEqual(data, remote_file_content)
     # Clean up
     os.unlink(local_target)
Beispiel #11
0
 def test_ascii_writelines(self):
     """Write ASCII text with `writelines`."""
     host = test_base.ftp_host_factory()
     data = [' \n', 'line 2\n', 'line 3']
     backup_data = data[:]
     output = host.file('dummy', 'w')
     output.writelines(data)
     output.close()
     child_data = mock_ftplib.content_of('dummy')
     expected_data = ' \r\nline 2\r\nline 3'
     self.assertEqual(child_data, expected_data)
     # Ensure that the original data was not modified
     self.assertEqual(data, backup_data)
 def test_ascii_writelines(self):
     """Write ASCII text with `writelines`."""
     host = test_base.ftp_host_factory()
     data = [' \n', 'line 2\n', 'line 3']
     backup_data = data[:]
     output = host.file('dummy', 'w')
     output.writelines(data)
     output.close()
     child_data = mock_ftplib.content_of('dummy')
     expected_data = ' \r\nline 2\r\nline 3'
     self.assertEqual(child_data, expected_data)
     # Ensure that the original data was not modified
     self.assertEqual(data, backup_data)
Beispiel #13
0
 def test_ascii_upload(self):
     """Test ASCII mode upload."""
     local_source = '__test_source'
     data = ascii_data()
     self.generate_ascii_file(data, local_source)
     # Upload
     host = test_base.ftp_host_factory()
     host.upload(local_source, 'dummy')
     # Check uploaded content
     # The data which was uploaded has its line endings converted
     #  so the conversion must also be applied to `data`.
     data = data.replace('\n', '\r\n')
     remote_file_content = mock_ftplib.content_of('dummy')
     self.assertEqual(data, remote_file_content)
     # Clean up
     os.unlink(local_source)
Beispiel #14
0
 def test_ascii_upload(self):
     """Test ASCII mode upload."""
     local_source = '__test_source'
     data = ascii_data()
     self.generate_ascii_file(data, local_source)
     # Upload
     host = test_base.ftp_host_factory()
     host.upload(local_source, 'dummy')
     # Check uploaded content
     # The data which was uploaded has its line endings converted
     #  so the conversion must also be applied to `data`.
     data = data.replace('\n', '\r\n')
     remote_file_content = mock_ftplib.content_of('dummy')
     self.assertEqual(data, remote_file_content)
     # Clean up
     os.unlink(local_source)