def test_give_guzas_to_should_increase_balance_outcome(self): source = User("source", None) target = Company("target", [User(None, None)]) for i in range(10): source.create_daily_guzis(date(2010, 1, i + 1)) source.give_guzas_to(target, 10) self.assertEqual(len(source.balance.outcome), 10)
def test_give_guzas_to_should_correctly_transfert_guzas(self): """ If a user source gives guzas to a target company, source must lose his guzas from his guza_wallet and target should have guza_wallet increased of the amount """ source = User("source", None) target = Company("target", [User(None, None)]) for i in range(10): source.create_daily_guzis(date(2010, 1, i + 1)) self.assertEqual(len(source.guza_wallet), 10) self.assertEqual(len(target.guzi_wallet), 0) source.give_guzas_to(target, 7) self.assertEqual(len(source.guza_wallet), 3) self.assertEqual(len(target.guzi_wallet), 7)
def test_give_guzas_to_takes_older_guzas_first(self): """ When a user gives Guzas, his oldest Guzas should be spended first to avoid constant outdate """ source = User("source", None) target = Company("target", [User(None, None)]) for i in range(31): source.create_daily_guzis(date(2010, 1, i + 1)) source.give_guzas_to(target, 10) # After spending, user waits 10 days more (to be at 31) for i in range(10): source.create_daily_guzis(date(2010, 2, i + 1)) # Then, of oldest have been taken, there should have no outdated # Guza which passed to the total_accumulated source.check_outdated_guzis(date(2010, 2, 9)) self.assertEqual(len(source.guza_trashbin), 0)
def test_give_guzas_to_should_raise_error_if_target_is_not_a_company(self): user = User("id", None) target = User(None, None) with self.assertRaises(ValueError): user.give_guzas_to(target, 0)
def test_give_guzas_to_should_raise_error_if_amount_is_negative(self): user = User("id", None) with self.assertRaises(ValueError): user.give_guzas_to(None, -10)
def test_give_guzas_to_should_raise_error_if_user_cannot_afford_it(self): user = User("id", None) with self.assertRaises(ValueError): user.give_guzas_to(None, 10)