Ejemplo n.º 1
0
 def test_valid_form(self, db):
     form = ConversationForm({
         'title': 'conversation-slug',
         'tags': 'tag',
         'text': 'description',
         'comments_count': 0,
     })
     assert form.is_valid()
Ejemplo n.º 2
0
 def test_empty_form(self):
     form = ConversationForm({})
     assert not form.is_valid()
     assert form.errors == {
         'tags': ['This field is required.'],
         'title': ['This field is required.'],
         'text': ['This field is required.'],
         'comments_count': ['This field is required.'],
     }
Ejemplo n.º 3
0
 def test_valid_conversation_form(self, db):
     form = ConversationForm({
         "title": "conversation-slug",
         "tags": "tag",
         "text": "description",
         "comments_count": 1,
         "comment-1": "comment",
     })
     assert form.is_valid()
Ejemplo n.º 4
0
    def test_edit_conversation_form(self, db, conversation):
        conversation.tags.add('oldtag')
        form = ConversationForm(
            data={
                'title': 'tiaatle',
                'tags': 'newtag',
                'text': 'description',
                'comments_count': 0,
            },
            instance=conversation,
        )

        assert form.is_valid()
        form.save()
        conversation.refresh_from_db()
        assert str(conversation.tags.first()) == 'newtag'
        assert conversation.tags.count() == 1
Ejemplo n.º 5
0
 def test_conversation_form_save_without_author(self, db):
     title = 'conversation-slug1'
     form = ConversationForm({
         'title': title,
         'tags': 'tag',
         'text': 'description',
         'comments_count': 1,
         'comment-1': 'comment',
     })
     form_is_valid = form.is_valid()
     assert form_is_valid
     with pytest.raises(IntegrityError):
         with transaction.atomic():
             form.save_all(
                 author=None,
                 is_promoted=True,
             )
Ejemplo n.º 6
0
    def test_conversation_form_save(self, db, user):
        form = ConversationForm({
            "title": "conversation",
            "tags": "tag",
            "text": "description",
            "comments_count": 1,
            "comment-1": "comment",
        })
        assert form.is_valid()
        with transaction.atomic():
            conversation = form.save_comments(author=user, is_promoted=True)

        assert conversation
        assert conversation.author == user
        assert conversation.title == "conversation"
        assert conversation.tags.first().name == "tag"
        assert conversation.comments.first().content == "comment"
        assert conversation.comments.first().status == Comment.STATUS.approved
Ejemplo n.º 7
0
 def test_conversation_form_save(self, db, user):
     title = 'conversation-slug1'
     form = ConversationForm({
         'title': title,
         'tags': 'tag',
         'text': 'description',
         'comments_count': 0,
     })
     form_is_valid = form.is_valid()
     assert form_is_valid
     with transaction.atomic():
         conversation = form.save_all(
             author=user,
             is_promoted=True,
         )
     assert conversation
     assert conversation.author == user
     assert conversation.title == title
     assert conversation.tags.first().name == 'tag'
Ejemplo n.º 8
0
 def test_conversation_form_save_with_board(self, db, user):
     title = 'conversation-slug1'
     form = ConversationForm({
         'title': title,
         'tags': 'tag',
         'text': 'description',
         'comments_count': 1,
     })
     board = Board.objects.create(owner=user, title='Title')
     form_is_valid = form.is_valid()
     assert form_is_valid
     with transaction.atomic():
         conversation = form.save_all(
             author=user,
             board=board,
         )
     assert conversation
     assert conversation.author == user
     assert conversation.title == title
     assert conversation.tags.first().name == 'tag'
     assert board.conversations.get(title=title) == conversation
Ejemplo n.º 9
0
 def test_conversation_form_save_with_comment(self, db, user):
     title = 'conversation-slug1'
     form = ConversationForm({
         'title': title,
         'tags': 'tag',
         'text': 'description',
         'comments_count': 1,
         'comment-1': 'comment',
     })
     form_is_valid = form.is_valid()
     assert form_is_valid
     with transaction.atomic():
         conversation = form.save_all(
             author=user,
             is_promoted=True,
         )
     assert conversation
     assert conversation.author == user
     assert conversation.title == title
     assert conversation.tags.first().name == 'tag'
     assert conversation.comments.first().content == 'comment'
     assert Comment.STATUS.approved == conversation.comments.first().status