def testCheckConditions(self): """Make sure `check` works for various input data.""" # totally fake Task, Role and Event data LC_org = Organization.objects.get(domain="librarycarpentry.org") e = Event.objects.create( slug="test-event", host=Organization.objects.first(), administrator=LC_org, start=date.today() + timedelta(days=7), end=date.today() + timedelta(days=8), ) e.tags.set( Tag.objects.filter( name__in=["SWC", "DC", "LC", "automated-email"])) p = Person(personal="Harry", family="Potter", email="*****@*****.**") r = Role(name="supporting-instructor") t = Task(event=e, person=p, role=r) # 1st case: everything is good self.assertEqual(NewSupportingInstructorAction.check(t), True) # 2nd case: event has no start date, but still valid tags e.start = None e.save() self.assertEqual(NewSupportingInstructorAction.check(t), True) # 3rd case: event start date in past, but still valid tags e.start = date(2000, 1, 1) e.save() self.assertEqual(NewSupportingInstructorAction.check(t), False) # bring back the good date e.start = date.today() + timedelta(days=7) e.save() self.assertEqual(NewSupportingInstructorAction.check(t), True) # 4th case: event is tagged with one (or more) excluding tags e.tags.add(Tag.objects.get(name="cancelled")) self.assertEqual(NewSupportingInstructorAction.check(t), False) e.tags.remove(Tag.objects.get(name="cancelled")) # 5th case: role is different than 'supporting-instructor' r.name = "helper" self.assertEqual(NewSupportingInstructorAction.check(t), False) r.name = "supporting-instructor" # 6th case: no administrator e.administrator = None e.save() self.assertEqual(NewSupportingInstructorAction.check(t), False) e.administrator = LC_org # 7th case: wrong administrator (self organized or instructor training) e.administrator = Organization.objects.get(domain="self-organized") e.save() self.assertEqual(NewSupportingInstructorAction.check(t), False) e.administrator = Organization.objects.get(domain="carpentries.org") e.save() self.assertEqual(NewSupportingInstructorAction.check(t), False)
def testCheckConditions(self): """Make sure `check` works for various input data.""" # totally fake Task, Role and Event data LC_org = Organization.objects.get(domain="librarycarpentry.org") e = Event.objects.create( slug="test-event", host=Organization.objects.first(), administrator=LC_org, start=date.today() + timedelta(days=7), end=date.today() + timedelta(days=8), # 2019-12-24: we no longer require published conditions met for # the event, so the values below were commented out # country='GB', # venue='Ministry of Magic', # address='Underground', # latitude=20.0, # longitude=20.0, # url='https://test-event.example.com', ) e.tags.set(Tag.objects.filter(name__in=["SWC", "DC", "LC", "automated-email"])) p = Person(personal="Harry", family="Potter", email="*****@*****.**") r = Role(name="instructor") t = Task(event=e, person=p, role=r) # 1st case: everything is good self.assertEqual(NewInstructorAction.check(t), True) # 2nd case: event has no start date, but still valid tags e.start = None e.save() self.assertEqual(NewInstructorAction.check(t), True) # 3rd case: event start date in past, but still valid tags e.start = date(2000, 1, 1) e.save() self.assertEqual(NewInstructorAction.check(t), False) # bring back the good date e.start = date.today() + timedelta(days=7) e.save() self.assertEqual(NewInstructorAction.check(t), True) # 4th case: event is tagged with one (or more) excluding tags e.tags.add(Tag.objects.get(name="cancelled")) self.assertEqual(NewInstructorAction.check(t), False) e.tags.remove(Tag.objects.get(name="cancelled")) # 5th case: role is different than 'instructor' r.name = "helper" self.assertEqual(NewInstructorAction.check(t), False) r.name = "instructor" # 6th case: no administrator e.administrator = None e.save() self.assertEqual(NewInstructorAction.check(t), False) e.administrator = LC_org # 7th case: wrong administrator (self organized or instructor training) e.administrator = Organization.objects.get(domain="self-organized") e.save() self.assertEqual(NewInstructorAction.check(t), False) e.administrator = Organization.objects.get(domain="carpentries.org") e.save() self.assertEqual(NewInstructorAction.check(t), False)