def setUpClass(cls): setup_logger(LOGS_PATH, LOGS_LEVEL, LOGS_FORMAT) queries.add_user(EXECUTOR) queries.add_user('user_readonly') owners = [ Owner(EXECUTOR, AccessLevels.EDIT.value), Owner('user_readonly', AccessLevels.READONLY.value) ] cls.task_id = queries.add_task(EXECUTOR, 'task_1', 'test_task', 'category_1', datetime(2018, 6, 14, 3), 1, owners=owners) cls.event_id = queries.add_event(EXECUTOR, 'event_1', datetime(2018, 6, 20), datetime(2018, 6, 21), 'test_event', 'category_1', 1, 'Minsk', participants=owners)
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 add_plan(user_name, args): owners = [Owner(user_name, AccessLevels.EDIT.value)] if args.owners: owners += args.owners plan_id = queries.add_plan(user_name, args.title, args.description, args.category, args.priority, args.tasks, args.events, args.reminders, owners) print(plan_id)
def add_task(user_name, args): owners = [Owner(user_name, AccessLevels.EDIT.value)] if args.owners: owners += args.owners task_id = queries.add_task(user_name, args.title, args.description, args.category, args.deadline, args.priority, owners, args.reminders, args.subtasks) print(task_id)
def setUpClass(cls): setup_logger(LOGS_PATH, LOGS_LEVEL, LOGS_FORMAT) queries.add_user(EXECUTOR) queries.add_user('user_2') owners = [ Owner(EXECUTOR, AccessLevels.EDIT.value), Owner('user_2', AccessLevels.EDIT.value) ] cls.task_1_id = queries.add_task(EXECUTOR, 'task_1', 'test_task', 'category_1', datetime(2018, 6, 14, 3), 1, owners=owners) queries.add_task(EXECUTOR, 'task_2', 'test_task', 'category_2', datetime(2018, 6, 14, 10), 1, owners=owners) queries.add_task(EXECUTOR, 'task_3', 'test_task', 'category_1', datetime(2018, 6, 20, 3), 3, owners=owners) queries.add_task(EXECUTOR, 'task_4', 'test_task', 'category_2', datetime(2018, 6, 17, 3), 1, owners=owners) queries.add_task(EXECUTOR, 'task_5', 'test_task', 'category_1', datetime(2018, 6, 24, 3), 1, owners=owners)
def add_event(user_name, args): participants = [Owner(user_name, AccessLevels.EDIT.value)] if args.participants: participants += args.participants event_id = queries.add_event(user_name, args.title, args.fromdt, args.todt, args.description, args.category, args.priority, args.place, participants, args.reminders) print(event_id)
def add_participant(request, id): if request.POST: username = request.POST.get('owner') access_level = request.POST.get('access_level') try: queries.add_participants_to_event(request.user.username, id, [Owner(username, access_level)]) except Exception as e: messages.error(request, str(e)) return redirect('events:details', id=id)
def setUpClass(cls): setup_logger(LOGS_PATH, LOGS_LEVEL, LOGS_FORMAT) queries.add_user(EXECUTOR) queries.add_user('user_readonly') queries.add_user('user_1') owners = [ Owner(EXECUTOR, AccessLevels.EDIT.value), Owner('user_readonly', AccessLevels.READONLY.value) ] cls.task_id = queries.add_task(EXECUTOR, 'task_1', 'test_task', 'category_1', datetime(2018, 6, 14, 3), 1, owners=owners) cls.event_id = queries.add_event(EXECUTOR, 'event_1', datetime(2018, 6, 20), datetime(2018, 6, 21), 'test_event', 'category_1', 1, 'Minsk', participants=owners) cls.plan_id = queries.add_plan(EXECUTOR, 'plan_1', 'test_plan', 'category_2', owners=owners) cls.reminder_id = queries.add_reminder( EXECUTOR, 'test_reminder', None, datetime(2018, 6, 15, 13, 45), datetime(2018, 7, 1, 11, 10), timedelta(days=3), [datetime(2018, 6, 18, 18, 30), datetime(2018, 6, 20, 12)], timedelta(minutes=30), [0, 1])
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 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])
def add_plan(request): form = PlanForm() if request.POST: form = PlanForm(request.POST) if form.is_valid(): plan = form.save(commit=False) plan.created_by = request.user.username plan.save() queries.add_owners_to_plan( ADMINS_NAME, plan.id, [Owner(request.user.username, AccessLevels.EDIT.value)]) return redirect('plans:all') filters_form = PlanFiltersForm() return render(request, 'nxtodoapp/plan/plan_add.html', { 'form': form, 'filters_form': filters_form })
def add_event(request): form = EventForm() if request.POST: form = EventForm(request.POST) if form.is_valid(): event = form.save(commit=False) event.status = Statuses.INPROCESS.value event.created_by = request.user.username event.save() queries.add_participants_to_event( ADMINS_NAME, event.id, [Owner(request.user.username, AccessLevels.EDIT.value)]) return redirect('events:all') filters_form = EventFiltersForm() return render(request, 'nxtodoapp/event/event_add.html', { 'form': form, 'filters_form': filters_form })
def add_task(request): form = TaskForm() if request.POST: form = TaskForm(request.POST) if form.is_valid(): task = form.save(commit=False) task.status = Statuses.INPROCESS.value task.created_by = request.user.username task.save() queries.add_owners_to_task( ADMINS_NAME, task.id, [Owner(request.user.username, AccessLevels.EDIT.value)]) return redirect('tasks:all') filters_form = TaskFiltersForm() return render(request, 'nxtodoapp/task/task_add.html', { 'form': form, 'filters_form': filters_form })
def get_objects_owners(obj): """ Defines obj type and returns objects owners. """ type = obj.get_type() owners = [] for user in obj.user_set.all(): if type == Entities.TASK: relation = UserTasks.objects.get(user=user, task=obj) elif type == Entities.EVENT: relation = UserEvents.objects.get(user=user, event=obj) elif type == Entities.PLAN: relation = UserPlans.objects.get(user=user, plan=obj) else: raise TypeError owners.append(Owner(user.name, relation.access_level)) return owners
def test_add_tasks_to_plan(self): owner = Owner(EXECUTOR, AccessLevels.EDIT.value) queries.add_owners_to_plan(ADMINS_NAME, self.plan_id, [owner]) queries.add_tasks_to_plan(EXECUTOR, self.plan_id, [self.task_2_id, self.task_3_id]) self.assertEqual(len(queries.get_plan(self.plan_id).tasks.all()), 2)