SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 40ed04cf authored by Jorran de Wit's avatar Jorran de Wit
Browse files

Merge branch 'tests' into development

parents bc5cf354 3fab0622
No related branches found
No related tags found
No related merge requests found
...@@ -38,7 +38,7 @@ class SubmissionFactory(factory.django.DjangoModelFactory): ...@@ -38,7 +38,7 @@ class SubmissionFactory(factory.django.DjangoModelFactory):
'''Fill empty arxiv fields.''' '''Fill empty arxiv fields.'''
self.arxiv_link = 'https://arxiv.org/abs/%s' % self.arxiv_identifier_wo_vn_nr self.arxiv_link = 'https://arxiv.org/abs/%s' % self.arxiv_identifier_wo_vn_nr
self.arxiv_identifier_w_vn_nr = '%sv1' % self.arxiv_identifier_wo_vn_nr self.arxiv_identifier_w_vn_nr = '%sv1' % self.arxiv_identifier_wo_vn_nr
self.arxiv_vn_nr = 1 self.arxiv_vn_nr = kwargs.get('arxiv_vn_nr', 1)
@factory.post_generation @factory.post_generation
def contributors(self, create, extracted, **kwargs): def contributors(self, create, extracted, **kwargs):
......
...@@ -8,6 +8,22 @@ from .constants import SUBMISSION_STATUS_OUT_OF_POOL, SUBMISSION_STATUS_PUBLICLY ...@@ -8,6 +8,22 @@ from .constants import SUBMISSION_STATUS_OUT_OF_POOL, SUBMISSION_STATUS_PUBLICLY
class SubmissionManager(models.Manager): class SubmissionManager(models.Manager):
def _newest_version_only(self, queryset):
"""
The current Queryset should return only the latest version
of the Arxiv submissions known to SciPost.
Method only compatible with PostGresQL
"""
# This method used a double query, which is a consequence of the complex distinct()
# filter combined with the PostGresQL engine. Without the double query, ordering
# on a specific field after filtering would be impossible.
ids = (queryset
.order_by('arxiv_identifier_wo_vn_nr', '-arxiv_vn_nr')
.distinct('arxiv_identifier_wo_vn_nr')
.values_list('id', flat=True))
return queryset.filter(id__in=ids)
def user_filter(self, user): def user_filter(self, user):
""" """
Prevent conflic of interest by filtering submissions possible related to user. Prevent conflic of interest by filtering submissions possible related to user.
...@@ -54,7 +70,8 @@ class SubmissionManager(models.Manager): ...@@ -54,7 +70,8 @@ class SubmissionManager(models.Manager):
This query contains an overcomplete set of public submissions, i.e. also containing This query contains an overcomplete set of public submissions, i.e. also containing
submissions with status "published" or "resubmitted". submissions with status "published" or "resubmitted".
""" """
return self.exclude(status__in=SUBMISSION_STATUS_PUBLICLY_INVISIBLE) queryset = self.exclude(status__in=SUBMISSION_STATUS_PUBLICLY_INVISIBLE)
return self._newest_version_only(queryset)
class EditorialAssignmentManager(models.Manager): class EditorialAssignmentManager(models.Manager):
......
...@@ -223,6 +223,17 @@ class SubmissionListTest(BaseContributorTestCase): ...@@ -223,6 +223,17 @@ class SubmissionListTest(BaseContributorTestCase):
visible_submission_ids.append(EICassignedSubmissionFactory.create().id) visible_submission_ids.append(EICassignedSubmissionFactory.create().id)
visible_submission_ids.append(PublishedSubmissionFactory.create().id) visible_submission_ids.append(PublishedSubmissionFactory.create().id)
# Extra submission with multiple versions where the newest is publicly visible
# again. Earlier versions should therefore be invisible!
arxiv_id_resubmission = random_arxiv_identifier_without_version_number()
ResubmittedSubmissionFactory.create(arxiv_identifier_wo_vn_nr=arxiv_id_resubmission)
visible_submission_ids.append(
EICassignedSubmissionFactory.create(
arxiv_identifier_wo_vn_nr=arxiv_id_resubmission,
fill_arxiv_fields__arxiv_vn_nr=2
).id
)
# Check with hardcoded URL as this url shouldn't change! # Check with hardcoded URL as this url shouldn't change!
client = Client() client = Client()
response = client.get('/submissions/') response = client.get('/submissions/')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment