def test_comment_form(): # must be bound to an object with pytest.raises(TypeError): CommentForm() with pytest.raises(AttributeError): CommentForm("some string") unit = Unit.objects.first() form = CommentForm(unit) secdata = form.generate_security_data() assert secdata["object_pk"] == str(unit.pk) assert secdata["content_type"] == str(unit._meta) assert "timestamp" in secdata assert "security_hash" in secdata
def test_comment_form_post(admin): unit = Unit.objects.first() form = CommentForm(unit) kwargs = dict( comment="Foo!", user=admin, timestamp=form.initial.get("timestamp"), security_hash=form.initial.get("security_hash")) post_form = CommentForm(unit, kwargs) if post_form.is_valid(): post_form.save() comment = Comment.objects.first() assert comment.comment == "Foo!" assert ".".join(comment.content_type.natural_key()) == str(unit._meta) assert comment.object_pk == str(unit.pk) assert comment.user == admin assert comment.name == admin.display_name assert comment.email == admin.email
def test_comment_form_post(admin): unit = Unit.objects.first() form = CommentForm(unit) kwargs = dict(comment="Foo!", user=admin, timestamp=form.initial.get("timestamp"), security_hash=form.initial.get("security_hash")) post_form = CommentForm(unit, kwargs) if post_form.is_valid(): post_form.save() comment = Comment.objects.first() assert comment.comment == "Foo!" assert ".".join(comment.content_type.natural_key()) == str(unit._meta) assert comment.object_pk == str(unit.pk) assert comment.user == admin assert comment.name == admin.display_name assert comment.email == admin.email