def test_cannot_activate_not_existing_plan(self): with when('Activating not existing plan'): command = plan.cmd.Activate(name='Not Existing Plan') result = self.handle(command) with expect('failure'): failed(result, plan.exce.DoesNotExists)
def test_plan_is_created_with_correct_values(self): command = DefineMonthlyPlanFactory() with when('defining new plan'): succeeded(self.handle(command)) with when('find a plan'): entry = self.repository.find(command.name) with then('plan is present'): self.assertIsNotNone(entry) with expect('correct values'): self.assertEqual(entry.name, command.name) self.assertEqual(entry.max_no_of_pauses, command.pauses) self.assertEqual(entry.fee_amount, command.monthlyFee.amount) self.assertEqual(entry.fee_currency, command.monthlyFee.currency) self.assertEqual(entry.renewal, Renewal.Month)
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_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_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_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)