示例#1
0
 def test_suggest_conflict_resolution(self, mock_last_modified):
     arena = TaskArena('my_arena', 'local', 'remote')
     ltask1 = self.create_shared_task(arena, 'paint walls')
     ltask2 = self.create_shared_task(arena, 'clean floor')
     ltask3 = self.create_shared_task(arena, 'do dishes')
     rtask1 = self.create_shared_task(arena, 'paint ceilling')
     rtask2 = self.create_shared_task(arena, 'clean floor')
     rtask3 = self.create_shared_task(arena, 'do dishes')
     ltask1.ArenaTaskID = 1
     ltask2.ArenaTaskID = 2
     ltask3.ArenaTaskID = 4
     rtask1.ArenaTaskID = 3
     rtask2.ArenaTaskID = 2
     rtask3.ArenaTaskID = 4
     rtask3.tw_task['priority'] = 'H'
     synclist = [
         SyncElement(ltask1, None, None, 'UPLOAD'),
         SyncElement(ltask2, rtask2, ltask2.different_fields(rtask2),
                     'CONFLICT'),
         SyncElement(None, rtask1, None, 'DOWNLOAD'),
         SyncElement(ltask3, rtask3, ltask3.different_fields(rtask3),
                     'CONFLICT')
     ]
     sm = SyncManager(arena, IOManager(False))
     sm.synclist = synclist
     sm.suggest_conflict_resolution()
     num_total = len(sm.synclist)
     num_uploads = len([x for x in sm.synclist if x.suggestion == 'UPLOAD'])
     num_downloads = len(
         [x for x in sm.synclist if x.suggestion == 'DOWNLOAD'])
     self.assertEqual(num_total, 3)
     self.assertEqual(num_uploads, 1)
     self.assertEqual(num_downloads, 2)
示例#2
0
 def sync_choice(self, e):
     if e.local_task:
         self.iom.send_message("Task Description: " +
                               e.local_task.tw_task['description'])
         self.iom.send_message("ArenaTaskID     : " +
                               e.local_task.ArenaTaskID)
         if e.remote_task:
             self.iom.send_message("Task exists in both repositories.", 1,
                                   1)
             self.iom.send_message("Last modified (local) : " +
                                   e.local_last_modified)
             self.iom.send_message("Last modified (remote): " +
                                   e.remote_last_modified)
             self.iom.send_message("Suggesting to " + e.suggestion + ".", 1,
                                   1)
             self.iom.send_message(
                 "This would cause the following modifications:", 0, 1)
             for field in e.fields:
                 local_field = str(e.local_task.tw_task[field]) \
                     if e.local_task.tw_task[field] else '(empty)'
                 remote_field = str(e.remote_task.tw_task[field]) \
                     if e.remote_task.tw_task[field] else '(empty)'
                 self.iom.send_message(field + ": " + local_field + (
                     " -> " if e.suggestion == 'UPLOAD' else ' <- ') +
                                       remote_field)
             result = IOManager.get_input(
                 "Do you want to (u)pload, (d)ownload, (s)kip or (c)ancel sync? (u/d/s/c) ",
                 1)
         else:
             self.iom.send_message(
                 "This task does not yet exist on remote. Suggestion: " +
                 e.suggestion, 1)
             result = IOManager.get_input(
                 "Do you want to (u)pload, (s)kip or (c)ancel sync? (u/s/c) ",
                 1)
     elif e.remote_task:
         self.iom.print_separator()
         self.iom.send_message("Description: " +
                               e.remote_task.tw_task['description'])
         self.iom.send_message("ArenaTaskID: " + e.remote_task.ArenaTaskID)
         self.iom.send_message("This task does not yet exist on local.", 1)
         result = IOManager.get_input(
             "Do you want to (d)ownload, (s)kip or (c)ancel sync? (d/s/c) ",
             1)
     else:
         result = None
     return result
