forked from apluslms/a-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
154 lines (129 loc) · 6.52 KB
/
tests.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
from django.contrib.auth.models import User
from django.test import TestCase
from course.models import CourseInstance
from exercise.submission_models import Submission
from exercise.exercise_models import BaseExercise, ExerciseWithAttachment
from exercise.submission_models import Submission
class CourseCloneTests(TestCase):
fixtures = [ 'doc/initial_data.json' ]
def setUp(self):
self.user = User(username='testUser')
self.user.set_password('testPassword')
self.user.save()
def test_course_clone(self):
instance = CourseInstance.objects.get(id=1)
instance.course.teachers.add(self.user.userprofile)
instance_url = instance.url
instance_str = str(instance)
visible = instance.visible_to_students
assistant_names = self._as_names(instance.assistants.all())
module_names = self._as_names(instance.course_modules.all())
url = instance.get_url('course-clone')
self.client.login(username='testUser', password='testPassword')
response = self.client.post(url, { 'url': 'another' }, follow=True)
self.assertEqual(response.status_code, 200)
self.assertNotContains(response, "alert alert-danger")
self.assertContains(response, "alert alert-success")
instance = CourseInstance.objects.get(id=1)
self.assertEqual(instance.url, instance_url)
self.assertEqual(str(instance), instance_str)
self.assertEqual(instance.visible_to_students, visible)
self.assertEqual(self._as_names(instance.assistants.all()), assistant_names)
self.assertEqual(self._as_names(instance.course_modules.all()), module_names)
new_instance = CourseInstance.objects.get(course=instance.course, url="another")
self.assertEqual(str(new_instance), instance_str)
self.assertFalse(new_instance.visible_to_students)
self.assertEqual(self._as_names(new_instance.assistants.all()), assistant_names)
self.assertEqual(self._as_names(new_instance.course_modules.all()), module_names)
old_modules = list(instance.course_modules.all())
new_modules = list(new_instance.course_modules.all())
self.assertEqual(len(old_modules), len(new_modules))
for i in range(len(old_modules)):
self.assertEqual(old_modules[i].url, new_modules[i].url)
self.assertEqual(
self._as_names(old_modules[i].flat_learning_objects(False)),
self._as_names(new_modules[i].flat_learning_objects(False))
)
self.assertEqual(
self._as_class(old_modules[i].flat_learning_objects(False)),
self._as_class(new_modules[i].flat_learning_objects(False))
)
def test_clone_submissions(self):
instance = CourseInstance.objects.get(id=1)
module = instance.course_modules.first()
n = module.learning_objects.count()
exercise = ExerciseWithAttachment(
category=instance.categories.first(),
course_module=instance.course_modules.first(),
url="",
name="Clone Test",
)
exercise.save()
self.assertEqual(module.learning_objects.count(), n + 1)
submission = Submission(exercise=exercise)
submission.save()
submission.submitters.add(self.user.userprofile)
self.assertEqual(exercise.submissions.count(), 1)
from .operations.clone import clone
new_instance = clone(instance, 'cloned')
new_module = new_instance.course_modules.first()
self.assertEqual(instance.course_modules.count(), new_instance.course_modules.count())
self.assertEqual(module.learning_objects.count(), n + 1)
self.assertEqual(new_module.learning_objects.count(), n + 1)
self.assertEqual(ExerciseWithAttachment.objects.filter(course_module=module).count(), 1)
self.assertEqual(ExerciseWithAttachment.objects.filter(course_module=new_module).count(), 1)
new_exercise = ExerciseWithAttachment.objects.filter(course_module=new_module).first()
self.assertEqual(exercise.submissions.count(), 1)
self.assertEqual(new_exercise.submissions.count(), 0)
def _as_names(self, items):
return [a.name for a in items]
def _as_class(self, items):
return [a.as_leaf_class().__class__ for a in items]
class BatchAssessTest(TestCase):
fixtures = [ 'doc/initial_data.json' ]
def setUp(self):
self.teacher = User(username='testUser')
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.save()
def test_batch_assess(self):
from json import dumps
instance = CourseInstance.objects.get(id=1)
instance.course.teachers.add(self.teacher.userprofile)
exercise = BaseExercise.objects.get(id=1)
url = instance.get_url('batch-assess')
json_to_post = dumps({
'objects': [
{
'students_by_student_id': [self.student.userprofile.student_id],
'feedback': 'Generic exercise feedback',
'grader': self.teacher.userprofile.id,
'exercise_id': 1,
'submission_time': '2014-09-24 11:50',
'points': 99
}
]
})
self.client.login(username='testUser', password='testPassword')
#response = self.client.post('/aplus1/basic_instance/teachers/batch-assess/',
# {'submissions_json': json_to_post}, follow=True)
# CHANGED! Batch submissions cannot be created if student has not already submitted
#at least one exercise to the course
#self.assertContains(response, "123TEST is not one of the available choices.")
sub = Submission.objects.create(
exercise=exercise,
grader=self.teacher.userprofile,
status=Submission.STATUS_ERROR)
sub.submitters.add(self.student.userprofile)
response = self.client.post('/aplus1/basic_instance/teachers/batch-assess/',
{'submissions_json': json_to_post}, follow=True)
self.assertContains(response, 'New submissions stored.')
subs = exercise.get_submissions_for_student(self.student.userprofile, exclude_errors=True)
self.assertEqual(len(subs), 1)
sub = subs.first()
self.assertEqual(sub.feedback, 'Generic exercise feedback')
self.assertEqual(sub.grade, 99)