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() self.article_draft = ArticleFactory(status="DRAFT") self.profile = ProfileFactory() self.user = self.profile.user self.client.force_login(self.user) def test_votes(self): url_upvote = reverse("api:article-upvote", kwargs={ "pk": self.article.id }) url_downvote = reverse("api:article-downvote", kwargs={ "pk": self.article.id }) response = self.client.post(url_upvote) assert response.status_code == 200 article_db = Article.objects.get(id=self.article.id) assert article_db.und_score == 1 response = self.client.post(url_downvote) assert response.status_code == 200 article_db = Article.objects.get(id=self.article.id) assert article_db.und_score == -1 def test_publish(self): url_publish = reverse("api:article-publish", kwargs={ "pk": self.article_draft.id }) response = self.client.post(url_publish) assert response.status_code == 200 article_db = Article.objects.get(id=self.article_draft.id) assert article_db.status == "PUBLISHED" def test_reject(self): url_reject = reverse("api:article-reject", kwargs={ "pk": self.article.id }) 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"