-
Notifications
You must be signed in to change notification settings - Fork 73
/
testdata.py
169 lines (152 loc) · 5.37 KB
/
testdata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
from datetime import timedelta
from django.conf import settings
from django.contrib.auth.models import User
from django.test import TestCase
from django.utils import timezone
from course.models import (
Course,
CourseInstance,
CourseModule,
LearningObjectCategory,
)
from exercise.models import (
BaseExercise,
StaticExercise,
Submission,
)
class CourseTestCase(TestCase):
@classmethod
def setUpTestData(cls):
cls.setUpCourse()
cls.setUpSubmissions()
@classmethod
def setUpCourse(self):
self.now = timezone.now()
self.tomorrow = self.now + timedelta(days=1)
self.two_days_after = self.now + timedelta(days=2)
self.three_days_after = self.now + timedelta(days=3)
self.yesterday = self.now - timedelta(days=1)
self.two_days_before = self.now - timedelta(days=2)
self.user = User(username='testUser')
self.user.set_password('testPassword')
self.user.save()
self.teacher = User(username='testTeacher')
self.teacher.set_password('testPassword')
self.teacher.save()
self.student = User(username='testStudent')
self.student.set_password('testPassword')
self.student.save()
self.student.userprofile.student_id = "123TEST"
self.student.userprofile.organization = settings.LOCAL_ORGANIZATION
self.student.userprofile.save()
self.course = Course.objects.create(
url="course",
name="Test Course",
code="123456",
)
self.instance = CourseInstance.objects.create(
course=self.course,
url="instance",
instance_name="2016",
starting_time=self.now,
ending_time=self.tomorrow,
)
self.instance.add_teacher(self.teacher.userprofile)
self.instance.enroll_student(self.student)
self.module = CourseModule.objects.create(
course_instance=self.instance,
url="module",
name="Test Module",
points_to_pass=10,
opening_time=self.now,
closing_time=self.tomorrow,
late_submissions_allowed=True,
late_submission_deadline=self.two_days_after,
late_submission_penalty=0.2
)
self.module2 = CourseModule.objects.create(
course_instance=self.instance,
url="module2",
name="Test Module 2",
points_to_pass=0,
opening_time=self.tomorrow,
closing_time=self.two_days_after,
)
self.module0 = CourseModule.objects.create(
course_instance=self.instance,
url="module0",
name="Past Module",
points_to_pass=10,
opening_time=self.two_days_before,
closing_time=self.yesterday,
)
self.category = LearningObjectCategory.objects.create(
course_instance=self.instance,
name="Test Category",
points_to_pass=5,
)
self.exercise = StaticExercise.objects.create(
course_module=self.module,
category=self.category,
url='e1',
name="Test Exercise",
exercise_page_content='$$exercise$$content',
submission_page_content='$$exercise$$received',
points_to_pass=0,
max_points=100,
order=1,
)
self.exercise2 = StaticExercise.objects.create(
course_module=self.module,
category=self.category,
url='e2',
name="Test Exercise 2",
exercise_page_content='$$exercise2$$content',
submission_page_content='$$exercise2$$received',
points_to_pass=10,
max_points=100,
order=2,
)
self.exercise3 = StaticExercise.objects.create(
course_module=self.module2,
category=self.category,
url='e3',
name="Test Exercise 3",
exercise_page_content='$$exercise3$$content',
submission_page_content='$$exercise3$$received',
points_to_pass=0,
max_points=100,
)
self.exercise0 = BaseExercise.objects.create(
course_module=self.module0,
category=self.category,
url='b0',
name="Base Exercise 0",
service_url="http://localhost/",
points_to_pass=0,
max_points=100,
min_group_size=1,
max_group_size=2,
)
@classmethod
def setUpSubmissions(self):
self.submission = Submission.objects.create(
exercise=self.exercise,
submission_data={'submission':1},
feedback='$$submission$$feedback',
)
self.submission.submitters.add(self.student.userprofile)
self.submission.set_points(1,2)
self.submission.set_ready()
self.submission.save()
self.submission2 = Submission.objects.create(
exercise=self.exercise,
submission_data={'submission':2},
)
self.submission2.submitters.add(self.student.userprofile)
self.submission3 = Submission.objects.create(
exercise=self.exercise2,
submission_data={'submission':3},
)
self.submission3.submitters.add(self.student.userprofile)
self.submission3.submitters.add(self.user.userprofile)