def test_clean_parent_invalid_parent_fail(self):
     data = self._get_test_comment_data()
     data.update(self.security_data)
     data.update({'parent': '2'})
     form = TCommentForm(self.site, data=data)
     self.assertFalse(form.is_valid(),
                      msg='form.errors: %s' % form.errors.as_data())
def create_tcomment(target=None, **kwargs):
    """
    Factory for creating TComment instances.
    :param target: Target model of the comment. Defaults to the current Site.
    :return: A new TComment instance.
    """
    site = Site.objects.get_current()
    target_ = target if target else site
    # content_type, object_pk, timestamp, security_hash
    security_data = TCommentForm(target_).generate_security_data()
    # Base django_comments data
    data = {
        'content_type': ContentType.objects.get_for_model(target_),
        'object_pk': security_data['object_pk'],
        'user_name': random_string(),
        'user_email': random_email(),
        'user_url': random_url(),
        'comment': random_string(25),
        'submit_date': timezone.now(),
        'site_id': site.pk,
        'is_public': True,
        'is_removed': False
    }
    # Extended TComment data
    data.update({'title': random_string()})
    # Caller override auto-generated fields
    data.update(kwargs)
    return TComment(**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())
 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_invalid_parent_fail(self):
     data = self._get_test_comment_data()
     data.update(self.security_data)
     data.update({'parent': '2'})
     form = TCommentForm(self.site, data=data)
     self.assertFalse(form.is_valid(), msg='form.errors: %s' % form.errors.as_data())
 def test_clean_noparent_success(self):
     data = self._get_test_comment_data()
     data.update(self.security_data)
     form = TCommentForm(self.site, data=data)
     self.assertTrue(form.is_valid(), msg='form.errors: %s' % form.errors.as_data())
 def setUp(self):
     # Establish mock target for the comments
     self.site = Site.objects.get_current()
     # Create a mock content_type, object_pk, timestamp, security_hash
     self.security_data = TCommentForm(self.site).generate_security_data()
 def test_clean_noparent_success(self):
     data = self._get_test_comment_data()
     data.update(self.security_data)
     form = TCommentForm(self.site, data=data)
     self.assertTrue(form.is_valid(),
                     msg='form.errors: %s' % form.errors.as_data())