def test_notification_signal(self): from notification.models import NoticeQueueBatch root = Post(author=self.user, plan=self.plan, content='post1') root.save() p1 = Post(author=self.user, plan=self.plan, content='post1', parent=root) p1.save() queue_length = len(NoticeQueueBatch.objects.all()) self.assertEqual(0, queue_length, msg="no post subscription, should be 0 after new post") subscription = PostSubscription(post=root, user=self.user, active=True) subscription.save() p2 = Post(author=self.user, plan=self.plan, content='post1', parent=root) p2.save() queue_length = len(NoticeQueueBatch.objects.all()) self.assertEqual(1, queue_length, msg="1 direct child") p11 = Post(author=self.user, plan=self.plan, content='post1', parent=p1) p11.save() queue_length = len(NoticeQueueBatch.objects.all()) self.assertEqual(2, queue_length, msg="2 direct comments") p111 = Post(author=self.user, plan=self.plan, content='post1', parent=p11) p111.save() queue_length = len(NoticeQueueBatch.objects.all()) self.assertEqual(3, queue_length, msg="2 direct + 1 subpost") pX = Post(author=self.user, plan=self.plan, content='post1') pX.save() queue_length = len(NoticeQueueBatch.objects.all()) self.assertEqual(3, queue_length, msg="still 3 notification, new not subscribed thread")
def test_get_root(self): root = Post(author=self.user, plan=self.plan, content='post1') root.save() p1 = Post(author=self.user, plan=self.plan, content='post1', parent=root) p1.save() p2 = Post(author=self.user, plan=self.plan, content='post1', parent=root) p2.save() p11 = Post(author=self.user, plan=self.plan, content='post1', parent=p1) p11.save() p111 = Post(author=self.user, plan=self.plan, content='post1', parent=p11) p111.save() self.assertEqual(root, root.get_root(), msg="self is root") self.assertEqual(root, p1.get_root(), msg="self.parent is root") self.assertEqual(root, p2.get_root(), msg="similar to p1") self.assertEqual(root, p11.get_root(), msg="second level") self.assertEqual(root, p111.get_root(), msg="third level")