|
2 | 2 |
|
3 | 3 | import datetime |
4 | 4 |
|
5 | | -from django.test import TestCase, override_settings |
| 5 | +from django.db import connection |
| 6 | +from django.test import TestCase, override_settings, TransactionTestCase |
6 | 7 | from django.contrib.auth.models import User |
7 | 8 | from django.conf import settings |
8 | 9 | from schools.models import School |
|
11 | 12 | from issues.models import Issue, IssueStatus |
12 | 13 | from groups.models import Group |
13 | 14 | from years.models import Year |
14 | | -from tasks.models import Task, TaskTaken |
| 15 | +from tasks.models import Task, TaskTaken, TaskGroupRelations |
15 | 16 | from tasks.management.commands.check_task_taken_expires import Command as CheckTastTakenExpiresCommand |
16 | 17 |
|
17 | 18 | from bs4 import BeautifulSoup |
@@ -114,8 +115,16 @@ def setUp(self): |
114 | 115 | self.group.students.set([self.student]) |
115 | 116 | self.group.save() |
116 | 117 |
|
| 118 | + seminar_status = IssueStatus(name="seminar", tag=IssueStatus.STATUS_SEMINAR) |
| 119 | + seminar_status.save() |
| 120 | + issue_status_system = IssueStatusSystem() |
| 121 | + issue_status_system.name = "seminar" |
| 122 | + issue_status_system.save() |
| 123 | + issue_status_system.statuses.add(seminar_status) |
| 124 | + |
117 | 125 | self.course = Course.objects.create(name='course_name', |
118 | | - year=self.year) |
| 126 | + year=self.year, |
| 127 | + issue_status_system=issue_status_system) |
119 | 128 | self.course.groups.set([self.group]) |
120 | 129 | self.course.teachers.set([self.teacher]) |
121 | 130 | self.course.save() |
@@ -963,6 +972,81 @@ def test_set_task_mark_with_student(self): |
963 | 972 | self.assertEqual(table_body_sum.span.string.strip().strip('\n'), '3.0') |
964 | 973 |
|
965 | 974 |
|
| 975 | +@override_settings(LANGUAGE_CODE='en-EN', LANGUAGES=(('en', 'English'),)) |
| 976 | +class DeleteTaskTest(TransactionTestCase): |
| 977 | + def setUp(self): |
| 978 | + if connection.vendor == "sqlite": |
| 979 | + with connection.cursor() as cursor: |
| 980 | + # We need TransactionTestCase here to run this PRAGMA |
| 981 | + # Can be deleted after migrating to Django 2.2+ |
| 982 | + # Need this pragma for test_delete_task, |
| 983 | + # because we got a problems with FK while deleting tasks |
| 984 | + |
| 985 | + cursor.execute("PRAGMA foreign_keys = ON;") |
| 986 | + |
| 987 | + self.teacher_password = 'password1' |
| 988 | + self.teacher = User.objects.create_user(username='teacher', |
| 989 | + password=self.teacher_password) |
| 990 | + self.teacher.first_name = 'teacher_name' |
| 991 | + self.teacher.last_name = 'teacher_last_name' |
| 992 | + self.teacher.save() |
| 993 | + |
| 994 | + self.student_password = 'password2' |
| 995 | + self.student = User.objects.create_user(username='student', |
| 996 | + password=self.student_password) |
| 997 | + self.student.first_name = 'student_name' |
| 998 | + self.student.last_name = 'student_last_name' |
| 999 | + self.student.save() |
| 1000 | + |
| 1001 | + self.year = Year.objects.create(start_year=2016) |
| 1002 | + |
| 1003 | + self.group = Group.objects.create(name='group_name', |
| 1004 | + year=self.year) |
| 1005 | + self.group.students.set([self.student]) |
| 1006 | + self.group.save() |
| 1007 | + |
| 1008 | + seminar_status = IssueStatus(name="seminar", tag=IssueStatus.STATUS_SEMINAR) |
| 1009 | + seminar_status.save() |
| 1010 | + issue_status_system = IssueStatusSystem() |
| 1011 | + issue_status_system.name = "seminar" |
| 1012 | + issue_status_system.save() |
| 1013 | + issue_status_system.statuses.add(seminar_status) |
| 1014 | + |
| 1015 | + self.course = Course.objects.create(name='course_name', |
| 1016 | + year=self.year, |
| 1017 | + issue_status_system=issue_status_system) |
| 1018 | + self.course.groups.set([self.group]) |
| 1019 | + self.course.teachers.set([self.teacher]) |
| 1020 | + self.course.save() |
| 1021 | + |
| 1022 | + self.school = School.objects.create(name='school_name', |
| 1023 | + link='school_link') |
| 1024 | + self.school.courses.set([self.course]) |
| 1025 | + self.school.save() |
| 1026 | + |
| 1027 | + def test_delete_task(self): |
| 1028 | + client = self.client |
| 1029 | + task = Task.objects.create(title='task_title', |
| 1030 | + course=self.course, |
| 1031 | + score_max=10, |
| 1032 | + type=Task.TYPE_SIMPLE) |
| 1033 | + |
| 1034 | + task.set_position_in_new_group() |
| 1035 | + |
| 1036 | + self.assertTrue(client.login(username=self.teacher.username, password=self.teacher_password)) |
| 1037 | + data = { |
| 1038 | + 'course_id': task.id, |
| 1039 | + 'group_id': self.group.id, |
| 1040 | + 'task_deleted[]': task.id, |
| 1041 | + 'deleting_ids_from_groups': '{}', |
| 1042 | + } |
| 1043 | + response = client.post("/course/change_table_tasks_pos", data=data) |
| 1044 | + self.assertEqual(response.status_code, 200) |
| 1045 | + |
| 1046 | + self.assertEqual(Task.objects.filter(id=task.id).count(), 0) |
| 1047 | + self.assertEqual(TaskGroupRelations.objects.filter(task__id=task.id).count(), 0) |
| 1048 | + |
| 1049 | + |
966 | 1050 | class PythonTaskTest(TestCase): |
967 | 1051 | def setUp(self): |
968 | 1052 | User.objects.create_user(username="anytask") |
|
0 commit comments