def test_read_metadata_from_valid_yaml(self, mexists): mexists.return_value = True meta = {'report_dir': '/tmp/report_dir', 'pid_dir': '/tmp/pid_dir'} mopen = mock.mock_open(read_data=yaml.dump(meta)) test_task = task.Task('ceph/deploy', self.conf) with mock.patch('tasklib.task.open', mopen, create=True): self.assertEqual(meta, test_task.metadata)
def test_base_cmd_task(self, mexecute, mexists): mexists.return_value = True mexecute.return_value = (0, '', '') mopen = mock.mock_open(read_data=yaml.dump(self.meta)) puppet_task = task.Task('test/cmd', self.config) with mock.patch('tasklib.task.open', mopen, create=True): puppet_task.run() expected_cmd = 'echo 1' mexecute.assert_called_once_with(expected_cmd)
def test_sync_choice(self, mock_input, mock_warrior): siom = SyncIOManager(self.iom) e = SyncElement() self.assertEqual(siom.sync_choice(e), None) t = tlib.Task(tlib.TaskWarrior()) t['description'] = 'foo' e = SyncElement(ltask=SharedTask(t)) self.assertEqual(siom.sync_choice(e), 'u') e = SyncElement(rtask=SharedTask(t)) self.assertEqual(siom.sync_choice(e), 'd') e = SyncElement(ltask=SharedTask(t), rtask=SharedTask(t)) e.fields = ['description'] self.assertEqual(siom.sync_choice(e), 's')
def test_default_puppet_action(self, mexecute, mexists): mexists.return_value = True mexecute.return_value = (0, '', '') mopen = mock.mock_open(read_data=yaml.dump(self.only_required)) puppet_task = task.Task('test/puppet/only_required', self.config) with mock.patch('tasklib.task.open', mopen, create=True): puppet_task.run() expected_cmd = [ 'puppet', 'apply', '--detailed-exitcodes', '--modulepath={0}'.format(self.config['puppet_modules']) ] expected = ' '.join(expected_cmd) self.assertEqual(mexecute.call_count, 1) received = mexecute.call_args[0][0] self.assertTrue(expected in received)
def test_user_checks_synclist(self, mock_input, mock_warrior): siom = SyncIOManager(self.iom) self.assertEqual(siom.user_checks_synclist(None, 'foo'), None) sync_list = [SyncElement(suggestion='UPLOAD')] result = siom.user_checks_synclist(sync_list, 'foo') # input=a self.assertEqual(result[0].action, 'UPLOAD') t = tlib.Task(tlib.TaskWarrior()) t['description'] = 'foo' e1 = SyncElement(ltask=SharedTask(t), suggestion='UPLOAD') e2 = SyncElement(rtask=SharedTask(t), suggestion='DOWNLOAD') e3 = SyncElement(ltask=SharedTask(t), suggestion='UPLOAD') sync_list = [e1, e2, e3] result = siom.user_checks_synclist(sync_list, 'foo') # input=m u d s self.assertEqual(result[0].action, 'UPLOAD') self.assertEqual(result[1].action, 'DOWNLOAD') self.assertEqual(result[2].action, 'SKIP') sync_list = [SyncElement(ltask=SharedTask(t), suggestion='UPLOAD')] result = siom.user_checks_synclist(sync_list, 'foo') # input = m c self.assertEqual(result, [])
def show(self, args): meta = task.Task(args.task, self.config).metadata print(yaml.dump(meta, default_flow_style=False))
def create_shared_task(self, arena, description): shared_task = SharedTask(tlib.Task(tlib.TaskWarrior())) shared_task.Arena = arena shared_task.tw_task['description'] = description return shared_task
def test_last_modified(self): se = SyncElement() self.assertEqual(se.local_last_modified, '') se.local_task = SharedTask(tlib.Task()) se.local_task.last_modified = lambda: 'now' self.assertEqual(se.local_last_modified, 'now')
def test_remote_description(self): se = SyncElement() self.assertEqual(se.remote_description, '') se.remote_task = SharedTask(tlib.Task()) se.remote_task.tw_task['description'] = 'foo' self.assertEqual(se.remote_description, 'foo')
def __init__(self, task_name, config): log.debug('Initializing task agent for task %s', task_name) self.config = config self.task = task.Task(task_name, self.config) self.init_directories()
def test_verify_nothing_happens_if_file_exists(self, mexists): mexists.return_value = True test_task = task.Task('ceph/deploy', self.conf) test_task.verify()
def test_verify_raises_not_found(self, mexists): mexists.return_value = False test_task = task.Task('ceph/deploy', self.conf) self.assertRaises(exceptions.NotFound, test_task.verify)
def add_task(self, task): t = SharedTask(tlib.Task(self.tw), self.arena) for field in tw_attrs_editable: t.tw_task[field] = task.tw_task[field] return t