Beispiel #1
0
    def test_rename(self):
        from_path = '/path/from'
        to_path = '/path/to'
        with fh.FTPHook() as ftp_hook:
            ftp_hook.rename(from_path, to_path)

        self.conn_mock.rename.assert_called_once_with(from_path, to_path)
        self.conn_mock.quit.assert_called_once_with()
Beispiel #2
0
    def test_mod_time_micro(self):
        self.conn_mock.sendcmd.return_value = '213 20170428010138.003'

        path = '/path/file'
        with fh.FTPHook() as ftp_hook:
            ftp_hook.get_mod_time(path)

        self.conn_mock.sendcmd.assert_called_once_with('MDTM ' + path)
Beispiel #3
0
    def test_get_size(self):
        self.conn_mock.size.return_value = 1942

        path = '/path/file'
        with fh.FTPHook() as ftp_hook:
            ftp_hook.get_size(path)

        self.conn_mock.size.assert_called_once_with(path)
Beispiel #4
0
    def test_delete_file(self):
        with fh.FTPHook() as ftp_hook:
            ftp_hook.delete_file(self.path)

        self.conn_mock.delete.assert_called_once_with(self.path)
Beispiel #5
0
    def test_delete_directory(self):
        with fh.FTPHook() as ftp_hook:
            ftp_hook.delete_directory(self.path)

        self.conn_mock.rmd.assert_called_once_with(self.path)
Beispiel #6
0
    def test_list_directory(self):
        with fh.FTPHook() as ftp_hook:
            ftp_hook.list_directory(self.path)

        self.conn_mock.cwd.assert_called_once_with(self.path)
        self.conn_mock.nlst.assert_called_once_with()
Beispiel #7
0
    def test_close_conn(self):
        ftp_hook = fh.FTPHook()
        ftp_hook.get_conn()
        ftp_hook.close_conn()

        self.conn_mock.quit.assert_called_once_with()
Beispiel #8
0
 def test_retrieve_file_with_callback(self):
     func = mock.Mock()
     _buffer = io.StringIO('buffer')
     with fh.FTPHook() as ftp_hook:
         ftp_hook.retrieve_file(self.path, _buffer, callback=func)
     self.conn_mock.retrbinary.assert_called_once_with('RETR path', func)
Beispiel #9
0
 def test_retrieve_file(self):
     _buffer = io.StringIO('buffer')
     with fh.FTPHook() as ftp_hook:
         ftp_hook.retrieve_file(self.path, _buffer)
     self.conn_mock.retrbinary.assert_called_once_with(
         'RETR path', _buffer.write)