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 testCheckForNonContactablePerson(self):
     """Make sure `may_contact` doesn't impede `check()`."""
     # 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),
         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="*****@*****.**",
                may_contact=True)  # contact allowed
     r = Role(name="supporting-instructor")
     t = Task(event=e, person=p, role=r)
     self.assertEqual(NewSupportingInstructorAction.check(t), True)
     p.may_contact = False  # contact disallowed
     self.assertEqual(NewSupportingInstructorAction.check(t), True)
Exemple #3
0
 def _setUpRoles(self):
     """Before #626, we don't have a migration that introduces roles that
     are currently in the database.  This is an auxiliary method for adding
     them to the tests, should one need them."""
     Role.objects.bulk_create([
         Role(name="helper", verbose_name="Helper"),
         Role(name="instructor", verbose_name="Instructor"),
         Role(name="host", verbose_name="Host"),
         Role(name="learner", verbose_name="Learner"),
         Role(name="organizer", verbose_name="Organizer"),
         Role(name="tutor", verbose_name="Tutor"),
     ])
Exemple #4
0
 def _setUpRoles(self):
     """Before #626, we don't have a migration that introduces roles that
     are currently in the database.  This is an auxiliary method for adding
     them to the tests, should one need them."""
     Role.objects.bulk_create([
         Role(name='helper', verbose_name='Helper'),
         Role(name='instructor', verbose_name='Instructor'),
         Role(name='host', verbose_name='Host'),
         Role(name='learner', verbose_name='Learner'),
         Role(name='organizer', verbose_name='Organizer'),
         Role(name='tutor', verbose_name='Tutor'),
     ])
    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)