コード例 #1
0
 def test_update_schedule_twice(self):
     """Make sure nothing changes if you update twice"""
     for _ in range(2):
         update_shifts(self.schedule)
         officers = get_duty_officers(self.schedule,
                                      at_time=datetime(
                                          2016, 11, 6, 0, 0, 0))
         usernames = [str(user.username) for user in officers]
         self.assertEqual(usernames, ['*****@*****.**'])
コード例 #2
0
    def test_calendar_long_name(self):
        """
        Test that we can sync oncall schedules for users with emails > 30 characters
        """
        self.schedule.ical_url = 'calendar_response_long_name.ics'
        self.schedule.save()
        update_shifts(self.schedule)

        officers = get_duty_officers(self.schedule,
                                     at_time=datetime(2016, 11, 7, 10, 0, 0))
        emails = [str(user.email) for user in officers]
        self.assertEqual(emails,
                         ['*****@*****.**'])
コード例 #3
0
    def test_multiple_schedules(self):
        """
        Add a second calendar and make sure the correct duty officers are marked
        for each calendar
        """
        self.assertEqual(len(User.objects.all()), 9)

        update_shifts(self.secondary_schedule)
        update_shifts(self.schedule)

        officers = get_duty_officers(self.secondary_schedule,
                                     at_time=datetime(2016, 11, 6, 0, 0, 0))
        usernames = [str(user.username) for user in officers]
        self.assertEqual(usernames, ['*****@*****.**'])

        old_officers = get_duty_officers(self.schedule,
                                         at_time=datetime(
                                             2016, 11, 6, 0, 0, 0))
        old_usernames = [user.username for user in old_officers]
        self.assertEqual(old_usernames, ['*****@*****.**'])
コード例 #4
0
    def test_calendar_update_remove_oncall(self):
        """
        Test that an oncall officer gets removed if they aren't on the schedule
        """
        update_shifts(self.schedule)

        officers = get_duty_officers(self.schedule,
                                     at_time=datetime(2016, 11, 8, 10, 0, 0))
        usernames = [str(user.username) for user in officers]
        self.assertEqual(usernames, ['*****@*****.**'])

        # Change the schedule
        self.schedule.ical_url = 'calendar_response_different.ics'
        self.schedule.save()
        update_shifts(self.schedule)

        officers = get_duty_officers(self.schedule,
                                     at_time=datetime(2016, 11, 8, 10, 0, 0))
        usernames = [str(user.username) for user in officers]
        self.assertEqual(usernames, ['*****@*****.**'])
コード例 #5
0
    def test_get_all_duty_officers(self):
        """
        Make sure get_all_duty_officers works with multiple calendars
        """
        self.assertEqual(len(User.objects.all()), 9)

        update_shifts(self.schedule)
        update_shifts(self.secondary_schedule)

        officers_dict = get_all_duty_officers(
            at_time=datetime(2016, 11, 6, 0, 0, 0))
        officers = []
        for item in officers_dict.iteritems():
            officers.append(item)

        self.assertEqual(len(officers), 2)

        officer_schedule = [(officers[0][0].username, officers[0][1][0].name),
                            (officers[1][0].username, officers[1][1][0].name)]
        self.assertIn(('*****@*****.**', 'Principal'), officer_schedule)
        self.assertIn(('*****@*****.**', 'Secondary'), officer_schedule)
コード例 #6
0
    def test_single_schedule(self):
        """
        Make sure the correct person is marked as a duty officer
        if there's a single calendar
        """
        # initial user plus new 8
        self.assertEqual(len(User.objects.all()), 9)

        update_shifts(self.schedule)

        officers = get_duty_officers(self.schedule,
                                     at_time=datetime(2016, 11, 6, 0, 0, 0))
        usernames = [str(user.username) for user in officers]
        self.assertEqual(usernames, ['*****@*****.**'])

        officers = get_duty_officers(self.schedule,
                                     at_time=datetime(2016, 11, 8, 0, 0, 0))
        usernames = [str(user.username) for user in officers]
        self.assertEqual(usernames, ['*****@*****.**'])

        officers = get_duty_officers(self.schedule,
                                     at_time=datetime(2016, 11, 8, 10, 0, 0))
        usernames = [str(user.username) for user in officers]
        self.assertEqual(usernames, ['*****@*****.**'])