dimanche 29 septembre 2019

Django Converting to CBV + tests

I'm trying to test my app. I went over the documentation, and managed to make the test for my URL's and all views but one.

I'm having trouble converting it to a class view and I'm not really sure what kind of tests should I do here ?

Anyone mind helping me out ?

here is the view that I'm trying to convert and test :

def add_comment_to_article(request, pk):
    article = get_object_or_404(Article, pk=pk)
    if request.method == "POST":
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.post = article
            comment.save()
            return HttpResponseRedirect(reverse('news:article', kwargs={"article_id": article.pk}))
    else:
        form = CommentForm()
    return render(request, 'news/add_comment_to_article.html', {'form': form})


The view is in charge of adding a comment to my Article post. Thank you !!

Aucun commentaire:

Enregistrer un commentaire