forked from apluslms/a-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
147 lines (126 loc) · 6.35 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
from datetime import datetime, timedelta
from django.contrib.auth.models import User
from django.test import TestCase
from course.models import Course, CourseInstance
from notification.models import Notification
class NotificationTest(TestCase):
def setUp(self):
self.student = User(username="testUser", first_name="Superb", last_name="Student", email="test@aplus.com")
self.student.set_password("testPassword")
self.student.save()
self.student_profile = self.student.userprofile
self.teacher = User(username="teacher", first_name="Tedious", last_name="Teacher", email="teacher@aplus.com", is_staff=True)
self.teacher.set_password("teacherPassword")
self.teacher.save()
self.teacher_profile = self.teacher.userprofile
self.superuser = User(username="superuser", first_name="Super", last_name="User", email="superuser@aplus.com", is_superuser=True)
self.superuser.set_password("superuserPassword")
self.superuser.save()
self.superuser_profile = self.superuser.userprofile
self.course = Course.objects.create(
name="test course",
code="123456",
url="Course-Url"
)
self.course.teachers.add(self.teacher.userprofile)
self.today = datetime.now()
self.tomorrow = self.today + timedelta(days=1)
self.two_days_from_now = self.tomorrow + timedelta(days=1)
self.course_instance = CourseInstance.objects.create(
instance_name="Fall 2011",
website="http://www.example.com",
starting_time=self.today,
ending_time=self.tomorrow,
course=self.course,
url="T-00.1000_2011"
)
self.course_instance2 = CourseInstance.objects.create(
instance_name="Fall 2011 day 2",
website="http://www.example.com",
starting_time=self.tomorrow,
ending_time=self.two_days_from_now,
course=self.course,
url="T-00.1000_d2"
)
self.notification = Notification.objects.create(
subject="testSubject",
notification="testNotification",
sender=self.student.userprofile,
recipient=self.teacher.userprofile,
course_instance=self.course_instance
)
def test_notification_send(self):
notifications = Notification.objects.all()
self.assertEqual(1, len(notifications))
self.assertEqual(self.student.userprofile, notifications[0].sender)
self.assertEqual(self.teacher.userprofile, notifications[0].recipient)
self.assertEqual(self.course_instance, notifications[0].course_instance)
self.assertEqual("testSubject", notifications[0].subject)
self.assertEqual("testNotification", notifications[0].notification)
self.assertFalse(notifications[0].seen)
Notification.send(self.teacher.userprofile, self.student.userprofile, self.course_instance, "subject", "notification")
notifications = Notification.objects.all()
self.assertEqual(2, len(notifications))
self.assertEqual(self.teacher.userprofile, notifications[0].sender)
self.assertEqual(self.student.userprofile, notifications[0].recipient)
self.assertEqual(self.course_instance, notifications[0].course_instance)
self.assertEqual("subject", notifications[0].subject)
self.assertEqual("notification", notifications[0].notification)
self.assertFalse(notifications[0].seen)
self.assertEqual(self.student.userprofile, notifications[1].sender)
self.assertEqual(self.teacher.userprofile, notifications[1].recipient)
self.assertEqual(self.course_instance, notifications[1].course_instance)
self.assertEqual("testSubject", notifications[1].subject)
self.assertEqual("testNotification", notifications[1].notification)
self.assertFalse(notifications[1].seen)
def test_notification_mark_as_seen(self):
self.assertFalse(self.notification.seen)
self.notification.mark_as_seen()
self.assertTrue(self.notification.seen)
def test_notification_string(self):
self.assertEqual("To:teacher, testSubject, testNotification", str(self.notification))
def test_notification_unread_count(self):
self.notification1 = Notification.objects.create(
subject="test1",
notification="testNotification1",
sender=self.superuser_profile,
recipient=self.student_profile,
course_instance=self.course_instance
)
self.notification2 = Notification.objects.create(
subject="test2",
notification="testNotification2",
sender=self.superuser_profile,
recipient=self.teacher_profile,
course_instance=self.course_instance
)
self.notification3 = Notification.objects.create(
subject="test3",
notification="testNotification3",
sender=self.superuser_profile,
recipient=self.student_profile,
course_instance=self.course_instance2
)
self.notification4 = Notification.objects.create(
subject="test4",
notification="testNotification4",
sender=self.superuser_profile,
recipient=self.teacher_profile,
course_instance=self.course_instance
)
self.notification5 = Notification.objects.create(
subject="test5",
notification="testNotification5",
sender=self.superuser_profile,
recipient=self.student_profile,
course_instance=self.course_instance2
)
self.notification.mark_as_seen()
self.assertEqual(3, Notification.get_unread_count(self.student_profile))
self.assertEqual(2, Notification.get_unread_count(self.teacher_profile))
self.assertEqual(0, Notification.get_unread_count(self.superuser_profile))
def test_notification_unread_course_instances(self):
self.assertEqual(0, len(Notification.get_unread_course_instances(self.student_profile)))
self.assertEqual(1, len(Notification.get_unread_course_instances(self.teacher_profile)))
self.assertEqual(0, len(Notification.get_unread_course_instances(self.superuser_profile)))
self.assertTrue(self.course_instance in Notification.get_unread_course_instances(self.teacher_profile))