Exemple #1
0
 def test_user_comments(self):
     ct = ContentType.objects.get_for_model(self.user1)
     pk = self.user1.pk
     p = api.post_comment(content_type_id=ct.id, object_pk=pk,
                          user_id=pk, comment="Root message")
     self.assertTrue(p is not None)
     uc = api.get_user_comments(pk)
     self.assertEqual(len(uc), 1)
     c = api.post_reply(user_id=pk, comment="Reply", parent_id=p.id)
     self.assertTrue(c is not None)
     uc = api.get_user_comments(pk)
     self.assertEqual(len(uc), 2)
     c = api.post_reply(user_id=self.user2.pk, comment="Reply", parent_id=p.id)
     self.assertTrue(c is not None)
     uc = api.get_user_comments(pk)
     self.assertEqual(len(uc), 2)
     uc = api.get_user_comments(self.user2.pk)
     self.assertEqual(len(uc), 1)
     uc = api.get_user_comments(self.user2.pk, content_type_id=ct.id)
     self.assertEqual(len(uc), 1)
     uc = api.get_user_comments(
         self.user2.pk, content_type_id=ct.id, object_pk=pk)
     self.assertEqual(len(uc), 1)
     uc = api.get_user_comments(
         self.user2.pk, content_type_id=ct.id, object_pk=pk, site_id=1)
Exemple #2
0
 def test_tree_depth(self):
     ct = ContentType.objects.get_for_model(self.user1)
     pk = self.user1.pk
     for _ in range(3):
         p = api.post_comment(content_type_id=ct.id, object_pk=pk,
                              user_id=pk, comment="Root message %s" % _)
         c = api.post_reply(user_id=pk, comment="Reply %s" % _, parent_id=p.id)
         self.assertTrue(c is not None)
         if settings.MAX_DEPTH > 2:
             r1 = api.post_reply(user_id=pk, comment="Reply %s 1" % _, parent_id=c.id)
             self.assertTrue(c is not None)
             r2 = api.post_reply(user_id=pk, comment="Reply %s 2" % _, parent_id=c.id)
             self.assertTrue(c is not None)
         if settings.MAX_DEPTH > 3:
             r1a = api.post_reply(user_id=pk, comment="Reply %s 3" % _, parent_id=r1.id)
             self.assertTrue(c is not None)
     tree = api.get_comments_as_tree(ct.id, pk)
     self.assertEqual(len(tree), 3)
     if settings.MAX_DEPTH == 2:
         self.assertEqual(len(tree[0].replies), 1)
     if settings.MAX_DEPTH > 2:
         self.assertEqual(len(tree[0].replies[0].replies), 2)
     if settings.MAX_DEPTH > 3:
         self.assertEqual(len(tree[0].replies[0].replies[0].replies), 1)
     tree = api.get_comments_limited_as_tree(ct.id, pk)
     self.assertEqual(len(tree), 3)
     if settings.MAX_DEPTH == 2:
         self.assertEqual(len(tree[0].replies), 1)
     if settings.MAX_DEPTH > 2:
         self.assertEqual(len(tree[0].replies[0].replies), 2)
     if settings.MAX_DEPTH > 3:
         self.assertEqual(len(tree[0].replies[0].replies[0].replies), 1)
Exemple #3
0
 def test_user_comments(self):
     ct = ContentType.objects.get_for_model(self.user1)
     pk = self.user1.pk
     p = api.post_comment(content_type_id=ct.id,
                          object_pk=pk,
                          user_id=pk,
                          comment="Root message")
     self.assertTrue(p is not None)
     uc = api.get_user_comments(pk)
     self.assertEqual(len(uc), 1)
     c = api.post_reply(user_id=pk, comment="Reply", parent_id=p.id)
     self.assertTrue(c is not None)
     uc = api.get_user_comments(pk)
     self.assertEqual(len(uc), 2)
     c = api.post_reply(user_id=self.user2.pk,
                        comment="Reply",
                        parent_id=p.id)
     self.assertTrue(c is not None)
     uc = api.get_user_comments(pk)
     self.assertEqual(len(uc), 2)
     uc = api.get_user_comments(self.user2.pk)
     self.assertEqual(len(uc), 1)
     uc = api.get_user_comments(self.user2.pk, content_type_id=ct.id)
     self.assertEqual(len(uc), 1)
     uc = api.get_user_comments(self.user2.pk,
                                content_type_id=ct.id,
                                object_pk=pk)
     self.assertEqual(len(uc), 1)
     uc = api.get_user_comments(self.user2.pk,
                                content_type_id=ct.id,
                                object_pk=pk,
                                site_id=1)
