def test_download_file_remote_file_params_none(self): foo = FtpFileTransfer(None) self.assertFalse(foo.download_file(None, None)) self.assertEqual(foo.get_error_msg(), 'remote_file None') self.assertFalse(foo.download_file('/hi', None)) self.assertEqual(foo.get_error_msg(), 'local_file None')
def test_download_file_not_connected(self): foo = FtpFileTransfer(None) self.assertFalse(foo.download_file('/remote/bye', '/local/hi')) self.assertEqual( foo.get_error_msg(), "Unable to download /remote/bye " "to /local/hi : 'NoneType' " "object has no attribute 'get'")
def test_download_file_success(self): mockftp = MockFtp() mockftp.get = Mock() mockftp.close = Mock(return_value=None) foo = FtpFileTransfer(None) foo.set_connection(mockftp) foo.connect() self.assertTrue(foo.download_file('/a/b', '/c/d')) self.assertEqual(foo.get_error_msg(), None) foo.disconnect() mockftp.get.assert_called_with('/a/b', local='/c/d')
def test_download_file_fail(self): mockftp = MockFtp() mockftp.get = Mock(side_effect=IOError('error')) mockftp.close = Mock(return_value=None) foo = FtpFileTransfer(None) foo.set_connection(mockftp) foo.connect() self.assertFalse(foo.download_file('/a/b', '/c/d')) self.assertEqual(foo.get_error_msg(), 'Unable to download /a/b to ' '/c/d : error') foo.disconnect() mockftp.get.assert_called_with('/a/b', local='/c/d')