forked from apluslms/a-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
39 lines (32 loc) · 1.31 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
from lib.testdata import CourseTestCase
from .cache import CachedNotifications
from .models import Notification
class NotificationTest(CourseTestCase):
def test_notifications(self):
Notification.send(self.teacher.userprofile, self.submission)
Notification.send(None, self.submission)
Notification.send(None, self.submission3)
cn = CachedNotifications(self.student)
self.assertEqual(cn.count(), 2)
cn = CachedNotifications(self.user)
self.assertEqual(cn.count(), 1)
n = Notification.objects.get(id=cn.notifications()[0]['id'])
n.seen = True
n.save()
cn = CachedNotifications(None)
self.assertEqual(cn.count(), 0)
cn = CachedNotifications(self.user)
self.assertEqual(cn.count(), 0)
cn = CachedNotifications(self.student)
self.assertEqual(cn.count(), 2)
for n in cn.notifications():
if n['submission_id'] == self.submission.id:
n = Notification.objects.get(id=n['id'])
n.seen = True
n.save()
break
cn = CachedNotifications(self.student)
self.assertEqual(cn.count(), 1)
Notification.remove(self.submission3)
cn = CachedNotifications(self.student)
self.assertEqual(cn.count(), 0)