Example #1
0
    def testProfanities(self):
        """Test COMMENTS_ALLOW_PROFANITIES and PROFANITIES_LIST settings"""
        a = Article.objects.get(pk=1)
        d = self.getValidData(a)

        # Try with COMMENTS_ALLOW_PROFANITIES off
        with self.settings(COMMENTS_ALLOW_PROFANITIES=False):
            f = CommentForm(a, data=dict(d, comment="What a rooster!"))
            self.assertFalse(f.is_valid())

        # Now with COMMENTS_ALLOW_PROFANITIES on
        with self.settings(COMMENTS_ALLOW_PROFANITIES=True):
            f = CommentForm(a, data=dict(d, comment="What a rooster!"))
            self.assertTrue(f.is_valid())
 def tamperWithForm(self, **kwargs):
     a = Article.objects.get(pk=1)
     d = self.getValidData(a)
     d.update(kwargs)
     f = CommentForm(Article.objects.get(pk=1), data=d)
     self.assertFalse(f.is_valid())
     return f
 def tamperWithForm(self, **kwargs):
     a = Article.objects.get(pk=1)
     d = self.getValidData(a)
     d.update(kwargs)
     f = CommentForm(Article.objects.get(pk=1), data=d)
     self.assertFalse(f.is_valid())
     return f
Example #4
0
def post_comment(request):
    if request.method == 'POST':
        prod_id = request.POST['object_pk']
        prod = Product.objects.get(pk=prod_id)
        form = CommentForm(target_object=prod, data=request.POST)
        if form.is_valid():
            form.save()
            return redirect('store_home')
    else:
        form = CommentForm()
    return render(request, "register.html", {'form': form})
Example #5
0
def ajax_comment_post(request):
    print request.POST
    try:
        form = CommentForm(request.POST)
    except Exception as e:
        print e
    print "HERE"
    if form.is_valid():
        form.save()
        return HttpResponse("IT WORKED!")
    return HttpResponse("FAIL!")
Example #6
0
def post_comment(request):
    if request.method == 'POST':
        prod_id = request.POST['object_pk']
        prod = Product.objects.get(pk=prod_id)
        form = CommentForm(target_object=prod, data=request.POST)
        if form.is_valid():
            form.save()
            return redirect('store_home')
    else:
        form = CommentForm() 
    return render(request, "register.html", {'form': form})
    def testProfanities(self):
        """Test COMMENTS_ALLOW_PROFANITIES and PROFANITIES_LIST settings"""
        a = Article.objects.get(pk=1)
        d = self.getValidData(a)

        # Save settings in case other tests need 'em
        saved = settings.PROFANITIES_LIST, settings.COMMENTS_ALLOW_PROFANITIES

        # Don't wanna swear in the unit tests if we don't have to...
        settings.PROFANITIES_LIST = ["rooster"]

        # Try with COMMENTS_ALLOW_PROFANITIES off
        settings.COMMENTS_ALLOW_PROFANITIES = False
        f = CommentForm(a, data=dict(d, comment="What a rooster!"))
        self.assertFalse(f.is_valid())

        # Now with COMMENTS_ALLOW_PROFANITIES on
        settings.COMMENTS_ALLOW_PROFANITIES = True
        f = CommentForm(a, data=dict(d, comment="What a rooster!"))
        self.assertTrue(f.is_valid())

        # Restore settings
        settings.PROFANITIES_LIST, settings.COMMENTS_ALLOW_PROFANITIES = saved
    def testProfanities(self):
        """Test COMMENTS_ALLOW_PROFANITIES and PROFANITIES_LIST settings"""
        a = Article.objects.get(pk=1)
        d = self.getValidData(a)

        # Save settings in case other tests need 'em
        saved = settings.PROFANITIES_LIST, settings.COMMENTS_ALLOW_PROFANITIES

        # Don't wanna swear in the unit tests if we don't have to...
        settings.PROFANITIES_LIST = ["rooster"]

        # Try with COMMENTS_ALLOW_PROFANITIES off
        settings.COMMENTS_ALLOW_PROFANITIES = False
        f = CommentForm(a, data=dict(d, comment="What a rooster!"))
        self.assertFalse(f.is_valid())

        # Now with COMMENTS_ALLOW_PROFANITIES on
        settings.COMMENTS_ALLOW_PROFANITIES = True
        f = CommentForm(a, data=dict(d, comment="What a rooster!"))
        self.assertTrue(f.is_valid())

        # Restore settings
        settings.PROFANITIES_LIST, settings.COMMENTS_ALLOW_PROFANITIES = saved
    def testDjango12Hash(self):
        # Ensure we can use the hashes generated by Django 1.2
        a = Article.objects.get(pk=1)
        d = self.getValidData(a)

        content_type = d['content_type']
        object_pk = d['object_pk']
        timestamp = d['timestamp']

        # The Django 1.2 method hard-coded here:
        info = (content_type, object_pk, timestamp, settings.SECRET_KEY)
        security_hash = sha_constructor("".join(info)).hexdigest()

        d['security_hash'] = security_hash
        f = CommentForm(a, data=d)
        self.assertTrue(f.is_valid(), f.errors)
    def testDjango12Hash(self):
        # Ensure we can use the hashes generated by Django 1.2
        a = Article.objects.get(pk=1)
        d = self.getValidData(a)

        content_type = d['content_type']
        object_pk = d['object_pk']
        timestamp = d['timestamp']

        # The Django 1.2 method hard-coded here:
        info = (content_type, object_pk, timestamp, settings.SECRET_KEY)
        security_hash = sha_constructor("".join(info)).hexdigest()

        d['security_hash'] = security_hash
        f = CommentForm(a, data=d)
        self.assertTrue(f.is_valid(), f.errors)
 def testValidPost(self):
     a = Article.objects.get(pk=1)
     f = CommentForm(a, data=self.getValidData(a))
     self.assertTrue(f.is_valid(), f.errors)
     return f
 def testValidPost(self):
     a = Article.objects.get(pk=1)
     f = CommentForm(a, data=self.getValidData(a))
     self.assertTrue(f.is_valid(), f.errors)
     return f