forked from apluslms/a-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
46 lines (37 loc) · 1.5 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
from datetime import timedelta
from django.contrib.auth.models import User
from django.test import TestCase
from django.utils import timezone
from course.models import Course, CourseInstance
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)