SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 1943c209 authored by Jorran de Wit's avatar Jorran de Wit
Browse files

Add tests to VetCommentary

Add tests to VetCommentary view, however
 the fixtures for groups remain empty (no permissions)
 causing problems with the ContributorFactory. Need some
 fix first, to have the groups work properly with the
 factories.
parent 121e082b
No related branches found
No related tags found
No related merge requests found
from django.test import TestCase from django.test import TestCase
from common.helpers import model_form_data
from scipost.factories import UserFactory from scipost.factories import UserFactory
from .models import Commentary
from .factories import VettedCommentaryFactory, UnVettedCommentaryFactory from .factories import VettedCommentaryFactory, UnVettedCommentaryFactory
from .forms import RequestCommentaryForm, VetCommentaryForm from .forms import RequestCommentaryForm, VetCommentaryForm
from common.helpers import model_form_data from .models import Commentary
class TestVetCommentaryForm(TestCase): class TestVetCommentaryForm(TestCase):
......
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.contrib.auth.models import Group
from django.test import TestCase from django.test import TestCase
from scipost.factories import ContributorFactory
from .factories import UnVettedCommentaryFactory
class RequestCommentaryTest(TestCase): class RequestCommentaryTest(TestCase):
"""Test cases for `request_commentary` view method""" """Test cases for `request_commentary` view method"""
...@@ -27,3 +32,45 @@ class RequestCommentaryTest(TestCase): ...@@ -27,3 +32,45 @@ class RequestCommentaryTest(TestCase):
self.client.login(username="Test", password="testpw") self.client.login(username="Test", password="testpw")
request = self.client.post(self.view_url) request = self.client.post(self.view_url)
self.assertEquals(request.status_code, 200) self.assertEquals(request.status_code, 200)
class VetCommentaryRequestsTest(TestCase):
"""Test cases for `vet_commentary_requests` view method"""
fixtures = ['groups', 'permissions']
def setUp(self):
self.view_url = reverse('commentaries:vet_commentary_requests')
self.login_url = reverse('scipost:login')
self.contributor = ContributorFactory()
def test_not_logged_in_user(self):
"""Test view permission is restricted to logged in users."""
response = self.client.get(self.view_url)
self.assertEquals(response.status_code, 403)
def test_get_valid_http_responses(self):
"""Test http response on GET requests"""
# Registered Contributor should get 200
self.client.login(username=self.contributor.user.username,
password=self.contributor.user.password)
# Wrong permissions group!
reponse = self.client.get(self.view_url)
self.assertEquals(reponse.status_code, 403)
# Right permissions group!
# self.client.logout()
group = Group.objects.get(name="Vetting Editors")
self.contributor.user.groups.add(group)
# Permission group is still empty!?!? These fixtures just don't seem to work properly.
# self.client.login(username=self.contributor.user.username,
# password=self.contributor.user.password)
reponse = self.client.get(self.view_url)
self.assertEquals(reponse.status_code, 200)
# def test_get_valid_unvetted_commentaries(self):
# """Test if valid commentaries are sent back to user."""
# self.client.login(username="Test", password="testpw")
# request = self.client.get(self.view_url)
# print(request)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment