diff --git a/theses/test_views.py b/theses/test_views.py index e1c9c7982e1cd36b83d213a82f3794ec860a05f5..0c733924704e0f5861958e8f8c6c8e307d5ec442 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)