ソースを参照

Add unit tests for notification model

master
David Winterbottom 13年前
コミット
1abaff7230
2個のファイルの変更40行の追加7行の削除
  1. 8
    7
      oscar/apps/customer/services.py
  2. 32
    0
      tests/unit/notification_tests.py

+ 8
- 7
oscar/apps/customer/services.py ファイルの表示

@@ -3,7 +3,7 @@ from django.db.models import get_model
3 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 8
     Send a simple notification to a user
9 9
     """
@@ -12,9 +12,10 @@ def notify(user, msg, category=None):
12 12
         subject=msg,
13 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 ファイルの表示

@@ -0,0 +1,32 @@
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)

読み込み中…
キャンセル
保存