From c3e8a2d52f95708b8fffc507567b6baa20474ece Mon Sep 17 00:00:00 2001 From: Jorran de Wit <jorrandewit@outlook.com> Date: Fri, 12 May 2017 22:37:03 +0200 Subject: [PATCH] Add tests covering prefiller+submit submission --- submissions/forms.py | 14 +++ .../templates/submissions/new_submission.html | 4 +- submissions/test_views.py | 93 ++++++++++++++++--- 3 files changed, 97 insertions(+), 14 deletions(-) diff --git a/submissions/forms.py b/submissions/forms.py index 73f7f6fe5..19cf53bb2 100644 --- a/submissions/forms.py +++ b/submissions/forms.py @@ -77,6 +77,20 @@ class SubmissionForm(forms.ModelForm): 'placeholder': 'Optional: names of referees whose reports should be treated with caution (+ short reason)', 'rows': 3}) + def update_submission_data(self): + """ + Some fields should not be accessible in the HTML form by the user and should be + inserted by for example an extra call to Arxiv into the Submission instance, right + *after* the form is submitted. + + Example fields: + - is_resubmission + - arxiv_link + - arxiv_identifier_w_vn_nr + - metadata (!) + """ + raise NotImplementedError + ###################### # Editorial workflow # diff --git a/submissions/templates/submissions/new_submission.html b/submissions/templates/submissions/new_submission.html index a9088e3a8..e0dbc27ad 100644 --- a/submissions/templates/submissions/new_submission.html +++ b/submissions/templates/submissions/new_submission.html @@ -54,7 +54,8 @@ $(document).ready(function(){ <div class="row mb-5"> <div class="col-12"> {% if perms.scipost.can_submit_manuscript %} - {% if form.arxiv_link.value %} + + {% if form.arxiv_link %} <form id="full_submission_form" action="{% url 'submissions:submit_manuscript' %}" method="post"> {% csrf_token %} {{form|bootstrap}} @@ -63,7 +64,6 @@ $(document).ready(function(){ </p> <input type="submit" class="btn btn-secondary"/> </form> - {% else %} {% endif %} {% else %} diff --git a/submissions/test_views.py b/submissions/test_views.py index 249c7a38d..4a5878434 100644 --- a/submissions/test_views.py +++ b/submissions/test_views.py @@ -1,3 +1,5 @@ +import json + from django.core.urlresolvers import reverse from django.test import TestCase from django.test import Client @@ -11,6 +13,39 @@ from .factories import EICassignedSubmissionFactory from .forms import SubmissionForm, SubmissionIdentifierForm from .models import Submission +# This is content of a real arxiv submission. As long as it isn't published it should +# be possible to run tests using this submission. +TEST_SUBMISSION = { + 'is_resubmission': False, + 'title': ('General solution of 2D and 3D superconducting quasiclassical' + ' systems:\n coalescing vortices and nanodisk geometries'), + 'author_list': 'Morten Amundsen, Jacob Linder', + 'arxiv_identifier_w_vn_nr': '1512.00030v1', + 'arxiv_identifier_wo_vn_nr': '1512.00030', + 'arxiv_vn_nr': 1, + 'arxiv_link': 'http://arxiv.org/abs/1512.00030v1', + 'abstract': ('In quasiclassical Keldysh theory, the Green function matrix $\\check{g}$' + ' is\nused to compute a variety of physical quantities in mesoscopic syst' + 'ems.\nHowever, solving the set of non-linear differential equations that' + ' provide\n$\\check{g}$ becomes a challenging task when going to higher s' + 'patial dimensions\nthan one. Such an extension is crucial in order to de' + 'scribe physical phenomena\nlike charge/spin Hall effects and topological' + ' excitations like vortices and\nskyrmions, none of which can be captured' + ' in one-dimensional models. We here\npresent a numerical finite element ' + 'method which solves the 2D and 3D\nquasiclassical Usadel equation, witho' + 'ut any linearisation, relevant for the\ndiffusive regime. We show the ap' + 'plication of this on two model systems with\nnon-trivial geometries: (i)' + ' a bottlenecked Josephson junction with external\nflux and (ii) a nanodi' + 'sk ferromagnet deposited on top of a superconductor. We\ndemonstrate tha' + 't it is possible to control externally not only the geometrical\narray i' + 'n which superconducting vortices arrange themselves, but also to cause\n' + 'coalescence and thus tune the number of vortices. The finite element met' + 'hod\npresented herein could pave the way for gaining insight in physical' + ' phenomena\nwhich so far have remained largely unexplored due to the com' + 'plexity of solving\nthe full quasiclassical equations in higher dimensio' + 'ns.') +} + class BaseContributorTestCase(TestCase): def setUp(self): @@ -34,7 +69,8 @@ class PrefillUsingIdentifierTest(BaseContributorTestCase): client = Client() response = client.get(self.url) self.assertEqual(response.status_code, 403) - response = client.post(self.url, {'identifier': '1512.00030v1'}) + response = client.post(self.url, + {'identifier': TEST_SUBMISSION['arxiv_identifier_w_vn_nr']}) self.assertEqual(response.status_code, 403) # Registered Contributor should get 200 @@ -43,12 +79,31 @@ class PrefillUsingIdentifierTest(BaseContributorTestCase): def test_retrieving_existing_arxiv_paper(self): '''Test view with a valid post request.''' - response = self.client.post(self.url, {'identifier': '1512.00030v1'}) + response = self.client.post(self.url, + {'identifier': + TEST_SUBMISSION['arxiv_identifier_w_vn_nr']}) self.assertEqual(response.status_code, 200) self.assertIsInstance(response.context['form'], SubmissionForm) self.assertIsInstance(response.context['identifierform'], SubmissionIdentifierForm) self.assertTrue(response.context['identifierform'].is_valid()) + # Explicitly compare fields instead of assertDictEqual as metadata field may be outdated + self.assertEqual(TEST_SUBMISSION['is_resubmission'], + response.context['form'].initial['is_resubmission']) + self.assertEqual(TEST_SUBMISSION['title'], response.context['form'].initial['title']) + self.assertEqual(TEST_SUBMISSION['author_list'], + response.context['form'].initial['author_list']) + self.assertEqual(TEST_SUBMISSION['arxiv_identifier_w_vn_nr'], + response.context['form'].initial['arxiv_identifier_w_vn_nr']) + self.assertEqual(TEST_SUBMISSION['arxiv_identifier_wo_vn_nr'], + response.context['form'].initial['arxiv_identifier_wo_vn_nr']) + self.assertEqual(TEST_SUBMISSION['arxiv_vn_nr'], + response.context['form'].initial['arxiv_vn_nr']) + self.assertEqual(TEST_SUBMISSION['arxiv_link'], + response.context['form'].initial['arxiv_link']) + self.assertEqual(TEST_SUBMISSION['abstract'], + response.context['form'].initial['abstract']) + def test_still_200_ok_if_identifier_is_wrong(self): response = self.client.post(self.url, {'identifier': '1512.00030'}) self.assertEqual(response.status_code, 200) @@ -60,29 +115,43 @@ class SubmitManuscriptTest(BaseContributorTestCase): # Unauthorized request shouldn't be possible response = client.post(reverse('submissions:prefill_using_identifier'), - {'identifier': '1512.00030v1'}) + {'identifier': TEST_SUBMISSION['arxiv_identifier_w_vn_nr']}) self.assertEquals(response.status_code, 403) - # Registered Contributor should get 200 + # Registered Contributor should get 200; assuming prefiller is working properly self.assertTrue(client.login(username="Test", password="testpw")) response = client.post(reverse('submissions:prefill_using_identifier'), - {'identifier': '1512.00030v1'}) + {'identifier': TEST_SUBMISSION['arxiv_identifier_w_vn_nr']}) self.assertEqual(response.status_code, 200) # Fill form parameters params = response.context['form'].initial params.update({ 'discipline': 'physics', - 'submitted_to_journal': 'SciPost Physics', + 'subject_area': 'Phys:MP', + 'submitted_to_journal': 'SciPostPhys', 'submission_type': 'Article', 'domain': 'T' }) - response = client.post(reverse('submissions:submit_manuscript'), **params) - - self.assertEqual(response.status_code, 200) - # submission = Submission.objects.filter(status=STATUS_UNASSIGNED).last() - # raise Exception(response.content) - # self.assertIn(submission, response.context) + params['metadata'] = json.dumps(params['metadata'], separators=(',', ':')) + + # Submit new Submission form + response = client.post(reverse('submissions:submit_manuscript'), params) + self.assertEqual(response.status_code, 302) + + # Do a quick check on the Submission submitted. + submission = Submission.objects.filter(status=STATUS_UNASSIGNED).last() + self.assertIsNotNone(submission) + self.assertEqual(TEST_SUBMISSION['is_resubmission'], submission.is_resubmission) + self.assertEqual(TEST_SUBMISSION['title'], submission.title) + self.assertEqual(TEST_SUBMISSION['author_list'], submission.author_list) + self.assertEqual(TEST_SUBMISSION['arxiv_identifier_w_vn_nr'], + submission.arxiv_identifier_w_vn_nr) + self.assertEqual(TEST_SUBMISSION['arxiv_identifier_wo_vn_nr'], + submission.arxiv_identifier_wo_vn_nr) + self.assertEqual(TEST_SUBMISSION['arxiv_vn_nr'], submission.arxiv_vn_nr) + self.assertEqual(TEST_SUBMISSION['arxiv_link'], submission.arxiv_link) + self.assertEqual(TEST_SUBMISSION['abstract'], submission.abstract) class SubmissionDetailTest(BaseContributorTestCase): -- GitLab