def setUp(self):
        with open(checklist_dir / 'onboarding.xml', 'w') as ch:
            ch.write(test_checklist)
        with open(checklist_dir / 'unlock.xml', 'w') as ch:
            ch.write(unlock_test)
        with open(CONFIG['Files']['task-path'], 'w') as fp:
            fp.write('')

        self.task_lib = TaskLib(CONFIG)
        self.check_lib = self.task_lib.libraries['checklist']
Beispiel #2
0
def main():
    args = parser.parse_args()
    logging.debug(args)

    if args.verbose:
        logger.setLevel(logging.INFO)
    if args.debug:
        logger.setLevel(logging.DEBUG)

    config.set('Tasker', 'wrap-behavior', args.wrap)
    config.set('Tasker', 'wrap-width', str(args.width))

    config.set('Tasker', 'show-priority-z', str(args.showz))
    config.set('Tasker', 'priority-z-last', str(args.integrate))

    config.set('Tasker', 'theme-name', args.theme)

    tasklib = TaskLib(config)
    tasklib.set_theme(args.theme)

    colorama.init(strip=True, autoreset=True)

    cli = TaskCmd(config=config, lib=tasklib)
    for e_point in pkg_resources.iter_entry_points('tasker_minions'):
        minion = e_point.load()
        cli.add_minion(e_point.name, minion())
        # the main library should have already loaded a library for the
        # plugin, if one exists.
        # the minion should now have a master
        if e_point.name in cli.lib.libraries:
            cli.minions[e_point.name].lib = cli.lib.libraries.get(e_point.name)

    if args.directory:
        if args.command:
            print(tasklib.libraries[args.command].directory)
        else:
            print(config['Files']['tasker-dir'])
        return 0
    if args.version:
        if args.command:
            print(tasklib.libraries[args.command].__version__)
        else:
            print(__version__)
        return 0
    elif args.interact:
        cli.cmdloop()
    elif not args.command:
        cli.onecmd('list')
    else:
        cli.onecmd(' '.join(sys.argv[sys.argv.index(args.command):]))

    return 0
class TaskLibTestCase(unittest.TestCase):
    def setUp(self):
        self.test_lib = TaskLib(TEST_CONFIG)
        with open(TEST_CONFIG['Files']['task-path'], 'w') as fp:
            fp.write('')

    def tearDown(self):
        del self.test_lib

    def test_add_task_returns_dictionary(self):
        res = self.test_lib.add_task('This is a test task')
        self.assertIsInstance(res, dict)

    def test_do_task_returns_tuple(self):
        self.test_lib.add_task('this is a test task')
        res = self.test_lib.complete_task(1)
        self.assertIsInstance(res, tuple)
        self.assertIsInstance(res[0], int)
        self.assertIsInstance(res[1], dict)
class ChecklistUnlockingTestCase(unittest.TestCase):
    def setUp(self):
        with open(checklist_dir / 'onboarding.xml', 'w') as ch:
            ch.write(test_checklist)
        with open(checklist_dir / 'unlock.xml', 'w') as ch:
            ch.write(unlock_test)
        with open(CONFIG['Files']['task-path'], 'w') as fp:
            fp.write('')

        self.task_lib = TaskLib(CONFIG)
        self.check_lib = self.task_lib.libraries['checklist']

    def tearDown(self):
        del self.check_lib
        del self.task_lib

        logging.getLogger().setLevel(logging.WARNING)

    def test_create_task_with_data(self):
        """Test unlocking multiple tasks on task_completion"""
       # logging.getLogger().setLevel(logging.DEBUG)
        # logging.debug('DEBUGGING')
        self.check_lib.create_instance('unlock', widget="spoon", group="utensil")
        tasks = self.task_lib.sort_tasks(filters="{cid:task1}")
        self.assertEqual(len(tasks), 1)
        generated_task = tasks[0][1]
        self.assertIn('utensil', generated_task.text)
        self.assertIn('spoon', generated_task.text)

    def test_unlock_multiple(self):
        # logging.getLogger().setLevel(logging.DEBUG)
        # logging.debug('DEBUGGING')
        self.check_lib.create_instance('unlock', widget="spoon", group="utensil")
        task2 = self.check_lib._get_task('unlock', 'spoon', 'task2')
        task3 = self.check_lib._get_task('unlock', 'spoon', 'task3')
        # logging.debug('tasks: %s', self.task_lib.sort_tasks(showcomplete=True))
        self.task_lib.complete_task(1, "this is a note")

        self.assertEqual(task2.get('status'), 'open',
            'Completing task did not open next checklist task')
        self.assertEqual(task3.get('status'), 'open')
        # logging.debug('Checking the tasker tasks are created')
        tasks = self.task_lib.sort_tasks(filters="{cid:task2}")
        self.assertEqual(len(tasks), 1)
        tasks = self.task_lib.sort_tasks(showcomplete=True)
        for idx, task in tasks:
            logging.debug("%d: %s", idx, task.text)
        logging.debug("Tasks found: %d", len(tasks))

    def test_fill_input(self):
        self.check_lib.create_instance('unlock', widget="spoon", group="utensil")
        self.task_lib.complete_task(1, "this is a note")
        task = self.check_lib._get_task('unlock', 'spoon', 'task1')
        self.assertTrue(self.check_lib._is_task_complete(task))
        self.assertEqual(task.find('input').text, 'this is a note')
 def setUp(self):
     self.test_lib = TaskLib(TEST_CONFIG)
     with open(TEST_CONFIG['Files']['task-path'], 'w') as fp:
         fp.write('')