Exemple #4
0
   def test_open(self):
       ct = ContentType.objects.get_for_model(self.user1)
       pk = self.user1.pk
       p = api.post_comment(content_type_id=ct.id, object_pk=pk,
                            user_id=pk, comment="Root message")
       self.assertTrue(p is not None)
 # wrong user
       x = api.open_comment(p.id, self.user2)
       self.assertTrue(x is None)
       p = api.open_comment(p.id, self.user1)
       self.assertTrue(p is not None)
       self.assertTrue(p.is_open)
       c = api.post_reply(user_id=pk, comment="Reply", parent_id=p.id)
       self.assertTrue(c is not None)
       x = api.close_comment(p.id, self.user2)
       self.assertTrue(x is None)
       p = api.close_comment(p.id, self.user1)
       self.assertTrue(p is not None)
       self.assertFalse(p.is_open)
       c = api.post_reply(user_id=pk, comment="Reply", parent_id=p.id)
       self.assertEqual(c, None)
       c = api.open_comment(-1, self.user1)
       self.assertEqual(c, None)
       c = api.close_comment(-1, self.user1)
       self.assertEqual(c, None)
Exemple #5
0
 def test_open(self):
     ct = ContentType.objects.get_for_model(self.user1)
     pk = self.user1.pk
     p = api.post_comment(content_type_id=ct.id,
                          object_pk=pk,
                          user_id=pk,
                          comment="Root message")
     self.assertTrue(p is not None)
     # wrong user
     x = api.open_comment(p.id, self.user2)
     self.assertTrue(x is None)
     p = api.open_comment(p.id, self.user1)
     self.assertTrue(p is not None)
     self.assertTrue(p.is_open)
     c = api.post_reply(user_id=pk, comment="Reply", parent_id=p.id)
     self.assertTrue(c is not None)
     x = api.close_comment(p.id, self.user2)
     self.assertTrue(x is None)
     p = api.close_comment(p.id, self.user1)
     self.assertTrue(p is not None)
     self.assertFalse(p.is_open)
     c = api.post_reply(user_id=pk, comment="Reply", parent_id=p.id)
     self.assertEqual(c, None)
     c = api.open_comment(-1, self.user1)
     self.assertEqual(c, None)
     c = api.close_comment(-1, self.user1)
     self.assertEqual(c, None)
Exemple #6
0
 def test_tree_depth(self):
     ct = ContentType.objects.get_for_model(self.user1)
     pk = self.user1.pk
     for _ in range(3):
         p = api.post_comment(content_type_id=ct.id, object_pk=pk,
                              user_id=pk, comment="Root message %s" % _)
         c = api.post_reply(user_id=pk, comment="Reply %s" % _, parent_id=p.id)
         self.assertTrue(c is not None)
         if settings.MAX_DEPTH > 2:
             r1 = api.post_reply(user_id=pk, comment="Reply %s 1" % _, parent_id=c.id)
             self.assertTrue(c is not None)
             r2 = api.post_reply(user_id=pk, comment="Reply %s 2" % _, parent_id=c.id)
             self.assertTrue(c is not None)
         if settings.MAX_DEPTH > 3:
             r1a = api.post_reply(user_id=pk, comment="Reply %s 3" % _, parent_id=r1.id)
             self.assertTrue(c is not None)
     tree = api.get_comments_as_tree(ct.id, pk)
     self.assertEqual(len(tree), 3)
     if settings.MAX_DEPTH == 2:
         self.assertEqual(len(tree[0].replies), 1)
     if settings.MAX_DEPTH > 2:
         self.assertEqual(len(tree[0].replies[0].replies), 2)
     if settings.MAX_DEPTH > 3:
         self.assertEqual(len(tree[0].replies[0].replies[0].replies), 1)
     tree = api.get_comments_limited_as_tree(ct.id, pk)
     self.assertEqual(len(tree), 3)
     if settings.MAX_DEPTH == 2:
         self.assertEqual(len(tree[0].replies), 1)
     if settings.MAX_DEPTH > 2:
         self.assertEqual(len(tree[0].replies[0].replies), 2)
     if settings.MAX_DEPTH > 3:
         self.assertEqual(len(tree[0].replies[0].replies[0].replies), 1)
