From 74b6ac959b826a68d8c57c2df70810e8a8db813d Mon Sep 17 00:00:00 2001 From: Geert Kapteijns <ghkapteijns@gmail.com> Date: Sun, 15 Jan 2017 14:52:33 +0100 Subject: [PATCH] Three failing tests regarding thesis link vetting; not doing anything about it right now --- strings/__init__.py | 6 ++++- theses/forms.py | 12 +++++++--- .../theses/vet_thesislink_requests.html | 2 +- theses/test_models.py | 2 ++ theses/test_views.py | 17 +++++++++----- theses/urls.py | 2 ++ theses/views.py | 22 +++++-------------- 7 files changed, 36 insertions(+), 27 deletions(-) diff --git a/strings/__init__.py b/strings/__init__.py index 82d957c9d..4aa362a9c 100644 --- a/strings/__init__.py +++ b/strings/__init__.py @@ -1 +1,5 @@ -acknowledge_request_thesis_link = "Thank you for your request for a Thesis Link. Your request will soon be handled by an editor" +acknowledge_request_thesis_link = ( + "Thank you for your request for a Thesis Link. Your request" + " will soon be handled by an editor." +) +acknowledge_vet_thesis_link = "Thesis Link request vetted." diff --git a/theses/forms.py b/theses/forms.py index 05963cb32..b448c5a80 100644 --- a/theses/forms.py +++ b/theses/forms.py @@ -41,10 +41,16 @@ class VetThesisLinkForm(forms.Form): justification = forms.CharField(widget=forms.Textarea( attrs={'rows': 5, 'cols': 40}), label='Justification (optional)', required=False) - def vet_request(self, thesis_link): - print(self.cleaned_data) + def vet_request(self, thesis_link_id): if self.cleaned_data['action_option'] == VetThesisLinkForm.ACCEPT: - print('hoi') + + thesislink.vetted = True + thesislink.vetted_by = Contributor.objects.get(user=request.user) + thesislink.save() + elif self.cleaned_data['action_option'] == VetThesisLinkForm.MODIFY: + print('hai') + elif self.cleaned_data['action_option'] == VetThesisLinkForm.REFUSE: + print('bla') class ThesisLinkSearchForm(forms.Form): diff --git a/theses/templates/theses/vet_thesislink_requests.html b/theses/templates/theses/vet_thesislink_requests.html index c49008776..2a74df850 100644 --- a/theses/templates/theses/vet_thesislink_requests.html +++ b/theses/templates/theses/vet_thesislink_requests.html @@ -22,7 +22,7 @@ <p>{{ thesislink_to_vet.abstract }}</p> </div> <div class="col-4"> - <form method="post"> + <form action= {% url 'theses:vet_thesislink_request' thesislink_to_vet.id %} method="post"> {% csrf_token %} {{ form.as_ul }} <input type="submit" value="Submit" /> diff --git a/theses/test_models.py b/theses/test_models.py index 4308ab25f..9cda61729 100644 --- a/theses/test_models.py +++ b/theses/test_models.py @@ -8,6 +8,8 @@ from .factories import ThesisLinkFactory class ThesisLinkTestCase(TestCase): + fixtures = ['permissions', 'groups'] + def test_domain_cannot_be_blank(self): thesis_link = ThesisLinkFactory() thesis_link.domain = "" diff --git a/theses/test_views.py b/theses/test_views.py index faa7f14d5..f87971e80 100644 --- a/theses/test_views.py +++ b/theses/test_views.py @@ -4,7 +4,8 @@ from django.core.exceptions import PermissionDenied from django.test import TestCase, RequestFactory from django.test.client import Client from django.contrib.auth.models import Group -from django.urls import reverse +from django.urls import reverse, reverse_lazy +from django.contrib.messages.storage.fallback import FallbackStorage from .views import RequestThesisLink, VetThesisLinkRequests from scipost.factories import UserFactory, ContributorFactory @@ -77,14 +78,20 @@ class TestVetThesisLinkRequests(TestCase): self.assertEqual(response.status_code, 200) def test_thesislink_is_vetted_by_correct_contributor(self): - # TODO: how to make sure we are vetting the right thesis link? + thesis_link = ThesisLinkFactory() contributor = ContributorFactory() contributor.user.groups.add(Group.objects.get(name="Vetting Editors")) post_data = VetThesisLinkFormFactory().data + target = reverse('theses:vet_thesislink_request', kwargs={'thesislink_id': thesis_link.id}) - request = RequestFactory().post(self.target, post_data) + request = RequestFactory().post(target, post_data) request.user = contributor.user - response = VetThesisLinkRequests.as_view()(request) + # I don't know what the following three lines do, but they help make a RequestFactory + # work with the messages middleware + setattr(request, 'session', 'session') + messages = FallbackStorage(request) + setattr(request, '_messages', messages) - self.assertTrue(False) + response = VetThesisLinkRequests.as_view()(request, thesislink_id=thesis_link.id) + self.assertEqual(thesis_link.vetted_by, contributor) diff --git a/theses/urls.py b/theses/urls.py index 3d3c530e4..9789d311e 100644 --- a/theses/urls.py +++ b/theses/urls.py @@ -11,6 +11,8 @@ urlpatterns = [ url(r'^request_thesislink$', views.RequestThesisLink.as_view(), name='request_thesislink'), url(r'^vet_thesislink_requests$', views.VetThesisLinkRequests.as_view(), name='vet_thesislink_requests'), + url(r'^vet_thesislink_request/(?P<thesislink_id>[0-9]+)/$', + views.VetThesisLinkRequests.as_view(), name='vet_thesislink_request'), url(r'^vet_thesislink_request_ack/(?P<thesislink_id>[0-9]+)$', views.vet_thesislink_request_ack, name='vet_thesislink_request_ack'), ] diff --git a/theses/views.py b/theses/views.py index 0dd1a2b6e..80ecb6952 100644 --- a/theses/views.py +++ b/theses/views.py @@ -20,7 +20,7 @@ from .forms import * from comments.models import Comment from comments.forms import CommentForm from scipost.forms import TITLE_CHOICES, AuthenticationForm - +import strings title_dict = dict(TITLE_CHOICES) # Convert titles for use in emails @@ -47,32 +47,20 @@ class RequestThesisLink(CreateView): class VetThesisLinkRequests(FormView): form_class = VetThesisLinkForm template_name = 'theses/vet_thesislink_requests.html' - # TODO: not right yet success_url = reverse_lazy('theses:vet_thesislink_requests') def get_context_data(self, **kwargs): context = super(VetThesisLinkRequests, self).get_context_data(**kwargs) - context['thesislink_to_vet'] = self.thesislink_to_vet() + context['thesislink_to_vet'] = ThesisLink.objects.filter(vetted=False).first() return context - def thesislink_to_vet(self): - return ThesisLink.objects.filter(vetted=False).first() - def form_valid(self, form): - form.vet_request(self.thesislink_to_vet()) + form.vet_request(self.kwargs['thesislink_id']) + messages.add_message(self.request, messages.SUCCESS, + strings.acknowledge_vet_thesis_link) return super(VetThesisLinkRequests, self).form_valid(form) -# @permission_required('scipost.can_vet_thesislink_requests', raise_exception=True) -# def vet_thesislink_requests(request): -# contributor = Contributor.objects.get(user=request.user) -# thesislink_to_vet = ThesisLink.objects.filter( -# vetted=False).first() # only handle one at a time -# form = VetThesisLinkForm() -# context = {'contributor': contributor, 'thesislink_to_vet': thesislink_to_vet, 'form': form} -# return render(request, 'theses/vet_thesislink_requests.html', context) - - @permission_required('scipost.can_vet_thesislink_requests', raise_exception=True) def vet_thesislink_request_ack(request, thesislink_id): if request.method == 'POST': -- GitLab