class TestContingent(AgiloTestCase): def setUp(self): self.super() self.team = self.teh.create_team(name='Team1') self.member1 = self.teh.create_member(name='Member 1', team=self.team) self.sprint = self.teh.create_sprint('Test Sprint', team=self.team) self.manager = ContingentModelManager(self.teh.get_env()) self.contingent = self.manager.create(name='Bugfixing', amount=10, sprint=self.sprint) def test_can_add_time_to_contingent(self): self.contingent.add_time(5) self.assert_equals(5, self.contingent.actual) def test_can_remove_time_from_contingents(self): self.contingent.add_time(4) self.contingent.add_time(-1) self.assert_equals(3, self.contingent.actual) def test_can_not_reduce_used_time_below_zero(self): self.assert_raises(Contingent.UnderflowException, lambda: self.contingent.add_time(-1)) self.assert_equals(0, self.contingent.actual) def test_adding_time_must_not_exceed_contingent_amount(self): self.contingent.add_time(5) e = self.assert_raises(Contingent.ExceededException, self.contingent.add_time, 6) self.assert_equals(1, e.amount) def test_can_create_contingent_with_percentage_of_capacity(self): contingent = self.manager.create(name='Support', percent=17, sprint=self.sprint) ten_percent_of_total_capacity = self.sprint.get_capacity_hours() * 0.17 self.assert_not_equals(0, contingent.amount) self.assert_almost_equals(ten_percent_of_total_capacity, contingent.amount, places=2)
def setUp(self): self.super() self.team = self.teh.create_team(name='Team1') self.member1 = self.teh.create_member(name='Member 1', team=self.team) self.sprint = self.teh.create_sprint('Test Sprint', team=self.team) self.manager = ContingentModelManager(self.teh.get_env()) self.contingent = self.manager.create(name='Bugfixing', amount=10, sprint=self.sprint)
def __init__(self): self.sp_manager = SprintModelManager(self.env) self.c_manager = ContingentModelManager(self.env)
def create_contingent(self, name, amount=20, actual=0): model_manager = ContingentModelManager(self.env) return model_manager.create(name=name, sprint=self.sprint, amount=amount, actual=actual)
def _clear_model_cache(self): ContingentModelManager(self.env).get_cache().invalidate()
def setUp(self): self.super() self.team = self.teh.create_team(name='Team1') self.first_sprint = self.teh.create_sprint('Test Sprint', team=self.team) self.manager = ContingentModelManager(self.teh.get_env())
class TestContingent(AgiloTestCase): def setUp(self): self.super() self.team = self.teh.create_team(name='Team1') self.first_sprint = self.teh.create_sprint('Test Sprint', team=self.team) self.manager = ContingentModelManager(self.teh.get_env()) def _add_time_to_contingent(self, contingent_name, sprint, nr_hours): self._clear_model_cache() cmd = ContingentController.AddTimeToContingentCommand(self.env, name=contingent_name, sprint=sprint.name, delta=str(nr_hours)) return ContingentController(self.env).process_command(cmd) def _create_contingent(self, contingent_name, sprint, amount): self._clear_model_cache() cmd = ContingentController.AddContingentCommand(self.env, name=contingent_name, sprint=sprint.name, amount=str(amount)) ContingentController(self.env).process_command(cmd) return self._get_contingent(contingent_name, sprint) def _clear_model_cache(self): ContingentModelManager(self.env).get_cache().invalidate() def _get_contingent(self, contingent_name, sprint): self._clear_model_cache() return ContingentController(self.env).get(name=contingent_name, sprint=sprint) def test_time_is_added_to_correct_contingent_even_if_two_contingents_with_the_same_name_exist(self): first_sprint = self.first_sprint second_sprint = self.teh.create_sprint('Second Sprint', team=self.team) self._create_contingent('Support', first_sprint, 10) self._create_contingent('Support', second_sprint, 5) self._add_time_to_contingent('Support', first_sprint, 4) # we need to load it from the db again... first_contingent = self._get_contingent('Support', first_sprint) second_contingent = self._get_contingent('Support', second_sprint) self.assert_equals(4, first_contingent.actual) self.assert_equals(0, second_contingent.actual) def _get_contingent_totals_for_sprint(self, sprint): cmd = ContingentController.GetSprintContingentTotalsCommand(self.env, sprint=sprint) return ContingentController(self.env).process_command(cmd) def test_contingent_model_manager_can_work_with_sprint_names(self): second_sprint = self.teh.create_sprint('Second Sprint', team=self.team) self.manager.create(name='Bugfixing', amount=4, sprint=self.first_sprint) self.manager.create(name='Support', amount=7, sprint=self.first_sprint) self.manager.create(name='Support', amount=20, sprint=second_sprint) self.manager.create(name='Bugfixing', amount=13, sprint=second_sprint) first_sprint_data = self._get_contingent_totals_for_sprint(self.first_sprint) self.assert_equals(4+7, first_sprint_data.amount) self.assert_equals(0, first_sprint_data.actual) second_sprint_data = self._get_contingent_totals_for_sprint(second_sprint) self.assert_equals(20+13, second_sprint_data.amount) self.assert_equals(0, second_sprint_data.actual) def test_can_get_contingents_with_command(self): self._create_contingent('fnord', self.first_sprint, 42) contingent = ContingentController(self.env).get(name='fnord', sprint=self.first_sprint) self.assert_equals('fnord', contingent.name) self.assert_equals(self.first_sprint.name, contingent.sprint.name) self.assert_equals(42, contingent.amount) self.assert_equals(0, contingent.actual) def test_cannot_create_two_contingents_with_same_name_in_a_sprint(self): self._create_contingent('Support', self.first_sprint, 10) self.assert_raises(ICommand.NotValidError, self._create_contingent, 'Support', self.first_sprint, 5) def test_raise_commanderror_if_new_total_is_negative(self): self._create_contingent('Support', self.first_sprint, 10) add_time = lambda: self._add_time_to_contingent('Support', self.first_sprint, -3) self.assertRaises(ICommand.CommandError, add_time)
def manager(self): return ContingentModelManager(self.env)