def test_task_tag_form_filled(self): """ test additional form content """ # get object taskname_id = Taskname.objects.get( taskname_name='taskname_1').taskname_id # get object taskpriority_id = Taskpriority.objects.get( taskpriority_name='prio_1').taskpriority_id # get object taskstatus_id = Taskstatus.objects.get( taskstatus_name='taskstatus_1').taskstatus_id # get object tag_1_id = Tag.objects.get(tag_name='tag_1').tag_id tag_2_id = Tag.objects.get(tag_name='tag_2').tag_id # get object form = TaskForm( data={ 'taskname': taskname_id, 'taskpriority': taskpriority_id, 'taskstatus': taskstatus_id, 'tag': [tag_1_id, tag_2_id], }) # compare self.assertTrue(form.is_valid())
def test_task_form_empty(self): """ test minimum form requirements / INVALID """ # get object form = TaskForm(data={}) # compare self.assertFalse(form.is_valid())
def test_task_parent_task_form_filled(self): """ test additional form content """ # get object taskname_id = Taskname.objects.get( taskname_name='taskname_1').taskname_id # get object taskpriority_id = Taskpriority.objects.get( taskpriority_name='prio_1').taskpriority_id # get object taskstatus_id = Taskstatus.objects.get( taskstatus_name='taskstatus_1').taskstatus_id # get object taskname_1 = Taskname.objects.get(taskname_name='taskname_1') # get object task_id = Task.objects.get(taskname=taskname_1).task_id # get object form = TaskForm( data={ 'taskname': taskname_id, 'taskpriority': taskpriority_id, 'taskstatus': taskstatus_id, 'parent_task': task_id, }) # compare self.assertTrue(form.is_valid())
def tasks_edit(request, pk): task = get_object_or_404(Task, pk=pk) if request.method == 'POST': form = TaskForm(request.POST, instance=task) if form.is_valid(): task = form.save(commit=False) task.task_modified_by_user_id = request.user # adapt starting and finishing time corresponding to taskstatus if task.taskstatus == Taskstatus.objects.get( taskstatus_name="Pending"): task.task_started_time = None task.task_finished_time = None elif task.taskstatus == Taskstatus.objects.get( taskstatus_name="Working"): task.task_started_time = timezone.now() task.task_finished_time = None elif task.taskstatus == Taskstatus.objects.get( taskstatus_name="Done"): task.task_finished_time = timezone.now() if task.task_started_time == None: task.task_started_time = timezone.now() task.save() form.save_m2m() task.logger(str(request.user), " TASK_EDIT_EXECUTED") messages.success(request, 'Task edited') return redirect('/tasks/' + str(task.task_id)) else: form = TaskForm(instance=task) task.logger(str(request.user), " TASK_EDIT_ENTERED") return render(request, 'dfirtrack_main/task/tasks_edit.html', {'form': form})
def test_task_taskname_form_filled(self): """ test minimum form requirements / INVALID """ # get object taskname_id = Taskname.objects.get(taskname_name='taskname_1').taskname_id # get object form = TaskForm(data = { 'taskname': taskname_id, }) # compare self.assertFalse(form.is_valid())
def test_task_taskstatus_form_filled(self): """ test minimum form requirements / VALID """ # get object taskname_id = Taskname.objects.get(taskname_name='taskname_1').taskname_id # get object taskpriority_id = Taskpriority.objects.get(taskpriority_name='prio_1').taskpriority_id # get object taskstatus_id = Taskstatus.objects.get(taskstatus_name='taskstatus_1').taskstatus_id # get object form = TaskForm(data = { 'taskname': taskname_id, 'taskpriority': taskpriority_id, 'taskstatus': taskstatus_id, }) # compare self.assertTrue(form.is_valid())
def tasks_add(request): if request.method == 'POST': form = TaskForm(request.POST) if form.is_valid(): task = form.save(commit=False) task.task_created_by_user_id = request.user task.task_modified_by_user_id = request.user # adapt starting and finishing time corresponding to taskstatus if task.taskstatus == Taskstatus.objects.get( taskstatus_name="Working"): task.task_started_time = timezone.now() elif task.taskstatus == Taskstatus.objects.get( taskstatus_name="Done"): task.task_started_time = timezone.now() task.task_finished_time = timezone.now() task.save() form.save_m2m() task.logger(str(request.user), " TASK_ADD_EXECUTED") messages.success(request, 'Task added') if 'system' in request.GET: system = request.GET['system'] return redirect('/systems/' + str(system)) else: return redirect('/tasks/' + str(task.task_id)) else: if request.method == 'GET' and 'system' in request.GET: system = request.GET['system'] form = TaskForm( initial={ 'system': system, 'taskpriority': 2, 'taskstatus': 1, 'task_scheduled_time': timezone.now(), 'task_due_time': timezone.now(), }) else: form = TaskForm( initial={ 'taskpriority': 2, 'taskstatus': 1, 'task_scheduled_time': timezone.now(), 'task_due_time': timezone.now(), }) debug_logger(str(request.user), " TASK_ADD_ENTERED") return render(request, 'dfirtrack_main/task/tasks_add.html', {'form': form})
def tasks_edit(request, pk): task = get_object_or_404(Task, pk=pk) if request.method == 'POST': form = TaskForm(request.POST, instance=task) if form.is_valid(): task = form.save(commit=False) task.task_modified_by_user_id = request.user task.save() form.save_m2m() task.logger(str(request.user), " TASK_EDIT_EXECUTED") messages.success(request, 'Task edited') return redirect('/tasks/' + str(task.task_id)) else: form = TaskForm(instance=task) task.logger(str(request.user), " TASK_EDIT_ENTERED") return render(request, 'dfirtrack_main/task/tasks_edit.html', {'form': form})
def test_task_due_time_formatcheck(self): """ test input format """ # get object taskname_id = Taskname.objects.get(taskname_name='taskname_1').taskname_id # get object taskpriority_id = Taskpriority.objects.get(taskpriority_name='prio_1').taskpriority_id # get object taskstatus_id = Taskstatus.objects.get(taskstatus_name='taskstatus_1').taskstatus_id # get object form = TaskForm(data = { 'taskname': taskname_id, 'taskpriority': taskpriority_id, 'taskstatus': taskstatus_id, 'task_due_time': 'wrong format', }) # compare self.assertFalse(form.is_valid())
def test_task_assigned_to_user_id_form_filled(self): """ test additional form content """ # get object taskname_id = Taskname.objects.get(taskname_name='taskname_1').taskname_id # get object taskpriority_id = Taskpriority.objects.get(taskpriority_name='prio_1').taskpriority_id # get object taskstatus_id = Taskstatus.objects.get(taskstatus_name='taskstatus_1').taskstatus_id # get user test_user_id = User.objects.get(username='******').id # get object form = TaskForm(data = { 'taskname': taskname_id, 'taskpriority': taskpriority_id, 'taskstatus': taskstatus_id, 'task_assigned_to_user_id': test_user_id, }) # compare self.assertTrue(form.is_valid())