示例#3
0
 def test_send_message(self):
     iom = IOManager()
     iom.send_message('test', 1, 2)
     self.assertEqual(self.mystdout.getvalue(), '\ntest\n\n\n')
     iom.show_output = False
     iom.send_message('test')
     self.assertEqual(self.mystdout.getvalue(), '\ntest\n\n\n')
示例#4
0
 def test_send_message(self):
     iom = IOManager()
     iom.send_message('test', 1, 2)
     self.assertEqual(self.mystdout.getvalue(), '\ntest\n\n\n')
     iom.show_output=False
     iom.send_message('test')
     self.assertEqual(self.mystdout.getvalue(), '\ntest\n\n\n')
示例#5
0
 def test_get_save_task_emperor(self):
     runner = CliRunner()
     sys.stdout = self.old_stdout
     with runner.isolated_filesystem():
         config_file_name = os.getcwd()+'/config_file'
         self.assertEqual(os.path.isfile(config_file_name), False)
         iom = IOManager(False, 75, config_file_name)
         iom.get_task_emperor()
         self.assertEqual(os.path.isfile(config_file_name), True)
         iom = IOManager(False, 75, config_file_name)
         te = iom.get_task_emperor()
         arena = te.create_arena('foo', 'local', 'remote')
         iom.save_task_emperor(te)
         iom = IOManager(False, 75, config_file_name)
         te = iom.get_task_emperor()
         self.assertEqual(len(te.arenas), 1)
         self.assertEqual(arena.name, te.arenas[0].name)
         self.assertEqual(arena.local_data, te.arenas[0].local_data)
         self.assertEqual(arena.remote_data, te.arenas[0].remote_data)
示例#6
0
 def sync_preview(self, synclist):
     self.iom.print_separator()
     IOManager.formatted_print(('', 'Task', 'LastModified', 'Suggestion'))
     self.iom.print_separator()
     for e in synclist:
         IOManager.formatted_print(
             ('Local', e.local_description, e.local_last_modified, ''))
         IOManager.formatted_print(('Remote', e.remote_description,
                                    e.remote_last_modified, e.suggestion))
         self.iom.print_separator()
     return IOManager.get_input(
         "Do you want to sync (a)ll, sync (m)anually or (c)ancel? (a/m/c) ",
         1)
示例#7
0
 def test_create_synclist(self):
     arena = TaskArena('my_arena', 'local', 'remote')
     ltask1 = self.create_shared_task(arena, 'paint walls')
     ltask2 = self.create_shared_task(arena, 'clean floor')
     rtask1 = self.create_shared_task(arena, 'paint ceilling')
     rtask2 = self.create_shared_task(arena, 'clean floor')
     ltask1.ArenaTaskID = 1
     rtask1.ArenaTaskID = 1
     local_tasks = [ltask1, ltask2]
     remote_tasks = [rtask1, rtask2]
     sm = SyncManager(arena, IOManager(False))
     sm.generate_synclist(local_tasks, remote_tasks)
     num_uploads = len([e for e in sm.synclist if e.suggestion == 'UPLOAD'])
     num_downloads = len(
         [e for e in sm.synclist if e.suggestion == 'DOWNLOAD'])
     num_conflicts = len(
         [e for e in sm.synclist if e.suggestion == 'CONFLICT'])
     self.assertEqual(num_uploads, 1)
     self.assertEqual(num_downloads, 1)
     self.assertEqual(num_conflicts, 1)
