示例#1
0
    def test_get_tasks(self):
        self.assertEqual(len(queries.get_tasks(EXECUTOR, title='task_1')), 1)

        self.assertEqual(
            len(queries.get_tasks(EXECUTOR, category='category_2')), 2)

        self.assertEqual(
            len(queries.get_tasks(EXECUTOR, category='category_2',
                                  priority=1)), 2)

        self.assertEqual(
            len(queries.get_tasks(EXECUTOR, status=Statuses.INPROCESS.value)),
            5)
示例#2
0
 def test_add_tasks_to_plan(self):
     queries.add_tasks_to_plan(
         USER_NAME,
         queries.get_plans(USER_NAME, 'unique_plan')[0].id, [
             queries.get_tasks(USER_NAME, 'test_task_1')[0].id,
             queries.get_tasks(USER_NAME, 'test_task_2')[0].id
         ])
     plan = queries.get_plans(USER_NAME, 'unique_plan')[0]
     self.assertTrue(plan.tasks.filter(title='test_task_1'))
     self.assertTrue(plan.tasks.filter(title='test_task_2'))
     self.assertEqual(
         queries.get_tasks(USER_NAME, 'test_task_2')[0].status, 'planned')
     self.assertFalse(
         queries.get_tasks(USER_NAME, 'test_task_1')[0].deadline)
示例#3
0
 def setUpClass(cls):
     setup_logger(LOGS_PATH, LOGS_LEVEL, LOGS_FORMAT)
     queries.add_user(USER_NAME)
     owners = [Owner(USER_NAME, AccessLevels.EDIT.value)]
     queries.add_task(USER_NAME,
                      title='test_task_1',
                      category='test',
                      owners=owners)
     queries.add_task(USER_NAME,
                      title='test_task_2',
                      category='test',
                      owners=owners)
     queries.add_plan(USER_NAME, 'unique_plan', owners=owners)
     queries.add_reminder(
         USER_NAME,
         description='test_reminder_1',
         remind_in=timedelta(days=1),
         interval=timedelta(hours=1),
         weekdays=[0, 6],
         datetimes=[datetime(2018, 6, 7, 11),
                    datetime(2018, 6, 8, 13)])
     queries.add_reminder(
         USER_NAME,
         description='test_reminder_2',
         remind_in=timedelta(hours=5),
         interval=timedelta(hours=4),
         datetimes=[datetime(2018, 6, 7, 19),
                    datetime(2018, 6, 7, 23, 5)])
     queries.add_reminder(USER_NAME,
                          description='test_reminder_3',
                          start_remind_from=datetime(2018, 6, 7, 6),
                          stop_remind_in=datetime(2018, 6, 15),
                          interval=timedelta(hours=1),
                          weekdays=[3, 4, 5],
                          datetimes=[
                              datetime(2018, 6, 7, 10, 15),
                              datetime(2018, 6, 7, 18, 50),
                              datetime(2018, 6, 9, 10),
                              datetime(2018, 6, 10, 15)
                          ])
     queries.add_reminders_to_task(
         USER_NAME,
         queries.get_tasks(USER_NAME, 'test_task_1')[0].id,
         [queries.get_reminders(USER_NAME, 'test_reminder_1')[0].id])
     queries.add_reminders_to_task(
         USER_NAME,
         queries.get_tasks(USER_NAME, 'test_task_2')[0].id,
         [queries.get_reminders(USER_NAME, 'test_reminder_2')[0].id])
示例#4
0
def show_task(user_name, args, config):
    try:
        tasks = queries.get_tasks(user_name, args.title, args.category,
                                  args.deadline, args.priority, args.status,
                                  args.id)
    except ObjectDoesNotFound as e:
        print(e, file=sys.stderr)
        return

    calendar = nxCalendar(datetime.today())
    linked_objects = []
    try:
        for task in tasks:
            if task.deadline is not None:
                cdate = ColoredDate(task.deadline.date(),
                                    int(config['colors']['task_bg']),
                                    int(config['colors']['foreground']))
                linked_objects.append(cdate)
    except KeyError:
        print("Your config file is incorrect, please, check 'colors' section.")
        show_task_table(tasks, config)
        return
    calendar.linked_objects += linked_objects
    try:
        month_num = int(config['nxcalendar']['month_num'])
        if not 0 < month_num < 7:
            raise ValueError('month_num is integer in range(0, 7),'
                             'please, check your config file.')
    except ValueError as e:
        print(e, file=sys.stderr)
        show_task_table(tasks, config)
        return

    calendar.show(month_num)
    show_task_table(tasks, config)
