Exemplo n.º 1
0
    def test_edit_task(self):
        with self.assertRaises(PermissionError):
            queries.edit_task('user_readonly', self.task_id, 'new_title')

        queries.edit_task(EXECUTOR,
                          self.task_id,
                          title='new_title',
                          deadline=datetime(2018, 7, 1))

        self.assertEqual(queries.get_task(self.task_id).title, 'new_title')
        self.assertEqual(
            queries.get_task(self.task_id).deadline, datetime(2018, 7, 1))
Exemplo n.º 2
0
def task_details(request, id):
    try:
        task = queries.get_task(id)
    except:
        return redirect('tasks:details', id=id)
    access_level = UserTasks.objects.get(user=queries.get_user(
        request.user.username),
                                         task=task).access_level
    readonly = True if access_level == AccessLevels.READONLY.value else False

    subtask_form = SubtaskForm(request.user.username, id)
    owner_form = OwnersForm(request.user.username)
    reminder_form = ReminderForm(request.user.username, id, Entities.TASK)
    filters_form = TaskFiltersForm()

    return render(
        request, 'nxtodoapp/task/task_details.html', {
            "task": task,
            "subtask_form": subtask_form,
            "owner_form": owner_form,
            "reminder_form": reminder_form,
            "task_owners": queries.get_objects_owners(task),
            "filters_form": filters_form,
            "readonly": readonly
        })
Exemplo n.º 3
0
def complete_task(user_name, task_id):
    """
    Complete task if it can be completed.
    """
    task = get_task(task_id)
    if task.can_complete():
        task.status = Statuses.FULFILLED.value
        task.save()
    else:
        msg = ("You can't complete '{}' task, "
               "because it has uncompleted subtasks".format(task_id))
        raise CompletionError(msg)
Exemplo n.º 4
0
def edit_task(request, id):
    task = queries.get_task(id)
    form = TaskForm(instance=task, initial={'deadline': task.deadline})
    if request.POST:
        form = TaskForm(request.POST, instance=task)
        if form.is_valid():
            task = form.save(commit=False)
            task.save()
            return redirect('tasks:details', id=task.id)
    filters_form = TaskFiltersForm()
    return render(request, 'nxtodoapp/task/task_edit.html', {
        'form': form,
        'filters_form': filters_form
    })
Exemplo n.º 5
0
 def get_choices(self, username, obj_id, obj_type):
     choices = ()
     user = queries.get_user(username)
     if obj_type == Entities.TASK:
         entity = queries.get_task(obj_id)
     if obj_type == Entities.EVENT:
         entity = queries.get_event(obj_id)
     if obj_type == Entities.PLAN:
         entity = queries.get_plan(obj_id)
     ids_for_exclude = [reminder.id for reminder in entity.reminders.all()]
     for reminder in user.reminder_set.all().exclude(
             id__in=ids_for_exclude):
         choices += ((reminder.id, reminder.id), )
     return choices
 def test_add_subtasks_to_task(self):
     with self.assertRaises(PermissionError):
         queries.add_subtasks_to_task('user_readonly', self.task_1_id, [1])
     queries.add_subtasks_to_task(EXECUTOR, self.task_1_id,
                                  [self.task_2_id])
     self.assertTrue(queries.get_task(self.task_1_id).subtasks.filter(
         title='task_2').exists())
     owner = Owner(EXECUTOR, AccessLevels.EDIT.value)
     queries.add_owners_to_task(ADMINS_NAME, self.task_2_id, [owner])
     queries.add_owners_to_task(ADMINS_NAME, self.task_3_id, [owner])
     queries.add_subtasks_to_task(EXECUTOR, self.task_2_id,
                                  [self.task_3_id])
     with self.assertRaises(Looping):
         queries.add_subtasks_to_task(EXECUTOR, self.task_3_id,
                                      [self.task_1_id])
 def test_add_owners_to_task(self):
     owners = [
         Owner(EXECUTOR, AccessLevels.EDIT.value),
         Owner('user_readonly', AccessLevels.READONLY.value),
         Owner('user_2', AccessLevels.EDIT),
         Owner('user_3', AccessLevels.READONLY)
     ]
     queries.add_owners_to_task(ADMINS_NAME, self.task_1_id, owners)
     task = queries.get_task(self.task_1_id)
     self.assertEqual(
         len(task.user_set.all()),
         4
     )
     task_owners = [owner.name for owner in task.user_set.all()]
     some_people = [EXECUTOR, 'user_readonly', 'user_2', 'user_3']
     self.assertEqual(task_owners.sort(), some_people.sort())
 def test_remove_task(self):
     with self.assertRaises(PermissionError):
         queries.remove_task('user_readonly', self.task_id)
     queries.remove_task(EXECUTOR, self.task_id)
     with self.assertRaises(ObjectDoesNotFound):
         queries.get_task(self.task_id)
 def test_add_reminders_to_task(self):
     task = queries.get_task(self.task_1_id)
     self.assertEqual(len(task.reminders.all()), 0)
     queries.add_reminders_to_task(EXECUTOR, self.task_1_id,
                                   [self.reminder_1_id])
     self.assertEqual(len(task.reminders.all()), 1)
Exemplo n.º 10
0
 def test_get_objects_owners(self):
     owners = queries.get_objects_owners(queries.get_task(self.task_1_id))
     self.assertEqual(len(owners), 2)
Exemplo n.º 11
0
 def test_get_task(self):
     self.assertEqual(
         queries.get_task(self.task_1_id).deadline,
         datetime(2018, 6, 14, 3))
Exemplo n.º 12
0
 def test_complete_task(self):
     with self.assertRaises(PermissionError):
         queries.complete_task('user_readonly', self.task_id)
     queries.complete_task(EXECUTOR, self.task_id)
     self.assertEqual(
         queries.get_task(self.task_id).status, Statuses.FULFILLED.value)