def test_add_remove_dates(self):
        """
        Tests adding and removing dates.
        """
        # copy data to a temporary file
        src_file_path = os.path.join(BASE_DIR, u'data', u'days-off-with-expired-dates.txt')
        with codecs.open(src_file_path, 'r', 'utf-8') as f1:
            data = f1.read()
            with codecs.open(self.temp_file, 'w', 'utf-8') as f2:
                f2.write(data)

        parser = DaysOffParser()
        parser.load(self.temp_file)

        self.assertIn(u'MON', parser.get_my_days_off(u'alice'),
                      u"'MON' should be in alice's days-off list.")
        # remove
        parser.remove(u'alice', [u'MON'])
        self.assertIsNone(parser.get_my_days_off(u'alice'),
                          u"alice's days-off list should be empty after removal.")

        # add
        parser.add(u'alice', [u'WED'])
        self.assertIn(u'WED', parser.get_my_days_off(u'alice'),
                      u"'WED' should be in alice's days-off list after addition: %s")
        self.assertEqual(len(parser.get_my_days_off(u'alice')), 1,
                         u"'alice' should have only one day-off.")

        # add for a new person
        parser.add(u'charley', [u'MON'])
        self.assertIn(u'MON', parser.get_my_days_off(u'charley'),
                      u"'MON' should be in charley's days-off list after addition.")
    def test_availability(self):
        """
        Tests check_availability().
        """
        # copy data to a temporary file
        src_file_path = os.path.join(BASE_DIR, u'data', u'days-off-with-expired-dates.txt')
        with codecs.open(src_file_path, 'r', 'utf-8') as f1:
            data = f1.read()
            with codecs.open(self.temp_file, 'w', 'utf-8') as f2:
                f2.write(data)

        parser = DaysOffParser()
        parser.load(self.temp_file)

        # 2016-02-22 is a Monday
        self.assertFalse(parser.check_availability(u'alice', datetime.date(2016, 2, 22)),
                         u"'alice' should NOT be available on Monday 2016-2-22.")
        # 2016-02-23 is a Tuesday
        self.assertTrue(parser.check_availability(u'alice', datetime.date(2016, 2, 23)),
                        u"'alice' should be available on Tuesday 2016-2-23.")

        parser.remove(u'alice', u'mon')

        # add today
        today_date = datetime.date.fromtimestamp(time.time())
        today_string = today_date.strftime(u"%Y-%m-%d")
        parser.add(u'alice', [today_string])
        self.assertFalse(parser.check_availability(u'alice', today_date),
                         u"'alice' should NOT be available today after addition.")
    def test_switch_with_availability(self):
        """
        Tests switching person with availability check.
        """
        team_list = [u"alice", u"bob"]
        parser = DaysOffParser()
        scheduler = TeamRoundRobinScheduler(team_list, parser)

        # 2016-02-22 is a Monday
        parser.add(u"alice", [u"MON"])
        monday = datetime.date(2016, 2, 22)

        self.assertEqual((u"bob", 1), scheduler.switch_to_next_person(monday), u"The current person should be bob.")

        self.assertEqual((u"bob", 1), scheduler.switch_to_next_person(monday), u"The current person should be bob.")

        parser.remove(u"alice", [u"MON"])
        self.assertEqual((u"alice", 0), scheduler.switch_to_next_person(monday), u"The current person should be alice.")
    def test_check_availability(self):
        """
        Tests check_availability().
        """
        team_list = [u"alice", u"bob"]
        parser = DaysOffParser()
        scheduler = TeamRoundRobinScheduler(team_list, parser)

        self.assertTrue(
            scheduler.check_availability(u"alice", datetime.date.fromtimestamp(time.time())),
            u"alice should be available today.",
        )

        # 2016-02-22 is a Monday
        parser.add(u"alice", [u"MON"])
        self.assertFalse(
            scheduler.check_availability(u"alice", datetime.date(2016, 2, 22)),
            u"alice should not be available on 2016-02-22.",
        )

        self.assertTrue(
            scheduler.check_availability(u"charley", datetime.date(2016, 2, 22)),
            u"alice should not be available on 2016-02-22.",
        )