示例#5
0
def show_tasks(request):
    try:
        tasks = queries.get_tasks(request.user.username)
    except:
        tasks = None
    filters_form = TaskFiltersForm()
    return render(request, 'nxtodoapp/task/tasks.html', {
        "tasks": tasks,
        "filters_form": filters_form
    })
示例#6
0
def filter_tasks(request):
    if request.POST:
        filters = TaskFiltersForm(request.POST)
        tasks = queries.get_tasks(request.user.username)
        if filters.is_valid():
            try:
                tasks = queries.get_tasks(
                    request.user.username,
                    title=filters.cleaned_data['title'] or None,
                    category=filters.cleaned_data['category'] or None,
                    deadline=filters.cleaned_data['deadline'] or None,
                    priority=filters.cleaned_data['priority'] or None,
                    status=filters.cleaned_data['status'] or None,
                    orderby=filters.cleaned_data['orderby'] or None)
            except:
                tasks = None
        return render(request, 'nxtodoapp/task/tasks.html', {
            "tasks": tasks,
            "filters_form": filters
        })
示例#7
0
 def tearDownClass(cls):
     queries.get_plans(USER_NAME, 'unique_plan').delete()
     queries.get_tasks(USER_NAME, category='test').delete()
     queries.remove_user(USER_NAME)
示例#8
0
    def test_check_plans(self):
        queries.check_plans(USER_NAME, now=datetime(2018, 6, 6, 15))
        self.assertEqual(
            len(queries.get_tasks(USER_NAME, title='test_task_1')), 1)
        self.assertEqual(
            len(queries.get_tasks(USER_NAME, title='test_task_2')), 1)

        queries.check_plans(USER_NAME, now=datetime(2018, 6, 7, 6, 30))
        self.assertEqual(
            len(queries.get_tasks(USER_NAME, title='test_task_1')), 2)
        self.assertEqual(
            len(queries.get_tasks(USER_NAME, title='test_task_2')), 2)
        self.assertEqual(
            len(queries.get_reminders(USER_NAME,
                                      description='test_reminder_1')), 1)
        self.assertEqual(
            len(queries.get_reminders(USER_NAME,
                                      description='test_reminder_2')), 1)

        queries.check_plans(USER_NAME, now=datetime(2018, 6, 7, 9, 3))
        self.assertEqual(
            len(queries.get_tasks(USER_NAME, title='test_task_1')), 3)
        self.assertEqual(
            len(queries.get_tasks(USER_NAME, title='test_task_2')), 3)
        self.assertEqual(
            len(queries.get_reminders(USER_NAME,
                                      description='test_reminder_1')), 1)
        self.assertEqual(
            len(queries.get_reminders(USER_NAME,
                                      description='test_reminder_2')), 1)

        queries.check_plans(USER_NAME, now=datetime(2018, 6, 7, 10, 30))
        self.assertEqual(
            len(queries.get_tasks(USER_NAME, title='test_task_1')), 4)
        self.assertEqual(
            len(queries.get_tasks(USER_NAME, title='test_task_2')), 4)

        queries.check_plans(USER_NAME, now=datetime(2018, 6, 9, 10, 55))
        self.assertEqual(
            len(queries.get_tasks(USER_NAME, title='test_task_1')), 5)
        self.assertEqual(
            len(queries.get_tasks(USER_NAME, title='test_task_2')), 5)

        queries.check_plans(USER_NAME, now=datetime(2018, 6, 16, 10))
        self.assertEqual(
            len(queries.get_tasks(USER_NAME, title='test_task_1')), 6)
        self.assertEqual(
            len(queries.get_tasks(USER_NAME, title='test_task_2')), 6)

        queries.check_plans(USER_NAME, now=datetime(2018, 6, 16, 11))
        self.assertEqual(
            len(queries.get_tasks(USER_NAME, title='test_task_1')), 6)
        self.assertEqual(
            len(queries.get_tasks(USER_NAME, title='test_task_2')), 6)