mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 22:28:24 +02:00
Implement canceling of file transmission
This commit is contained in:
@@ -43,17 +43,29 @@ class TestFileTransmission(BaseTest):
|
||||
self.ae(ft.test_responses, [] if quiet == 2 else [{'status': 'EPERM:User refused the transfer', 'id': 'x'}])
|
||||
self.assertFalse(ft.active_cmds)
|
||||
# simple single file send
|
||||
for quiet in (0, 1, 2):
|
||||
ft = FileTransmission()
|
||||
dest = os.path.join(self.tdir, '1.bin')
|
||||
ft.handle_serialized_command(serialized_cmd(action='send', dest=dest, quiet=quiet))
|
||||
self.assertIn('', ft.active_cmds)
|
||||
self.ae(os.path.basename(ft.active_cmds[''].dest), '1.bin')
|
||||
self.assertIsNone(ft.active_cmds[''].file)
|
||||
self.ae(ft.test_responses, [] if quiet else [{'status': 'OK'}])
|
||||
ft.handle_serialized_command(serialized_cmd(action='data', data='abcd'))
|
||||
self.ae(ft.active_cmds[''].file.name, dest)
|
||||
ft.handle_serialized_command(serialized_cmd(action='end_data', data='123'))
|
||||
self.assertFalse(ft.active_cmds)
|
||||
self.ae(ft.test_responses, [] if quiet else [{'status': 'OK'}, {'status': 'COMPLETED'}])
|
||||
with open(dest) as f:
|
||||
self.ae(f.read(), 'abcd123')
|
||||
# cancel a send
|
||||
ft = FileTransmission()
|
||||
dest = os.path.join(self.tdir, '1.bin')
|
||||
dest = os.path.join(self.tdir, '2.bin')
|
||||
ft.handle_serialized_command(serialized_cmd(action='send', dest=dest))
|
||||
self.assertIn('', ft.active_cmds)
|
||||
self.ae(os.path.basename(ft.active_cmds[''].dest), '1.bin')
|
||||
self.assertIsNone(ft.active_cmds[''].file)
|
||||
self.ae(ft.test_responses, [{'status': 'OK'}])
|
||||
ft.handle_serialized_command(serialized_cmd(action='data', data='abcd'))
|
||||
self.assertIsNotNone(ft.active_cmds[''].file)
|
||||
ft.handle_serialized_command(serialized_cmd(action='end_data', data='123'))
|
||||
self.assertTrue(os.path.exists(dest))
|
||||
ft.handle_serialized_command(serialized_cmd(action='cancel'))
|
||||
self.ae(ft.test_responses, [{'status': 'OK'}])
|
||||
self.assertFalse(os.path.exists(dest))
|
||||
self.assertFalse(ft.active_cmds)
|
||||
self.ae(ft.test_responses, [{'status': 'OK'}, {'status': 'COMPLETED'}])
|
||||
with open(dest) as f:
|
||||
self.ae(f.read(), 'abcd123')
|
||||
|
||||
Reference in New Issue
Block a user