diff --git a/commentaries/factories.py b/commentaries/factories.py index cd364cc9b827f28f0b0297858e98143e10556987..a3cd0186ab5dbd17c8cb5fc398ff2b6c4ace98db 100644 --- a/commentaries/factories.py +++ b/commentaries/factories.py @@ -20,7 +20,7 @@ class BaseCommentaryFactory(factory.django.DjangoModelFactory): requested_by = factory.SubFactory('scipost.factories.ContributorFactory') vetted = True - vetted_by = factory.Iterator(Contributor.objects.all()) + vetted_by = factory.SubFactory('scipost.factories.ContributorFactory') type = factory.Iterator(COMMENTARY_TYPES, getter=lambda c: c[0]) discipline = factory.Iterator(SCIPOST_DISCIPLINES[2][1], getter=lambda c: c[0]) subject_area = factory.Iterator(SCIPOST_SUBJECT_AREAS[0][1], getter=lambda c: c[0]) diff --git a/commentaries/test_forms.py b/commentaries/test_forms.py index 7a1d1f81bfa5d7fa1e6fc12c8c1b74601b9656d4..1d1015d5be1ba50b48eab495a4ae173d5f6b996e 100644 --- a/commentaries/test_forms.py +++ b/commentaries/test_forms.py @@ -80,7 +80,7 @@ class TestDOIToQueryForm(TestCase): self.assertRegexpMatches(error_message, re.compile('already exist')) def test_physrev_doi_is_valid(self): - physrev_doi = "10.21468/SciPostPhys.2.2.010" + physrev_doi = "10.1103/PhysRevLett.123.183602" form = DOIToQueryForm({'doi': physrev_doi}) self.assertTrue(form.is_valid()) diff --git a/comments/factories.py b/comments/factories.py index ceb51dcd761a2dc415e61708eac92f84657c5451..c1956f6c58baf5c9a5ea16a23971e5b7730ee475 100644 --- a/comments/factories.py +++ b/comments/factories.py @@ -18,9 +18,9 @@ from faker import Faker class CommentFactory(factory.django.DjangoModelFactory): status = STATUS_VETTED - vetted_by = factory.Iterator(Contributor.objects.all()) + vetted_by = factory.SubFactory('scipost.factories.ContributorFactory') - author = factory.Iterator(Contributor.objects.all()) + author = factory.SubFactory('scipost.factories.ContributorFactory') comment_text = factory.Faker('paragraph') remarks_for_editors = factory.Faker('paragraph') file_attachment = Faker().file_name(extension='pdf') @@ -43,11 +43,11 @@ class CommentFactory(factory.django.DjangoModelFactory): class CommentaryCommentFactory(CommentFactory): - content_object = factory.Iterator(Commentary.objects.all()) + content_object = factory.SubFactory('commentaries.factories.CommentaryFactory') class SubmissionCommentFactory(CommentFactory): - content_object = factory.Iterator(Submission.objects.all()) + content_object = factory.SubFactory('submissions.factories.Submission') @factory.post_generation def replies(self, create, extracted, **kwargs): @@ -62,8 +62,8 @@ class ReplyCommentFactory(CommentFactory): class ThesislinkCommentFactory(CommentFactory): - content_object = factory.Iterator(ThesisLink.objects.all()) + content_object = factory.SubFactory('theses.factories.ThesisLinkFactory') class ReportCommentFactory(CommentFactory): - content_object = factory.Iterator(Report.objects.all()) + content_object = factory.SubFactory('submissions.factories.ReportFactory') diff --git a/comments/test_views.py b/comments/test_views.py index e385f0a48577e7a5bf0f330aaecde7d07137e57d..48e77f8996a5aae81822166886d0b4d0c8433250 100644 --- a/comments/test_views.py +++ b/comments/test_views.py @@ -82,6 +82,8 @@ class TestNewComment(TestCase): 'submissions:submission', kwargs={'identifier_w_vn_nr': submission.preprint.identifier_w_vn_nr} ) + print(response) + print(expected_redirect_link) self.assertRedirects(response, expected_redirect_link) def test_submitting_comment_on_commentary_creates_comment_and_redirects(self): diff --git a/journals/factories.py b/journals/factories.py index 53f7aaaca16a1ad1039c3108c111a28b1be16de3..8a67b14495c4ab31a1bf30d3c281deefd1c14f34 100644 --- a/journals/factories.py +++ b/journals/factories.py @@ -36,8 +36,8 @@ class ReferenceFactory(factory.django.DjangoModelFactory): class JournalFactory(factory.django.DjangoModelFactory): - name = factory.Iterator(Journal.objects.filter(active=True)) - doi_label = factory.Iterator(Journal.objects.filter(active=True)) + name = 'fakeJournal' + doi_label = '10.21468/fakeJournal' issn = factory.lazy_attribute(lambda n: random_digits(8)) structure = factory.Iterator(JOURNAL_STRUCTURE, getter=lambda c: c[0]) diff --git a/organizations/models.py b/organizations/models.py index 376bf3fe867eceff170b2063dad9a241021a7537..eaec80ed60f33264f4108145711774c8343225ae 100644 --- a/organizations/models.py +++ b/organizations/models.py @@ -4,6 +4,7 @@ __license__ = "AGPL v3" import datetime import hashlib +import pytz import random import string diff --git a/scipost/services.py b/scipost/services.py index 29794a0ad8b30dfa446439e79ce1b54bd98e554c..63278cdff17cbb02e2f8b8f2959c8145b7de4f29 100644 --- a/scipost/services.py +++ b/scipost/services.py @@ -23,7 +23,7 @@ class DOICaller: self._format_data() def _call_crosslink(self): - url = 'http://api.crossref.org/works/%s' % self.doi_string + url = 'https://api.crossref.org/works/%s' % self.doi_string request = requests.get(url) doi_logger.info('GET [{doi}] [request] | {url}'.format( diff --git a/scipost/test_services.py b/scipost/test_services.py index 52e05f85d0deb16030ce2ab56545616309bc33ab..44566cb6318934277c3f5e00e753193ed2e418c9 100644 --- a/scipost/test_services.py +++ b/scipost/test_services.py @@ -16,17 +16,15 @@ class ArxivCallerTest(TestCase): caller = ArxivCaller('1612.07611v1') self.assertTrue(caller.is_valid) correct_data = { - 'pub_abstract': 'The Berezinskii-Kosterlitz-Thouless (BKT) transitions of the six-state clock\nmodel on the square lattice are investigated by means of the corner-transfer\nmatrix renormalization group method. The classical analogue of the entanglement\nentropy $S( L, T )$ is calculated for $L$ by $L$ square system up to $L = 129$,\nas a function of temperature $T$. The entropy has a peak at $T = T^{*}_{~}( L\n)$, where the temperature depends on both $L$ and boundary conditions. Applying\nthe finite-size scaling to $T^{*}_{~}( L )$ and assuming the presence of BKT\ntransitions, the transition temperature is estimated to be $T_1^{~} = 0.70$ and\n$T_2^{~} = 0.88$. The obtained results agree with previous analyses. It should\nbe noted that no thermodynamic function is used in this study.', 'author_list': ['Roman KrÄmár', 'Andrej Gendiar', 'Tomotoshi Nishino'], 'arxiv_link': 'http://arxiv.org/abs/1612.07611v1', 'title': 'Phase transition of the six-state clock model observed from the\n entanglement entropy', 'pub_date': datetime.date(2016, 12, 22) + 'arxiv_link': 'https://arxiv.org/abs/1612.07611v1', 'author_list': 'Roman KrÄmár, Andrej Gendiar, Tomotoshi Nishino', 'abstract': 'The Berezinskii-Kosterlitz-Thouless (BKT) transitions of the six-state clock\nmodel on the square lattice are investigated by means of the corner-transfer\nmatrix renormalization group method. The classical analogue of the entanglement\nentropy $S( L, T )$ is calculated for $L$ by $L$ square system up to $L = 129$,\nas a function of temperature $T$. The entropy has a peak at $T = T^{*}_{~}( L\n)$, where the temperature depends on both $L$ and boundary conditions. Applying\nthe finite-size scaling to $T^{*}_{~}( L )$ and assuming the presence of BKT\ntransitions, the transition temperature is estimated to be $T_1^{~} = 0.70$ and\n$T_2^{~} = 0.88$. The obtained results agree with previous analyses. It should\nbe noted that no thermodynamic function is used in this study.', 'pub_abstract': 'The Berezinskii-Kosterlitz-Thouless (BKT) transitions of the six-state clock\nmodel on the square lattice are investigated by means of the corner-transfer\nmatrix renormalization group method. The classical analogue of the entanglement\nentropy $S( L, T )$ is calculated for $L$ by $L$ square system up to $L = 129$,\nas a function of temperature $T$. The entropy has a peak at $T = T^{*}_{~}( L\n)$, where the temperature depends on both $L$ and boundary conditions. Applying\nthe finite-size scaling to $T^{*}_{~}( L )$ and assuming the presence of BKT\ntransitions, the transition temperature is estimated to be $T_1^{~} = 0.70$ and\n$T_2^{~} = 0.88$. The obtained results agree with previous analyses. It should\nbe noted that no thermodynamic function is used in this study.', 'title': 'Phase transition of the six-state clock model observed from the\n entanglement entropy', 'pub_date': datetime.date(2016, 12, 22) } - self.assertEqual(caller.data, correct_data) + self.assertDictEqual(caller.data, correct_data) def test_identifier_old_style(self): caller = ArxivCaller('cond-mat/0612480') self.assertTrue(caller.is_valid) - correct_data = { - 'author_list': ['Kouji Ueda', 'Chenglong Jin', 'Naokazu Shibata', 'Yasuhiro Hieida', 'Tomotoshi Nishino'], 'pub_date': datetime.date(2006, 12, 19), 'arxiv_link': 'http://arxiv.org/abs/cond-mat/0612480v2', 'pub_abstract': 'A kind of least action principle is introduced for the discrete time\nevolution of one-dimensional quantum lattice models. Based on this principle,\nwe obtain an optimal condition for the matrix product states on succeeding time\nslices generated by the real-time density matrix renormalization group method.\nThis optimization can also be applied to classical simulations of quantum\ncircuits. We discuss the time reversal symmetry in the fully optimized MPS.', 'title': 'Least Action Principle for the Real-Time Density Matrix Renormalization\n Group' - } - self.assertEqual(caller.data, correct_data) + correct_data = {'arxiv_link': 'https://arxiv.org/abs/cond-mat/0612480v2', 'pub_date': datetime.date(2006, 12, 19), 'author_list': 'Kouji Ueda, Chenglong Jin, Naokazu Shibata, Yasuhiro Hieida, Tomotoshi Nishino', 'abstract': 'A kind of least action principle is introduced for the discrete time\nevolution of one-dimensional quantum lattice models. Based on this principle,\nwe obtain an optimal condition for the matrix product states on succeeding time\nslices generated by the real-time density matrix renormalization group method.\nThis optimization can also be applied to classical simulations of quantum\ncircuits. We discuss the time reversal symmetry in the fully optimized MPS.', 'pub_abstract': 'A kind of least action principle is introduced for the discrete time\nevolution of one-dimensional quantum lattice models. Based on this principle,\nwe obtain an optimal condition for the matrix product states on succeeding time\nslices generated by the real-time density matrix renormalization group method.\nThis optimization can also be applied to classical simulations of quantum\ncircuits. We discuss the time reversal symmetry in the fully optimized MPS.', 'title': 'Least Action Principle for the Real-Time Density Matrix Renormalization\n Group'} + self.assertDictEqual(caller.data, correct_data) def valid_but_nonexistent_identifier(self): caller = ArxivCaller('1613.07611v1') @@ -36,30 +34,15 @@ class ArxivCallerTest(TestCase): class DOICallerTest(TestCase): def test_works_for_physrev_doi(self): caller = DOICaller('10.1103/PhysRevB.92.214427') - correct_data = { - 'pub_date': '2015-12-18', - 'journal': 'Physical Review B', - 'pages': '', - 'author_list': [ - 'R. Vlijm', 'M. Ganahl', 'D. Fioretto', 'M. Brockmann', 'M. Haque', 'H. G. Evertz', 'J.-S. Caux'], - 'volume': '92', - 'title': 'Quasi-soliton scattering in quantum spin chains' - } + correct_data = {'title': 'Quasi-soliton scattering in quantum spin chains', 'pages': '214427', 'author_list': 'R. Vlijm, M. Ganahl, D. Fioretto, M. Brockmann, M. Haque, H. G. Evertz, J.-S. Caux', 'pub_date': '2015-12-18', 'volume': '92', 'journal': 'Physical Review B'} self.assertTrue(caller.is_valid) - self.assertEqual(caller.data, correct_data) + self.assertDictEqual(caller.data, correct_data) def test_works_for_scipost_doi(self): caller = DOICaller('10.21468/SciPostPhys.2.2.012') - correct_data = { - 'pub_date': '2017-04-04', - 'journal': 'SciPost Physics', - 'title': 'One-particle density matrix of trapped one-dimensional impenetrable bosons from conformal invariance', - 'pages': '', - 'volume': '2', - 'author_list': ['Yannis Brun', 'Jerome Dubail'] - } + correct_data = {'author_list': 'Yannis Brun, Jerome Dubail', 'pub_date': '2017-04-04', 'volume': '2', 'title': 'One-particle density matrix of trapped one-dimensional impenetrable bosons from conformal invariance', 'pages': '012', 'journal': 'SciPost Physics'} self.assertTrue(caller.is_valid) - self.assertEqual(caller.data, correct_data) + self.assertDictEqual(caller.data, correct_data) def test_valid_but_non_existent_doi(self): caller = DOICaller('10.21468/NonExistentJournal.2.2.012') diff --git a/scipost/test_views.py b/scipost/test_views.py index 69fae6f60af05b50488b655a7bbe00e1bafb701b..6c7a74b16daf9c835269be6d860e2738f25882da 100644 --- a/scipost/test_views.py +++ b/scipost/test_views.py @@ -6,6 +6,8 @@ from django.urls import reverse from django.contrib.auth.models import Group from django.test import TestCase, Client, tag +from common.helpers.test import add_groups_and_permissions + from commentaries.factories import UnvettedCommentaryFactory, CommentaryFactory,\ UnpublishedCommentaryFactory from commentaries.forms import CommentarySearchForm @@ -16,9 +18,11 @@ from .factories import ContributorFactory class RequestCommentaryTest(TestCase): """Test cases for `request_commentary` view method""" - fixtures = ['permissions', 'groups', 'contributors'] def setUp(self): + add_groups_and_permissions() + self.contributor = ContributorFactory(user__username='Test', + user__password='testpw') self.view_url = reverse('commentaries:request_commentary') self.login_url = reverse('scipost:login') self.redirected_login_url = '%s?next=%s' % (self.login_url, self.view_url) @@ -43,9 +47,9 @@ class RequestCommentaryTest(TestCase): class VetCommentaryRequestsTest(TestCase): """Test cases for `vet_commentary_requests` view method""" - fixtures = ['groups', 'permissions'] def setUp(self): + add_groups_and_permissions() self.view_url = reverse('commentaries:vet_commentary_requests') self.login_url = reverse('scipost:login') self.password = 'test123' @@ -95,9 +99,9 @@ class VetCommentaryRequestsTest(TestCase): class BrowseCommentariesTest(TestCase): """Test cases for `browse` view.""" - fixtures = ['groups', 'permissions'] def setUp(self): + add_groups_and_permissions() CommentaryFactory(discipline='physics') self.view_url = reverse('commentaries:browse', kwargs={ 'discipline': 'physics', @@ -110,15 +114,15 @@ class BrowseCommentariesTest(TestCase): self.assertEquals(response.status_code, 200) # The created vetted Commentary is found! - self.assertTrue(response.context['commentary_browse_list'].count() >= 1) + self.assertTrue(response.context['commentary_list'].count() >= 1) # The search form is passed trough the view... self.assertTrue(type(response.context['form']) is CommentarySearchForm) class CommentaryDetailTest(TestCase): - fixtures = ['permissions', 'groups'] def setUp(self): + add_groups_and_permissions() self.client = Client() self.commentary = UnpublishedCommentaryFactory() self.target = reverse( diff --git a/submissions/factories.py b/submissions/factories.py index b5c73254a499b43d31bfda2e2425a02e289b4e79..a940deff54205c218055b160aa11a14a0f1148bb 100644 --- a/submissions/factories.py +++ b/submissions/factories.py @@ -15,7 +15,7 @@ from common.helpers import random_scipost_report_doi_label from .constants import ( STATUS_UNASSIGNED, STATUS_EIC_ASSIGNED, STATUS_INCOMING, STATUS_PUBLISHED, SUBMISSION_TYPE, STATUS_RESUBMITTED, STATUS_VETTED, REFEREE_QUALIFICATION, RANKING_CHOICES, QUALITY_SPEC, - REPORT_REC, REPORT_STATUSES, STATUS_UNVETTED, STATUS_DRAFT) + REPORT_REC, REPORT_STATUSES, STATUS_UNVETTED, STATUS_DRAFT, ASSIGNMENT_STATUSES) from .models import Submission, Report, RefereeInvitation, EICRecommendation, EditorialAssignment from faker import Faker @@ -27,14 +27,14 @@ class SubmissionFactory(factory.django.DjangoModelFactory): """ author_list = factory.Faker('name') - submitted_by = factory.Iterator(Contributor.objects.all()) + submitted_by = factory.SubFactory('scipost.factories.ContributorFactory') submission_type = factory.Iterator(SUBMISSION_TYPE, getter=lambda c: c[0]) - submitted_to = factory.Iterator(Journal.objects.all()) + submitted_to = factory.SubFactory('journals.factories.JournalFactory') title = factory.Faker('sentence') abstract = factory.Faker('paragraph', nb_sentences=10) list_of_changes = factory.Faker('paragraph', nb_sentences=10) subject_area = factory.Iterator(SCIPOST_SUBJECT_AREAS[0][1], getter=lambda c: c[0]) - approaches = factory.Iterator(SCIPOST_APPROACHES, getter=lambda c: c[0]) + approaches = factory.Iterator(SCIPOST_APPROACHES, getter=lambda c: [c[0],]) abstract = factory.Faker('paragraph') author_comments = factory.Faker('paragraph') remarks_for_editors = factory.Faker('paragraph') @@ -91,10 +91,10 @@ class EICassignedSubmissionFactory(SubmissionFactory): status = STATUS_EIC_ASSIGNED open_for_commenting = True open_for_reporting = True - - @factory.lazy_attribute - def editor_in_charge(self): - return Contributor.objects.order_by('?').first() + editor_in_charge = factory.SubFactory('scipost.factories.ContributorFactory') + # @factory.lazy_attribute + # def editor_in_charge(self): + # return Contributor.objects.order_by('?').first() @factory.post_generation def eic_assignment(self, create, extracted, **kwargs): @@ -257,11 +257,11 @@ class PublishedSubmissionFactory(EICassignedSubmissionFactory): class ReportFactory(factory.django.DjangoModelFactory): status = factory.Iterator(REPORT_STATUSES, getter=lambda c: c[0]) - submission = factory.Iterator(Submission.objects.all()) - report_nr = 1 + submission = factory.SubFactory('submissions.factories.SubmissionFactory') + report_nr = factory.LazyAttribute(lambda o: o.submission.reports.count() + 1) date_submitted = factory.Faker('date_time_this_decade') - vetted_by = factory.Iterator(Contributor.objects.all()) - author = factory.Iterator(Contributor.objects.all()) + vetted_by = factory.SubFactory('scipost.factories.ContributorFactory') + author = factory.SubFactory('scipost.factories.ContributorFactory') strengths = factory.Faker('paragraph') weaknesses = factory.Faker('paragraph') report = factory.Faker('paragraph') @@ -372,10 +372,8 @@ class EditorialAssignmentFactory(factory.django.DjangoModelFactory): mostly be done using the post_generation hook in any SubmissionFactory. """ submission = None - to = factory.Iterator(Contributor.objects.all()) - accepted = True - deprecated = False - completed = False + to = factory.SubFactory('scipost.factories.ContributorFactory') + status = factory.Iterator(ASSIGNMENT_STATUSES, getter=lambda c: c[0]) date_created = factory.lazy_attribute(lambda o: o.submission.latest_activity) date_answered = factory.lazy_attribute(lambda o: o.submission.latest_activity)