class ChecklistIntegrationTestCase(unittest.TestCase):
    def setUp(self):
        with open(checklist_dir / 'onboarding.xml', 'w') as ch:
            ch.write(test_checklist)
        with open(checklist_dir / 'unlock.xml', 'w') as ch:
            ch.write(unlock_test)
        with open(CONFIG['Files']['task-path'], 'w') as fp:
            fp.write('')

        self.task_lib = TaskLib(CONFIG)
        self.check_lib = self.task_lib.libraries['checklist']

    def tearDown(self):
        del self.check_lib
        del self.task_lib

    def test_add_task_on_instantiation(self):
        '''Test that creating a checklist instance creates a new task as
        necessary'''
        self.check_lib.create_instance('onboarding', **{'name': 'New Employee'})
        tasks = self.task_lib.sort_tasks(filters="{cid:crmadd}")
        self.assertEqual(len(tasks), 1)
        generated_task = tasks[0][1]
        target_uid = generated_task.extensions.get('uid')
        checklist = self.check_lib.checklists['onboarding']
        instance = checklist.find('./instance[@id="NewEmployee"]')
        ch_task = instance.find('.//task[@id="crmadd"]')
        self.assertEqual(target_uid, ch_task.attrib.get('uid'))
        self.assertIn("NewEmployee", generated_task.text)
        self.assertIn("+NewEmployeeHire", generated_task.text)

    def test_complete_task_to_checklist_warning(self):
        '''Test that completing a task in task_lib raises a warning'''
        # In this example, there are inputs that are not automatically filled in
        self.check_lib.create_instance('onboarding', name='New Employee')
        with self.assertWarns(UserWarning):
            self.task_lib.complete_task(1)
        self.assertFalse(self.check_lib._is_task_complete(
            self.check_lib._get_task('onboarding', 'NewEmployee', 'crmadd')))

    def test_is_task_complete(self):
        '''Test is_task_complete works as expected'''
        self.check_lib.create_instance('onboarding', name='NewEmployee')
        self.assertFalse(self.check_lib._is_task_complete(
            self.check_lib._get_task('onboarding', 'NewEmployee', 'crmadd')))
        self.complete_crm_add()
        self.assertTrue(self.check_lib._is_task_complete(
            self.check_lib._get_task('onboarding', 'NewEmployee', 'crmadd')))

    def test_complete_checklist_to_task(self):
        '''Test completing a task in the checklist marks the task as
        complete'''
        self.check_lib.create_instance('onboarding', name='NewEmployee')
        ch_task = self.check_lib._get_task(
            'onboarding', 'NewEmployee', 'crmadd')
        logging.debug('ch_task uid %s', ch_task.get('uid', 'NOTHING'))
        self.assertFalse(self.check_lib._is_task_complete(ch_task))
        self.complete_crm_add()

        res = self.task_lib.sort_tasks(
                filters=[f"{{uid:{ch_task.get('uid')}}}"],
            showcomplete=True)
        task = res[0][1]
        self.assertTrue(task.complete, "Task was not marked as complete")

    def test_complete_task_unlocks_next_task(self):
        """oncomplete unlocks the next task"""
        self.check_lib.create_instance('onboarding', name="New Employee")
        crmt = self.check_lib._get_task('onboarding', 'NewEmployee', 'crmt')
        self.assertEqual(crmt.get('status'), 'onhold')
        self.complete_crm_add()

        self.assertEqual(crmt.get('status'), 'open')
        res = self.task_lib.sort_tasks(filters=[f"{{uid:{crmt.get('uid')}}}"])
        task = res[0][1]
        self.assertFalse(task.complete, "task was added as complete")


    def complete_crm_add(self):
        """Several tests require a task to be marked as closed, this
        should do this consistently"""
        self.check_lib.complete_action(
            'onboarding', 'NewEmployee', 'crmadd', 1)
        self.check_lib.complete_action(
            'onboarding', 'NewEmployee', 'crmadd', 2)
        self.check_lib.fill_input(
            'onboarding', 'NewEmployee', 'crmadd', 1, 'some input')