Exemple #7
0
   def test_post_reply(self):
       ct = ContentType.objects.get_for_model(self.user1)
       pk = self.user1.pk
       p = api.post_comment(content_type_id=ct.id, object_pk=pk,
                            user_id=pk, comment="Root message")
       self.assertEqual(p.path,  u'1'.zfill(settings.STEPLEN))
       c = api.post_reply(user_id=pk, comment="Reply", parent_id=p.id)
       self.assertEqual(c.path,  u'1'.zfill(settings.STEPLEN)+u'2'.zfill(settings.STEPLEN))
       self.assertEqual(c.get_parents()[0].id, p.id)
       self.assertEqual(p.get_replies()[0].id, c.id)
       tp = api.get_comment_thread(p.id)
       tc = api.get_comment_thread(c.id)
       self.assertEqual(len(tp), 2)
       self.assertEqual(len(tc), 2)
 # Non existing parent
       c = api.post_reply(user_id=pk, comment="Reply", parent_id=-1)
       self.assertEqual(c, None)
Exemple #8
0
 def test_post_reply(self):
     ct = ContentType.objects.get_for_model(self.user1)
     pk = self.user1.pk
     p = api.post_comment(content_type_id=ct.id, object_pk=pk,
                          user_id=pk, comment="Root message")
     self.assertEqual(p.path,  u'1'.zfill(settings.STEPLEN))
     c = api.post_reply(user_id=pk, comment="Reply", parent_id=p.id)
     self.assertEqual(c.path,  u'1'.zfill(settings.STEPLEN)+u'2'.zfill(settings.STEPLEN))
     self.assertEqual(c.get_parents()[0].id, p.id)
     self.assertEqual(p.get_replies()[0].id, c.id)
     tp = api.get_comment_thread(p.id)
     tc = api.get_comment_thread(c.id)
     self.assertEqual(len(tp), 2)
     self.assertEqual(len(tc), 2)
     # Non existing parent
     c = api.post_reply(user_id=pk, comment="Reply", parent_id=-1)
     self.assertEqual(c, None)
Exemple #9
0
 def test_replies(self):
     ct = ContentType.objects.get_for_model(self.user1)
     pk = self.user1.pk
     for _ in range(5):
         p = api.post_comment(content_type_id=ct.id, object_pk=pk,
                              user_id=pk, comment="Root message %s" % _)
         for __ in range(settings.REPLY_LIMIT+3):
             c = api.post_reply(user_id=pk, comment="Reply %s%s" % (_, __), parent_id=p.id)
     self.assertEqual(api.get_comments_limited(ct.id, pk).count(), 5*(settings.REPLY_LIMIT+1))
Exemple #10
0
 def test_replies(self):
     ct = ContentType.objects.get_for_model(self.user1)
     pk = self.user1.pk
     for _ in range(5):
         p = api.post_comment(content_type_id=ct.id, object_pk=pk,
                              user_id=pk, comment="Root message %s" % _)
         for __ in range(settings.REPLY_LIMIT+3):
             c = api.post_reply(user_id=pk, comment="Reply %s%s" % (_, __), parent_id=p.id)
     self.assertEqual(api.get_comments_limited(ct.id, pk).count(), 5*(settings.REPLY_LIMIT+1))