def test_can_count_active_plans(self): with given('2 inactive plans'): for _ in range(2): plan = IndividualPlanFactory(status=Status.Deactivated) self.repository.save(plan) with given('3 active plans'): for _ in range(3): plan = IndividualPlanFactory(status=Status.Activated) self.repository.save(plan) with when('count active plans'): active = self.repository.active_plans_count() with then('result is 3 plans'): self.assertEqual(active, 3)
def test_can_activate_a_plan(self): with given('defined not active plan'): command = DefineMonthlyPlanFactory() succeeded(self.handle(command)) name = command.name with then('plan can be activated'): succeeded(self.handle(ActivateFactory(name=name)))
def test_cannot_activate_plan_when_max_number_of_plans_activated(self): with given('max number of active plans'): for _ in range(register.get(plan.settings.MaxActivePlans)): self._define_and_activate_random_plan() with when('define and activate plan'): result = self._define_and_activate_random_plan() with expect('failure'): failed(result, plan.exce.MaxActivePlansReached)
def test_can_deactivate_an_existing_plan(self): with given('activate monthly plan'): define = DefineMonthlyPlanFactory() succeeded(self.handle(define)) succeeded(self.handle(ActivateFactory(name=define.name))) name = define.name with then('plan can be deactivated'): succeeded(self.handle(DeactivateFactory(name=name)))
def test_should_not_create_a_plan_when_a_name_already_exists(self): with given('defined plan'): name = plan.cmd.PlanName("Very cool plan for 10 bucks") succeeded(self.handle(DefineMonthlyPlanFactory(name=name))) with when('defining plan with same name'): result = self.handle(DefineMonthlyPlanFactory(name=name)) with expect('failure'): failed(result, plan.exce.AlreadyExists)
def test_can_save_a_plan(self): with given('plan'): plan = IndividualPlanFactory() with when('saves in repository'): self.repository.save(plan) self.session.close() with then('plan can be found by name'): entry = self.repository.find(plan.name) self.assertIsNotNone(entry) with expect('same values in entry'): self.assertEqual(plan.name, entry.name) self.assertEqual(plan.status, entry.status) self.assertEqual(plan.fee_amount, entry.fee_amount) self.assertEqual(plan.fee_currency, entry.fee_currency) self.assertEqual(plan.max_no_of_pauses, entry.max_no_of_pauses) self.assertEqual(plan.renewal, entry.renewal)
def test_should_create_a_plan_when_there_is_no_plan_with_such_a_name(self): with given('defined plan'): succeeded(self.handle(DefineMonthlyPlanFactory())) with then('defining yet another plan should succeed'): succeeded(self.handle(DefineMonthlyPlanFactory()))