Beispiel #7
0
 def loadlibs(self):
     # many tests are dependent on faking the date, so creating
     # the libraries needs to be controlled.
     # quotidia runs
     self.task_lib = TaskLib(CONFIG)
     self.q_lib = self.task_lib.libraries['quotidia']
Beispiel #8
0
class QuotidiaTestCase(unittest.TestCase):
    def setUp(self):
        for qname, qtext in test_quotidia:
            with open(q_dir / f'{qname}.quotidia', 'w') as qf:
                qf.write(qtext)
        with open(CONFIG['Files']['task-path'], 'w') as fp:
            fp.write('')

    def loadlibs(self):
        # many tests are dependent on faking the date, so creating
        # the libraries needs to be controlled.
        # quotidia runs
        self.task_lib = TaskLib(CONFIG)
        self.q_lib = self.task_lib.libraries['quotidia']

    def tearDown(self):
        del self.q_lib
        del self.task_lib

        logging.getLogger().setLevel(logging.WARNING)

    def test_add_quotidia(self):
        self.loadlibs()
        logging.getLogger().setLevel(logging.CRITICAL)
        self.assertRaises(ValueError, self.q_lib.add_quotidia, "monday",
                          "error", "M")

    def test_load_quotidia(self):
        self.loadlibs()
        for (qid, q) in self.q_lib.qids.items():
            self.assertIsInstance(q, quotidia.Quotidium,
                                  "json did not load quotidium object")

    def test_get_todays_quotidia_dom(self):
        with fixed_today(datetime.date(2020, 6, 2)):
            self.loadlibs()
            # deactivate the test dow quotidium for this test
            self.q_lib.deactivate_quotidium('monday')
            # mark a dom quotidium as done on a day of the month
            self.q_lib.run_quotidium('alex')
            self.assertEqual(self.q_lib.qids['alex'].last_run,
                             datetime.date(2020, 6, 2))

        # logging.getLogger().setLevel(logging.DEBUG)

        with fixed_today(datetime.date(2020, 6, 30)):
            self.assertNotIn('alex',
                             (a for a, b in self.q_lib.get_todays_quotidia()))
        with fixed_today(datetime.date(2020, 7, 1)):
            self.assertIn('alex',
                          [a for a, b in self.q_lib.get_todays_quotidia()])

    def test_get_today_quotidia_dow(self):
        # mark a quotidium as run on a Monday
        with fixed_today(datetime.date(2020, 7, 20)):
            self.loadlibs()
            self.q_lib.run_quotidium('monday')
            self.assertEqual(self.q_lib.qids['monday'].last_run,
                             datetime.date(2020, 7, 20))

        with fixed_today(datetime.date(2020, 7, 21)):
            self.assertNotIn('monday',
                             (a for a, b in self.q_lib.get_todays_quotidia()))

        with fixed_today(datetime.date(2020, 7, 26)):
            self.assertNotIn('monday',
                             (a for a, b in self.q_lib.get_todays_quotidia()))

        with fixed_today(datetime.date(2020, 7, 27)):
            self.assertIn('monday',
                          (a for a, b in self.q_lib.get_todays_quotidia()))

        with fixed_today(datetime.date(2020, 7, 28)):
            quotidia = self.q_lib.get_todays_quotidia()
            self.assertIn('monday', (a for a, b in quotidia))
            for (a, b) in quotidia:
                self.q_lib.run_quotidium(a)
            self.assertNotIn('monday',
                             (a for a, b in self.q_lib.get_todays_quotidia()))

    def test_quotidia_adds_task(self):
        # quotidia should be checked on startup
        self.loadlibs()
        tasks = self.task_lib.sort_tasks(filters=["{qid:alex}"])
        self.assertEqual(len(tasks), 1)

    def test_quotidia_prevent_duplication(self):
        """quotidia should not add the quotidia if there is an open task
        attached to that qid"""
        with fixed_today(datetime.date(2020, 7, 27)):
            self.loadlibs()
        self.tearDown()
        with fixed_today(datetime.date(2020, 8, 3)):
            self.loadlibs()
            mondaytasks = self.task_lib.sort_tasks(filters=["{qid:monday}"])
            self.assertEqual(len(mondaytasks), 1)