def form_valid(self, form): self.object = form.save() event = self.object wr = self.other_object person = wr.host() if person: Task.objects.create(event=event, person=person, role=Role.objects.get(name="host")) wr.state = "a" wr.event = event wr.save() if SelfOrganisedRequestAction.check(event): objs = dict(event=event, request=wr) jobs, rqjobs = ActionManageMixin.add( action_class=SelfOrganisedRequestAction, logger=logger, scheduler=scheduler, triggers=Trigger.objects.filter( active=True, action="self-organised-request-form"), context_objects=objs, object_=event, request=self.request, ) if PostWorkshopAction.check(event): objs = dict(event=event, request=wr) jobs, rqjobs = ActionManageMixin.add( action_class=PostWorkshopAction, logger=logger, scheduler=scheduler, triggers=Trigger.objects.filter( active=True, action="week-after-workshop-completion", ), context_objects=objs, object_=event, request=self.request, ) return super().form_valid(form)
def testCheckConditions(self): """Make sure `check` works for various input data.""" # totally fake Event and SelfOrganisedSubmission e = Event.objects.create( slug="test-event", host=Organization.objects.first(), administrator=Organization.objects.get(domain="self-organized"), start=date.today() + timedelta(days=7), end=date.today() + timedelta(days=8), ) e.tags.set(Tag.objects.filter(name__in=["LC", "Circuits", "automated-email"])) r = SelfOrganisedSubmission.objects.create( state="p", personal="Harry", family="Potter", email="*****@*****.**", institution_other_name="Hogwarts", workshop_url="", workshop_format="", workshop_format_other="", workshop_types_other_explain="", language=Language.objects.get(name="English"), event=e, ) r.workshop_types.set(Curriculum.objects.filter(carpentry="LC")) # 1st case: everything is good self.assertEqual(SelfOrganisedRequestAction.check(e), True) # 2nd case: event has no start date # result: FAIL e.start = None e.save() self.assertEqual(SelfOrganisedRequestAction.check(e), False) # bring back the good date e.start = date.today() + timedelta(days=7) e.save() self.assertEqual(SelfOrganisedRequestAction.check(e), True) # 3rd case: event is tagged with one (or more) excluding tags # result: FAIL for tag in ["cancelled", "stalled", "unresponsive"]: e.tags.add(Tag.objects.get(name=tag)) self.assertEqual(SelfOrganisedRequestAction.check(e), False) e.tags.remove(Tag.objects.get(name=tag)) # retest to make sure it's back to normal self.assertEqual(SelfOrganisedRequestAction.check(e), True) # 4th case: no administrator # result: FAIL e.administrator = None e.save() self.assertEqual(SelfOrganisedRequestAction.check(e), False) e.administrator = Organization.objects.get(domain="self-organized") e.save() # retest to make sure it's back to normal self.assertEqual(SelfOrganisedRequestAction.check(e), True) # 5th case: wrong administrator (Instructor Training) # result: FAIL e.administrator = Organization.objects.get(domain="carpentries.org") e.save() self.assertEqual(SelfOrganisedRequestAction.check(e), False) # retest to make sure it's back to normal e.administrator = Organization.objects.get(domain="self-organized") e.save() self.assertEqual(SelfOrganisedRequestAction.check(e), True) # 6th case: no related SelfOrganisedSubmission # result: FAIL e.selforganisedsubmission = None e.save() self.assertEqual(SelfOrganisedRequestAction.check(e), False)