test_votes_views.py 1.74 KB
Newer Older
luxcem's avatar
luxcem committed
1 2 3 4 5 6 7 8 9 10 11
from django.urls import reverse
from django.test import TestCase

from userprofile.factories import ProfileFactory
from rp.factories import ArticleFactory
from rp.models import Article


class VoteViewTestCase(TestCase):
    def setUp(self):
        self.article = ArticleFactory()
12 13
        self.article_draft = ArticleFactory(status="DRAFT")

luxcem's avatar
luxcem committed
14 15 16 17 18
        self.profile = ProfileFactory()
        self.user = self.profile.user
        self.client.force_login(self.user)

    def test_votes(self):
luxcem's avatar
luxcem committed
19 20
        url_upvote = reverse("api:article-upvote", kwargs={
            "pk": self.article.id
luxcem's avatar
luxcem committed
21 22
        })

luxcem's avatar
luxcem committed
23 24
        url_downvote = reverse("api:article-downvote", kwargs={
            "pk": self.article.id
luxcem's avatar
luxcem committed
25 26
        })

luxcem's avatar
luxcem committed
27
        response = self.client.post(url_upvote)
luxcem's avatar
luxcem committed
28 29 30 31
        assert response.status_code == 200
        article_db = Article.objects.get(id=self.article.id)
        assert article_db.und_score == 1

luxcem's avatar
luxcem committed
32
        response = self.client.post(url_downvote)
luxcem's avatar
luxcem committed
33 34 35
        assert response.status_code == 200
        article_db = Article.objects.get(id=self.article.id)
        assert article_db.und_score == -1
luxcem's avatar
luxcem committed
36 37 38

    def test_publish(self):
        url_publish = reverse("api:article-publish", kwargs={
39
            "pk": self.article_draft.id
luxcem's avatar
luxcem committed
40 41 42 43
        })

        response = self.client.post(url_publish)
        assert response.status_code == 200
44
        article_db = Article.objects.get(id=self.article_draft.id)
luxcem's avatar
luxcem committed
45 46
        assert article_db.status == "PUBLISHED"

47 48 49 50 51 52

    def test_reject(self):
        url_reject = reverse("api:article-reject", kwargs={
            "pk": self.article.id
        })

luxcem's avatar
luxcem committed
53 54 55 56
        response = self.client.post(url_reject)
        assert response.status_code == 200
        article_db = Article.objects.get(id=self.article.id)
        assert article_db.status == "REJECTED"