Commits

Angel Velasquez  committed 94a9950

Adding tests for validating status parameter on the om_write and pm_broadcast functions

  • Participants
  • Parent commits 5533cb1

Comments (0)

Files changed (1)

File postman/tests.py

         except KeyError: # happens once at the setUp
             pass
         reload(get_resolver(get_urlconf()).urlconf_module)
-    
+
 class ViewTest(BaseTest):
     """
     Test the views.
                   |<------|             x    x
                   |------>
                    ------>
-                   ------>              x    
-                   <------              
+                   ------>              x
+                   <------
                     ...---
               x       X---
         """
 
-        m1 = self.c12(moderation_status=STATUS_PENDING); 
+        m1 = self.c12(moderation_status=STATUS_PENDING);
         m2 = self.c12(moderation_status=STATUS_REJECTED, recipient_deleted_at=now())
         m3 = self.c12()
         m3.read_at, m3.thread = now(), m3
                   |<------|   X    X    x    x
                   |------>
          X         ------>    X
-                   ------>         X    x    
-              X    <------              
+                   ------>         X    x
+              X    <------
                     ...---         X
               x       X---    X
         """
         self.check_status(r.parent, status=STATUS_ACCEPTED, thread=parent, is_replied=True)
         # accepted -> rejected: parent is no more replied
         r.update_parent(STATUS_ACCEPTED)
-        p = Message.objects.get(pk=parent.pk) 
+        p = Message.objects.get(pk=parent.pk)
         self.check_status(p, status=STATUS_ACCEPTED, thread=parent)
         # note: accepted -> rejected, with the existence of another suitable reply
         # is covered in the accepted -> pending case
         # pending -> pending: no change. In real case, parent.replied_at would be from another reply object
         r.update_parent(STATUS_PENDING)
         self.check_status(r.parent, status=STATUS_ACCEPTED, thread=parent, is_replied=True)
-        # rejected -> pending: no change. In real case, parent.replied_at would be from another reply object 
+        # rejected -> pending: no change. In real case, parent.replied_at would be from another reply object
         r.update_parent(STATUS_REJECTED)
         self.check_status(r.parent, status=STATUS_ACCEPTED, thread=parent, is_replied=True)
         # accepted -> pending: parent is still replied but by another object
         # use 'H', 'd', 'm' instead of 'G', 'j', 'n' because no strftime equivalents
         t = Template('{% load postman_tags %}{{ date|compact_date:"'+format+'" }}')
         self.assertEqual(t.render(Context({'date': date})), value)
-    
+
     def test_compact_date(self):
         "Test '|compact_date'."
         dt = now()
         self.assertEqual(ctx['var'], 1)
         self.assertRaises(TemplateSyntaxError, self.check_postman_unread, '', self.user1, 'as var extra')
         self.assertRaises(TemplateSyntaxError, self.check_postman_unread, '', self.user1, 'As var')
-    
+
     def check_order_by(self, keyword, value_list, context=None):
         t = Template("{% load postman_tags %}{% postman_order_by " + keyword +" %}")
         r = t.render(Context({'gets': QueryDict(context)} if context else {}))
         self.check_message(m)
         self.assertEqual(len(mail.outbox), 1)
 
+    def test_pm_broadcast_moderated(self):
+        "Test the case of a single recipient, routing to pending messages"
+        pm_broadcast(sender=self.user1, recipients=self.user2, subject='s', body='b', status=STATUS_PENDING)
+        m = Message.objects.get()
+        self.check_status(m, status=STATUS_PENDING, moderation_date=True,
+            sender_archived=True, sender_deleted_at=True)
+        self.check_now(m.sender_deleted_at)
+        self.check_now(m.moderation_date)
+        self.check_message(m)
+
+    def test_pm_broadcast_rejected(self):
+        "Test the case of a single recipient, routing to the rejected messages"
+        pm_broadcast(sender=self.user1, recipients=self.user2, subject='s', body='b', status=STATUS_REJECTED)
+        m = Message.objects.get()
+        self.check_status(m, status=STATUS_REJECTED, moderation_date=True,
+            sender_archived=True, sender_deleted_at=True)
+        self.check_now(m.sender_deleted_at)
+        self.check_now(m.moderation_date)
+        self.check_message(m)
+
     def test_pm_broadcast_skip_notification(self):
         "Test the notification skipping."
         pm_broadcast(sender=self.user1, recipients=self.user2, subject='s', skip_notification=True)
         m = Message.objects.get()
         self.check_status(m, status=STATUS_ACCEPTED, moderation_date=True, sender_deleted_at=True)
         self.check_now(m.sender_deleted_at)
+
+    def test_pm_write_status_moderated(self):
+        "Test the status parameter to moderated"
+        pm_write(sender=self.user1, recipient=self.user2, subject='s', auto_delete=True, status=STATUS_PENDING)
+        m = Message.objects.get()
+        self.check_status(m, status=STATUS_PENDING, moderation_date=True, sender_deleted_at=True)
+        self.check_now(m.sender_deleted_at)
+
+    def test_pm_write_status_rejected(self):
+        "Test the status parameter to rejected"
+        pm_write(sender=self.user1, recipient=self.user2, subject='s', auto_delete=True, status=STATUS_REJECTED)
+        m = Message.objects.get()
+        self.check_status(m, status=STATUS_REJECTED, moderation_date=True, sender_deleted_at=True)
+        self.check_now(m.sender_deleted_at)