From 2e7b64540bf9a7ad1469608524c1c8a8c079eb0d Mon Sep 17 00:00:00 2001 From: George Katsikas <giorgakis.katsikas@gmail.com> Date: Tue, 16 May 2023 17:40:29 +0200 Subject: [PATCH] add proceedings handling and tests to proofs repo --- scipost_django/production/models.py | 66 +++++++---- .../production/tests/test_models.py | 110 +++++++++++++----- 2 files changed, 129 insertions(+), 47 deletions(-) diff --git a/scipost_django/production/models.py b/scipost_django/production/models.py index f29affeb9..87868c360 100644 --- a/scipost_django/production/models.py +++ b/scipost_django/production/models.py @@ -284,36 +284,62 @@ class ProofsRepository(models.Model): ) @property - def journal_path_abbrev(self) -> str: + def journal_abbrev(self) -> str: # The DOI label is used to determine the path of the repository and template - journal_abbrev = ( - self.stream.submission.editorial_decision.for_journal.doi_label - ) - return journal_abbrev + return self.stream.submission.editorial_decision.for_journal.doi_label + + @property + def journal_subdivision(self) -> str: + """ + Return the subdivision of the repository depending on the journal type. + Regular journals are subdivided per year and month, + while proceedings are subdivided per year and conference. + """ + + # TODO: Removing the whitespace should be more standardised + # Refactor: journal and year are common to both cases + # perhaps it is best to only return the subdivision month/conference + if proceedings_issue := self.stream.submission.proceedings: + return "{journal}/{year}/{conference}".format( + journal=self.journal_abbrev, + year=self.stream.submission.proceedings.event_end_date.year, + conference=proceedings_issue.event_suffix.replace(" ", ""), + ) + else: + # Get creation date of the stream + # Warning: The month grouping of streams was done using the tasked date, + # but should now instead be the creation (opened) date. + opened_year, opened_month = self.stream.opened.strftime("%Y-%m").split("-") + + return "{journal}/{year}/{month}".format( + journal=self.journal_abbrev, + year=opened_year, + month=opened_month, + ) @property def git_path(self) -> str: - # Get creation date of the stream - # Warning: The month grouping of streams was done using the tasked date, - # but should now instead be the creation (opened) date. - creation_year, creation_month = self.stream.opened.strftime( - "%Y-%m" - ).split("-") - - return "{ROOT}/Proofs/{journal}/{year}/{month}/{repo_name}".format( + return "{ROOT}/Proofs/{journal_subdivision}/{repo_name}".format( ROOT=settings.GITLAB_ROOT, - journal=self.journal_path_abbrev, - year=creation_year, - month=creation_month, + journal_subdivision=self.journal_subdivision, repo_name=self.name, ) @property def template_path(self) -> str: - return "{ROOT}/Templates/{journal}".format( - ROOT=settings.GITLAB_ROOT, - journal=self.journal_path_abbrev, - ) + """ + Return the path to the template repository. + """ + if self.stream.submission.proceedings is not None: + return "{ROOT}/Templates/{journal_subdivision}".format( + ROOT=settings.GITLAB_ROOT, + journal_subdivision=self.journal_subdivision, + ) + else: + return "{ROOT}/Templates/{journal}".format( + ROOT=settings.GITLAB_ROOT, + journal=self.journal_abbrev, + ) def __str__(self) -> str: return f"Proofs repo for {self.stream}" diff --git a/scipost_django/production/tests/test_models.py b/scipost_django/production/tests/test_models.py index 397b48bdf..e35c6d72e 100644 --- a/scipost_django/production/tests/test_models.py +++ b/scipost_django/production/tests/test_models.py @@ -8,7 +8,7 @@ from django.test import TestCase # Create your tests here. from submissions.constants import EIC_REC_PUBLISH -from journals.models import Journal +from journals.models import Journal, Issue from submissions.models import Submission, EditorialDecision from production.models import ProductionStream, ProofsRepository from preprints.models import Preprint @@ -16,9 +16,10 @@ from ontology.models import AcademicField, Branch, Specialty from colleges.models import College from scipost.models import Contributor from profiles.models import Profile - +from proceedings.models import Proceedings from django.contrib.auth.models import User +from django.conf import settings class TestProofRepository(TestCase): @@ -89,9 +90,7 @@ class TestProofRepository(TestCase): def _create_submission(self): submission = Submission.objects.create( - preprint=Preprint.objects.get( - identifier_w_vn_nr="scipost_202101_00001v1" - ), + preprint=Preprint.objects.get(identifier_w_vn_nr="scipost_202101_00001v1"), submitted_to=Journal.objects.get(name="SciPost Physics"), title="Test submission", abstract="Test abstract", @@ -100,9 +99,7 @@ class TestProofRepository(TestCase): # specialties=Specialty.objects.filter(name="Quantum Information"), submitted_by=Contributor.objects.get(user__username="testuser"), ) - submission.authors.add( - Contributor.objects.get(user__username="testuser") - ) + submission.authors.add(Contributor.objects.get(user__username="testuser")) submission.save() def _create_production_stream(self): @@ -128,19 +125,14 @@ class TestProofRepository(TestCase): self._create_editorial_decision() self._create_production_stream() - def test_repo_scipostphys_existing_profile(self): + def test_repo_name_existing_profile(self): proofs_repo = ProofsRepository.objects.get( stream__submission__preprint__identifier_w_vn_nr="scipost_202101_00001v1" ) - self.assertEqual( - proofs_repo.git_path, - "Proofs/SciPostPhys/2021/01/scipost_202101_00001v1_User", - ) - - self.assertEqual(proofs_repo.template_path, "Templates/SciPostPhys") + self.assertEqual(proofs_repo.name, "scipost_202101_00001v1_User") - def test_repo_scipostphys_nonexisting_profile(self): + def test_repo_name_nonexisting_profile(self): proofs_repo = ProofsRepository.objects.get( stream__submission__preprint__identifier_w_vn_nr="scipost_202101_00001v1" ) @@ -148,28 +140,92 @@ class TestProofRepository(TestCase): # delete profile Contributor.objects.get(user__username="testuser").profile.delete() - self.assertEqual( - proofs_repo.git_path, - "Proofs/SciPostPhys/2021/01/scipost_202101_00001v1_User", - ) - self.assertEqual(proofs_repo.template_path, "Templates/SciPostPhys") + self.assertEqual(proofs_repo.name, "scipost_202101_00001v1_User") - def test_repo_scipostphys_double_last_name_profile(self): + def test_repo_name_double_last_name_profile(self): proofs_repo = ProofsRepository.objects.get( stream__submission__preprint__identifier_w_vn_nr="scipost_202101_00001v1" ) proofs_repo.stream.submission.author_list = "Test Usable User" - user_profile = Contributor.objects.get( - user__username="testuser" - ).profile + user_profile = Contributor.objects.get(user__username="testuser").profile user_profile.last_name = "Usable User" user_profile.save() + self.assertEqual(proofs_repo.name, "scipost_202101_00001v1_User") + + def test_repo_name_two_authors(self): + proofs_repo = ProofsRepository.objects.get( + stream__submission__preprint__identifier_w_vn_nr="scipost_202101_00001v1" + ) + + proofs_repo.stream.submission.author_list = ( + "Another Personable Person, Test Usable User" + ) + + self.assertEqual(proofs_repo.name, "scipost_202101_00001v1_Person") + + def test_repo_paths_scipostphys(self): + proofs_repo = ProofsRepository.objects.get( + stream__submission__preprint__identifier_w_vn_nr="scipost_202101_00001v1" + ) + + settings.GITLAB_ROOT = "ProjectRoot" + self.assertEqual( proofs_repo.git_path, - "Proofs/SciPostPhys/2021/01/scipost_202101_00001v1_User", + "ProjectRoot/Proofs/SciPostPhys/2021/01/scipost_202101_00001v1_User", ) - self.assertEqual(proofs_repo.template_path, "Templates/SciPostPhys") + self.assertEqual( + proofs_repo.template_path, + "ProjectRoot/Templates/SciPostPhys", + ) + + def test_repo_paths_scipostphysproc(self): + proofs_repo = ProofsRepository.objects.get( + stream__submission__preprint__identifier_w_vn_nr="scipost_202101_00001v1" + ) + + journal = Journal.objects.get(name="SciPost Physics") + journal.name = "SciPost Physics Proceedings" + journal.doi_label = "SciPostPhysProc" + journal.structure = "IO" # proceedings, as Issues Only + journal.save() + + issue = Issue.objects.create( + in_journal=journal, + number=1, + slug="proc-1", + doi_label="SciPostPhysProc.1", + ) + + proceedings = Proceedings.objects.create( + issue=issue, + submissions_open=datetime.datetime.now(), + submissions_close=datetime.datetime.now(), + submissions_deadline=datetime.datetime.now(), + event_end_date=datetime.datetime(2021, 5, 5), + event_start_date=datetime.datetime(2021, 5, 1), + event_suffix="ProcName21", + ) + + submission = Submission.objects.get( + preprint__identifier_w_vn_nr="scipost_202101_00001v1" + ) + + submission.proceedings = proceedings + submission.save() + + settings.GITLAB_ROOT = "ProjectRoot" + + self.assertEqual( + proofs_repo.git_path, + "ProjectRoot/Proofs/SciPostPhysProc/2021/ProcName21/scipost_202101_00001v1_User", + ) + + self.assertEqual( + proofs_repo.template_path, + "ProjectRoot/Templates/SciPostPhysProc/2021/ProcName21", + ) -- GitLab