From 5ef51a5daa081a76ec5920739bb08692a432956c Mon Sep 17 00:00:00 2001 From: Geert Kapteijns <ghkapteijns@gmail.com> Date: Fri, 12 May 2017 15:26:08 +0200 Subject: [PATCH] Write view tests for RequestPublishedArticle. All OK. --- commentaries/factories.py | 1 + commentaries/forms.py | 9 --------- commentaries/test_views.py | 17 +++++++++++++++++ commentaries/views.py | 4 ---- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/commentaries/factories.py b/commentaries/factories.py index 60f1625f2..09d034275 100644 --- a/commentaries/factories.py +++ b/commentaries/factories.py @@ -24,6 +24,7 @@ class CommentaryFactory(factory.django.DjangoModelFactory): arxiv_identifier = factory.Sequence(lambda n: random_arxiv_identifier_with_version_number()) author_list = factory.Faker('name') pub_abstract = factory.Faker('text') + pub_date = factory.Faker('date') @factory.post_generation def create_urls(self, create, extracted, **kwargs): diff --git a/commentaries/forms.py b/commentaries/forms.py index 5fd67a38d..49c5e7bf7 100644 --- a/commentaries/forms.py +++ b/commentaries/forms.py @@ -76,9 +76,6 @@ class RequestPublishedArticleForm(forms.ModelForm): 'discipline', 'domain', 'subject_area', 'pub_title', 'author_list', 'journal', 'volume', 'pages', 'pub_date', 'pub_DOI', 'pub_abstract' ] - widgets = { - 'metadata': forms.HiddenInput(), - } placeholders = { 'pub_DOI': 'ex.: 10.21468/00.000.000000', 'pub_date': 'Format: YYYY-MM-DD', @@ -100,12 +97,6 @@ class RequestPublishedArticleForm(forms.ModelForm): return input_doi - def save(self, *args): - commentary = super().save(*args) - commentary.metadata = self.metadata - commentary.save() - return commentary - class RequestCommentaryForm(forms.ModelForm): """Create new valid Commetary by user request""" diff --git a/commentaries/test_views.py b/commentaries/test_views.py index 2077489c0..1d99bcc88 100644 --- a/commentaries/test_views.py +++ b/commentaries/test_views.py @@ -62,6 +62,23 @@ class PrefillUsingDOITest(TestCase): self.assertEqual(response.status_code, 200) +class RequestPublishedArticleTest(TestCase): + def setUp(self): + add_groups_and_permissions() + self.target = reverse('commentaries:request_published_article') + self.commentary_instance = UnvettedCommentaryFactory.build() + self.valid_form_data = model_form_data(self.commentary_instance, RequestPublishedArticleForm) + + def test_commentary_gets_created(self): + request = RequestFactory().post(self.target, self.valid_form_data) + request.user = UserFactory() + + self.assertEqual(Commentary.objects.count(), 0) + response = RequestPublishedArticle.as_view()(request) + self.assertEqual(Commentary.objects.count(), 1) + self.assertEqual(Commentary.objects.first().pub_DOI, self.valid_form_data['pub_DOI']) + + class VetCommentaryRequestsTest(TestCase): """Test cases for `vet_commentary_requests` view method""" diff --git a/commentaries/views.py b/commentaries/views.py index 63f9293af..f1ce56e66 100644 --- a/commentaries/views.py +++ b/commentaries/views.py @@ -80,10 +80,6 @@ class RequestPublishedArticle(CreateView): context['doi_query_form'] = DOIToQueryForm() return context - def form_valid(self, form): - form.type = "published" - return super(RequestPublishedArticle, self).form_valid(form) - @permission_required('scipost.can_request_commentary_pages', raise_exception=True) def prefill_using_DOI(request): -- GitLab