コード例 #1
0
def test_question_can_be_posted(user):
    question = Post(id=1,
                    post_type_id=Post.QUESTION,
                    description="Test Question",
                    posted_by=user)
    question.save()
    post = Post.objects.get(pk=1)
    assert question.description == post.description
コード例 #2
0
def test_question_can_not_have_parent_id(user):
    with pytest.raises(Exception) as e:
        question = Post(id=1,
                        post_type_id=Post.QUESTION,
                        posted_by=user,
                        parent_id=1)
        question.save()
    assert 'Question should have null parent id' in str(e.value)
コード例 #3
0
def test_downvotes_can_not_be_negative(user):
    with pytest.raises(Exception) as e:
        question = Post(id=1,
                        post_type_id=Post.QUESTION,
                        description="Test Question",
                        down_votes=-1,
                        posted_by=user)
        question.save()
    assert 'Invalid udown_votes, Downvote should be a non-negative integer' in str(
        e.value)
コード例 #4
0
def test_comment_can_be_posted_to_question(user):
    question = Post(id=1,
                    post_type_id=Post.QUESTION,
                    description="Test Question",
                    posted_by=user)
    comment = Post(id=2,
                   post_type_id=Post.COMMENT,
                   description="Test Comment",
                   parent_id=1,
                   posted_by=user)
    comment.save()
    post = Post.objects.get(pk=2)
    assert comment.description == post.description
コード例 #5
0
def test_answer_can_be_posted_to_question(user):
    question = Post(id=1,
                    post_type_id=Post.QUESTION,
                    description="Test Question",
                    posted_by=user)
    answer = Post(id=2,
                  post_type_id=Post.ANSWER,
                  description="Test Answer",
                  parent_id=1,
                  posted_by=user)
    answer.save()
    post = Post.objects.get(pk=2)
    assert answer.description == post.description
コード例 #6
0
ファイル: actions.py プロジェクト: riteshm93/Learning
def new_post(request, post_type_id, post_id=None):
    if request.method == 'POST':
        form = PostForm(request.POST)
        if form.is_valid():
            post = Post()
            post.post_type_id = post_type_id
            post.description = request.POST['description']
            if post_type_id != Post.QUESTION:
                post.parent_id = post_id
            post.posted_by = request.user
            post.save()
            return HttpResponseRedirect(get_redirect_url(post))
        else:
            return HttpResponse("Invalid Input.")
コード例 #7
0
def test_answer_can_not_be_posted_to_answer(user):
    with pytest.raises(Exception) as e:
        question = Post(id=1,
                        post_type_id=Post.QUESTION,
                        description="Test Question",
                        posted_by=user)
        valid_answer = Post(id=2,
                            post_type_id=Post.ANSWER,
                            description="Test Valid Answer",
                            parent_id=1,
                            posted_by=user)
        invalid_answer = Post(id=3,
                              post_type_id=Post.ANSWER,
                              description="Test Invalid Answer",
                              parent_id=2,
                              posted_by=user)
        invalid_answer.save()
    assert 'Invalid parrent id' in str(e.value)
コード例 #8
0
def test_comments_can_not_be_posted_to_comments(user):
    with pytest.raises(Exception) as e:
        question = Post(id=1,
                        post_type_id=Post.QUESTION,
                        description="Test Question",
                        posted_by=user)
        answer = Post(id=2,
                      post_type_id=Post.ANSWER,
                      description="Test Answer",
                      parent_id=1,
                      posted_by=user)
        valid_comment = Post(id=3,
                             post_type_id=Post.COMMENT,
                             description="Test Valid Comment",
                             parent_id=2,
                             posted_by=user)
        invalid_comment = Post(id=4,
                               post_type_id=Post.COMMENT,
                               description="Test Invalid Comment",
                               parent_id=3,
                               posted_by=user)
        invalid_comment.save()
    assert 'Invalid parrent id' in str(e.value)
コード例 #9
0
def test_get_root_parent_id_for_answer_comment():
    question = Post(id=1, post_type_id=Post.QUESTION)
    answer = Post(id=2, post_type_id=Post.ANSWER, parent=question)
    comment = Post(id=3, post_type_id=Post.COMMENT, parent=answer)
    assert 1 == comment.get_root_parent_id()
コード例 #10
0
def test_get_root_parent_id_for_question_comment():
    question = Post(id=1, post_type_id=Post.QUESTION)
    comment = Post(id=2, post_type_id=Post.COMMENT, parent=question)
    assert 1 == comment.get_root_parent_id()
コード例 #11
0
def test_get_root_parent_id_for_answer():
    question = Post(id=1, post_type_id=Post.QUESTION)
    answer = Post(id=2, post_type_id=Post.ANSWER, parent=question)
    assert 1 == answer.get_root_parent_id()
コード例 #12
0
def test_get_root_parent_id_for_question():
    question = Post(id=1, post_type_id=Post.QUESTION)
    assert 1 == question.get_root_parent_id()
コード例 #13
0
def test_comment_must_have_parent_id(user):
    with pytest.raises(Exception) as e:
        comment = Post(id=1, post_type_id=Post.COMMENT, posted_by=user)
        comment.save()
    assert 'Parent id cant be null for answers and comments' in str(e.value)
コード例 #14
0
def test_answer_must_have_parent_id(user):
    with pytest.raises(Exception) as e:
        answer = Post(id=1, post_type_id=Post.ANSWER, posted_by=user)
        answer.save()
    assert 'Parent id cant be null for answers and comments' in str(e.value)
コード例 #15
0
def post(request):
    user = User(id=1, username='******')
    post = Post(post_type_id=Post.QUESTION, posted_by=user)
    post.save()
    return post