Procházet zdrojové kódy

Add unit tests for notification model

master
David Winterbottom před 13 roky
rodič
revize
1abaff7230
2 změnil soubory, kde provedl 40 přidání a 7 odebrání
  1. 8
    7
      oscar/apps/customer/services.py
  2. 32
    0
      tests/unit/notification_tests.py

+ 8
- 7
oscar/apps/customer/services.py Zobrazit soubor

3
 Notification = get_model('notifications', 'Notification')
3
 Notification = get_model('notifications', 'Notification')
4
 
4
 
5
 
5
 
6
-def notify(user, msg, category=None):
6
+def notify_user(user, msg, category=None):
7
     """
7
     """
8
     Send a simple notification to a user
8
     Send a simple notification to a user
9
     """
9
     """
12
         subject=msg,
12
         subject=msg,
13
         category=category)
13
         category=category)
14
 
14
 
15
-def send_message(user, subject, body, category):
16
-    Notification.objects.create(
17
-        recipient=user,
18
-        subject=subject,
19
-        body=body,
20
-        category=category)
15
+
16
+def notify_users(users, msg, category=None):
17
+    """
18
+    Send a simple notification to an iterable of users
19
+    """
20
+    for user in users:
21
+        notify_user(user, msg, category)

+ 32
- 0
tests/unit/notification_tests.py Zobrazit soubor

1
+from django.test import TestCase
2
+from django.contrib.auth.models import User
3
+from django_dynamic_fixture import G
4
+
5
+from oscar.apps.notifications.models import Notification
6
+
7
+
8
+class TestANewNotification(TestCase):
9
+
10
+    def setUp(self):
11
+        # Don't save models for speed
12
+        self.notification = Notification(
13
+            recipient=User(),
14
+            subject="Hello")
15
+
16
+    def test_is_in_a_users_inbox(self):
17
+        self.assertEqual(Notification.INBOX, self.notification.location)
18
+
19
+    def test_is_not_read(self):
20
+        self.assertFalse(self.notification.is_read)
21
+
22
+
23
+class TestANotification(TestCase):
24
+
25
+    def setUp(self):
26
+        self.notification = Notification.objects.create(
27
+            recipient=G(User),
28
+            subject="Hello")
29
+
30
+    def test_can_be_archived(self):
31
+        self.notification.archive()
32
+        self.assertEqual(Notification.ARCHIVE, self.notification.location)

Načítá se…
Zrušit
Uložit