Ejemplo n.º 1
0
    def test_only_one_active_duty_and_unable_clear_unfinished_duty(self):
        """One duty at a time handled by single manager. 
        New duty cannot be created when ongoing duty not finished yet.
        """
        duty_manager = DutyManager()

        # verify initially no existing duty
        self.assertIsNone(duty_manager.duty)

        # start 3 hour 1st duty with user1
        duty_manager.start_duty(self.user1)

        # verify duty started in duty manager
        self.assertIsNotNone(duty_manager.duty)

        # expect 2nd duty cannot be started since
        # there is already an active one
        with self.assertRaises(CannotStartOverOngoingDuty):
            duty_manager.start_duty(self.user2)

        # expect 2nd duty not created, hence DoesNotExist must be raised
        with self.assertRaises(Duty.DoesNotExist):
            duty2 = self.user2.duty

        # expect 1st duty can't be cleared since
        # not finished yet
        with self.assertRaises(CannotClearUnfinishedDuty):
            duty_manager.clear_duty()

        # 1st duty remain active in duty manager
        self.assertIsNotNone(duty_manager.duty)
Ejemplo n.º 2
0
    def test_start_and_clear_duty(self):
        """Duty manager can start duty if previously there is no duty
        then the duty can be cleared and replaced with newer one.
        """
        duty_manager = DutyManager()

        # verify initially no existing duty
        self.assertIsNone(duty_manager.duty)

        # start duty with auto_flush off
        duty_manager.start_duty(self.user1)

        # verify duty is started in duty manager
        self.assertIsNotNone(duty_manager.duty)
        self.assertIs(duty_manager.duty, self.user1.duty)
        self.assertIs(self.user1, duty_manager.user)

        # clear current duty
        duty_manager.force_fast_forward_duty(next_minutes=-1)
        duty_manager.clear_duty()

        # verify duty is cleared
        self.assertIsNone(duty_manager.duty)

        # expect duty to be deleted, hence DoesNotExist must be raised
        with self.assertRaises(Duty.DoesNotExist):
            self.user1.duty