From 2fb06b63242d30c25436f40c1b0a0763f72432b2 Mon Sep 17 00:00:00 2001 From: Jorran de Wit <jorrandewit@outlook.com> Date: Thu, 11 May 2017 21:38:03 +0200 Subject: [PATCH] Add first basics for Submission cycle test --- common/helpers/test.py | 1 + submissions/factories.py | 30 +++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/common/helpers/test.py b/common/helpers/test.py index 2c0d7c96d..e7ed63a92 100644 --- a/common/helpers/test.py +++ b/common/helpers/test.py @@ -1,4 +1,5 @@ import scipost.management.commands.add_groups_and_permissions + def add_groups_and_permissions(): scipost.management.commands.add_groups_and_permissions.Command().handle(verbose=False) diff --git a/submissions/factories.py b/submissions/factories.py index f69a50ec0..cdf905fb5 100644 --- a/submissions/factories.py +++ b/submissions/factories.py @@ -44,10 +44,13 @@ class SubmissionFactory(factory.django.DjangoModelFactory): @factory.post_generation def contributors(self, create, extracted, **kwargs): contributors = list(Contributor.objects.order_by('?') - .exclude(pk=self.submitted_by.pk).all()[:4]) + .exclude(pk=self.submitted_by.pk).all()[:3]) if not create: return - self.editor_in_charge = contributors.pop() + # Auto-add the submitter as an author + self.authors.add(self.submitted_by) + + # Add three random authors for contrib in contributors: self.authors.add(contrib) self.author_list += ', %s %s' % (contrib.user.first_name, contrib.user.last_name) @@ -55,12 +58,22 @@ class SubmissionFactory(factory.django.DjangoModelFactory): @factory.post_generation def dates(self, create, extracted, **kwargs): timezone.now() - self.submission_date = Faker().date_time_between(start_date="-3y", end_date="now", - tzinfo=pytz.UTC) + if kwargs.get('submission', False): + self.submission_date = kwargs['submission'] + else: + self.submission_date = Faker().date_time_between(start_date="-3y", end_date="now", + tzinfo=pytz.UTC) self.latest_activity = Faker().date_time_between(start_date=self.submission_date, end_date="now", tzinfo=pytz.UTC) +class UnassignedSubmissionFactory(SubmissionFactory): + ''' + This Submission is a 'new request' by a Contributor for its Submission. + ''' + status = STATUS_UNASSIGNED + + class EICassignedSubmissionFactory(SubmissionFactory): status = STATUS_EIC_ASSIGNED open_for_commenting = True @@ -70,9 +83,12 @@ class EICassignedSubmissionFactory(SubmissionFactory): def report_dates(self, create, extracted, **kwargs): self.reporting_deadline = self.latest_activity + datetime.timedelta(weeks=2) - -class UnassignedSubmissionFactory(SubmissionFactory): - status = STATUS_UNASSIGNED + @factory.post_generation + def eic(self, create, extracted, **kwargs): + author_ids = list(self.authors.values_list('id', flat=True)) + self.editor_in_charge = (Contributor.objects.order_by('?') + .exclude(pk=self.submitted_by.pk) + .exclude(pk__in=author_ids).first()) class ResubmittedScreeningSubmissionFactory(SubmissionFactory): -- GitLab