From dfbe1feca375599c78ec17a6106ddd8d9831ecc2 Mon Sep 17 00:00:00 2001 From: Geert Kapteijns <ghkapteijns@gmail.com> Date: Thu, 15 Dec 2016 23:07:59 +0100 Subject: [PATCH] Use reverse instead of hardcoding urls in theses/test_views.py --- theses/test_views.py | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/theses/test_views.py b/theses/test_views.py index e1c9c7982..0c7339247 100644 --- a/theses/test_views.py +++ b/theses/test_views.py @@ -1,10 +1,36 @@ -from django.test import TestCase +from django.test import TestCase, RequestFactory from django.test.client import Client +from django.contrib.auth.models import AnonymousUser +from django.urls import reverse + +from .views import request_thesislink, RequestThesisLink +from scipost.factories import UserFactory +from .factories import ThesisLinkFactory +from .models import ThesisLink class TestThesisDetail(TestCase): + fixtures = ['groups', 'permissions'] + + def test_visits_valid_thesis_detail(self): + thesis_link = ThesisLinkFactory() + client = Client() + target = reverse('theses:thesis', kwargs={'thesislink_id': thesis_link.id}) + response = client.post(target) + self.assertEqual(response.status_code, 200) - def test_acknowledges_after_submitting_comment(self): + +class TestRequestThesisLink(TestCase): + fixtures = ['groups', 'permissions'] + + def test_response_when_not_logged_in(self): + '''A visitor that is not logged in cannot view this page.''' client = Client() - response = client.post('/theses/1') - self.assertEqual(response.get('location'), 'bladiebla') + response = client.get('/theses/request_thesislink') + self.assertEqual(response.status_code, 403) + + def test_response_when_logged_in(self): + request = RequestFactory().get('/theses/request_thesislink') + request.user = UserFactory() + response = request_thesislink(request) + self.assertEqual(response.status_code, 200) -- GitLab