示例#8
0
 def test_carry_out_sync(self, mock_save):
     arena = TaskArena('my_arena', 'local', 'remote')
     ltask1 = self.create_shared_task(arena, 'paint walls')
     ltask3 = self.create_shared_task(arena, 'do dishes')
     rtask1 = self.create_shared_task(arena, 'paint ceilling')
     rtask3 = self.create_shared_task(arena, 'do dishes')
     ltask1.ArenaTaskID = 1
     ltask3.ArenaTaskID = 4
     rtask1.ArenaTaskID = 3
     rtask3.ArenaTaskID = 4
     rtask3.tw_task['priority'] = 'H'
     synclist = [
         SyncElement(ltask1, None, None, None, 'UPLOAD'),
         SyncElement(None, rtask1, None, None, 'DOWNLOAD'),
         SyncElement(ltask3, rtask3, None, None, 'DOWNLOAD')
     ]
     sm = SyncManager(arena, IOManager(False))
     sm.synclist = synclist
     sm.carry_out_sync()
     self.assertEqual(synclist[0].local_task, synclist[0].remote_task)
     self.assertEqual(synclist[1].local_task, synclist[1].remote_task)
     self.assertEqual(synclist[2].local_task, synclist[2].remote_task)
     self.assertEqual(synclist[2].local_task.tw_task['priority'],
                      synclist[2].remote_task.tw_task['priority'])
示例#9
0
 def test_formatted_print(self):
     t = ('Local', 'do dishes', '2014-01-01', 'UPLOAD')
     IOManager.formatted_print(t)
     line = "Local    do dishes                   2014-01-01" \
            + "             UPLOAD    \n"
     self.assertEqual(self.mystdout.getvalue(), line)
示例#10
0
 def test_get_input(self, mock_input):
     result = IOManager.get_input('test', 1, 2)
     self.assertEqual(result, 'foo')
示例#11
0
 def test_create_io_manager(self):
     iom = IOManager()
     self.assertEqual(type(iom), IOManager)
     self.assertEqual(iom.seplength, 75)
     self.assertEqual(iom.show_output, True)
     self.assertNotEqual(iom.configfile_name, None)
示例#12
0
 def test_print_seperator(self):
     iom = IOManager()
     iom.print_separator()
     self.assertEqual(self.mystdout.getvalue(), "-" * 75 + "\n")
示例#13
0
 def test_print_seperator(self):
     iom = IOManager()
     iom.print_separator()
     self.assertEqual(self.mystdout.getvalue(), "-" * 75 + "\n")
示例#14
0
 def test_get_input(self, mock_input):
     result = IOManager.get_input('test', 1, 2)
     self.assertEqual(result, 'foo')
示例#15
0
 def test_newlines(self):
     IOManager.newlines(3)
     self.assertEqual(self.mystdout.getvalue(), "\n\n\n")
示例#16
0
 def test_formatted_print(self):
     t = ('Local', 'do dishes', '2014-01-01', 'UPLOAD')
     IOManager.formatted_print(t)
     line = "Local    do dishes                   2014-01-01" \
            + "             UPLOAD    \n"
     self.assertEqual(self.mystdout.getvalue(), line)
示例#17
0
 def test_get_save_task_emperor(self):
     runner = CliRunner()
     sys.stdout = self.old_stdout
     with runner.isolated_filesystem():
         config_file_name = os.getcwd() + '/config_file'
         self.assertEqual(os.path.isfile(config_file_name), False)
         iom = IOManager(False, 75, config_file_name)
         iom.get_task_emperor()
         self.assertEqual(os.path.isfile(config_file_name), True)
         iom = IOManager(False, 75, config_file_name)
         te = iom.get_task_emperor()
         arena = te.create_arena('foo', 'local', 'remote')
         iom.save_task_emperor(te)
         iom = IOManager(False, 75, config_file_name)
         te = iom.get_task_emperor()
         self.assertEqual(len(te.arenas), 1)
         self.assertEqual(arena.name, te.arenas[0].name)
         self.assertEqual(arena.local_data, te.arenas[0].local_data)
         self.assertEqual(arena.remote_data, te.arenas[0].remote_data)
示例#18
0
 def test_newlines(self):
     IOManager.newlines(3)
     self.assertEqual(self.mystdout.getvalue(), "\n\n\n")
示例#19
0
 def setUp(self):
     self.old_stdout = sys.stdout
     self.mystdout = StringIO()
     sys.stdout = self.mystdout
     self.iom = IOManager(show_output=False)