def test_render_comment_tree(self):
     from pprint import pprint as pp
     t = Template('{% load comments bearded_comments %}'
                  '{% render_comment_tree for site %}')
     s = Site.objects.get_current()
     c = Context({'site': s})
     utils.create_tcomment_tree(s)
     print(t.render(c))
     pp(TCommentNode.get_annotated_list())
     pp(TCommentNode.dump_bulk())
Пример #2
0
 def test_render_comment_tree(self):
     from pprint import pprint as pp
     t = Template('{% load comments bearded_comments %}'
                  '{% render_comment_tree for site %}')
     s = Site.objects.get_current()
     c = Context({'site': s})
     utils.create_tcomment_tree(s)
     print(t.render(c))
     pp(TCommentNode.get_annotated_list())
     pp(TCommentNode.dump_bulk())
Пример #3
0
def add_comment_node(sender, **kwargs):
    comment = kwargs['comment']
    request = kwargs['request']
    parent = request.POST['parent']
    if parent:
        pnode = TCommentNode.objects.get(pk=parent)
        node = pnode.add_child(comment=comment)
    else:
        node = TCommentNode.add_root(comment=comment)

    return True if node else False
    def test_parent_childnode_wasadded(self):
        parent_comment = create_tcomment()
        parent_comment.save()
        parent_node = TCommentNode.add_root(comment=parent_comment)
        comment = create_tcomment()
        comment.save()
        self.request.POST = {'parent': parent_node.pk}
        responses = comment_was_posted.send(sender=comment.__class__,
                                            comment=comment,
                                            request=self.request)

        self._assert_responses_true(responses)
        self.assertEqual(parent_node, comment.node.get_parent())
    def test_parent_childnode_wasadded(self):
        parent_comment = create_tcomment()
        parent_comment.save()
        parent_node = TCommentNode.add_root(comment=parent_comment)
        comment = create_tcomment()
        comment.save()
        self.request.POST = {'parent': parent_node.pk}
        responses = comment_was_posted.send(
            sender=comment.__class__,
            comment=comment,
            request=self.request)

        self._assert_responses_true(responses)
        self.assertEqual(parent_node, comment.node.get_parent())
Пример #6
0
 def test_clean_parent_valid_parent_success(self):
     another_site = Site.objects.create(domain='duckduckgo.com', name='duckduckgo')
     comment = TComment.objects.create(
         user_name='Bubbles',
         user_email='*****@*****.**',
         comment='Sugar and spice',
         content_type=ContentType.objects.get_for_model(Site),
         site=self.site,
         object_pk=another_site.pk
     )
     node = TCommentNode.add_root(comment=comment)
     data = self._get_test_comment_data()
     data.update(self.security_data)
     data.update({'parent': str(node.pk)})
     form = TCommentForm(another_site, data=data)
     self.assertTrue(form.is_valid(), msg='form.errors: %s' % form.errors.as_data())
 def test_clean_parent_valid_parent_success(self):
     another_site = Site.objects.create(domain='duckduckgo.com',
                                        name='duckduckgo')
     comment = TComment.objects.create(
         user_name='Bubbles',
         user_email='*****@*****.**',
         comment='Sugar and spice',
         content_type=ContentType.objects.get_for_model(Site),
         site=self.site,
         object_pk=another_site.pk)
     node = TCommentNode.add_root(comment=comment)
     data = self._get_test_comment_data()
     data.update(self.security_data)
     data.update({'parent': str(node.pk)})
     form = TCommentForm(another_site, data=data)
     self.assertTrue(form.is_valid(),
                     msg='form.errors: %s' % form.errors.as_data())
Пример #8
0
def create_tcomment_tree(target=None, 
                         max_depth=3, 
                         max_children=3, 
                         with_signal=False,
                         depth=1, 
                         parent=None):
    """
    Recursively populate the database with a random tree of depth max_depth.
    """
    if depth <= max_depth:
        children = random.randrange(1, max_children + 1)
        for _ in range(children):
            c = create_tcomment(target)
            c.save()
            if parent:
                node = parent.node.add_child(comment=c)
            else:
                node = TCommentNode.add_root(comment=c)
            c.node = node
            c.save()
            create_tcomment_tree(target, depth=depth+1, parent=c, with_signal=with_signal)
Пример #9
0
def create_tcomment_tree(target=None,
                         max_depth=3,
                         max_children=3,
                         with_signal=False,
                         depth=1,
                         parent=None):
    """
    Recursively populate the database with a random tree of depth max_depth.
    """
    if depth <= max_depth:
        children = random.randrange(1, max_children + 1)
        for _ in range(children):
            c = create_tcomment(target)
            c.save()
            if parent:
                node = parent.node.add_child(comment=c)
            else:
                node = TCommentNode.add_root(comment=c)
            c.node = node
            c.save()
            create_tcomment_tree(target,
                                 depth=depth + 1,
                                 parent=c,
                                 with_signal=with_signal)