Esempio n. 1
0
    def test_spend_to_user_to_himself_should_go_to_total_accumulated(self):
        """
        When a user spends his own Guzis to himself, before they become
        outdated, then they are added to total_accumulated
        """
        user = User("", None)

        for i in range(10):
            user.create_daily_guzis(date(2010, 2, i + 1))

        user.spend_to(user, 10)

        self.assertEqual(len(user.guzi_wallet), 0)
        self.assertEqual(len(user.balance.income), 0)
        self.assertEqual(len(user.balance.outcome), 0)
        self.assertEqual(len(user.total_accumulated), 10)
Esempio n. 2
0
    def test_spend_to_takes_older_guzis_first(self):
        """
        When a user pays, his oldest Guzis should be spended first
        to avoid constant outdate
        """
        source = User("source", None)
        target = User("target", None)

        for i in range(31):
            source.create_daily_guzis(date(2010, 1, i + 1))

        source.spend_to(target, 10)

        # After spending, user waits 9 days more (to be at 30)
        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
        # Guzi which passed to the total_accumulated
        source.check_outdated_guzis(date(2010, 2, 9))
        self.assertEqual(len(source.total_accumulated), 0)
Esempio n. 3
0
    def test_spend_to_should_correctly_transfert_guzis(self):
        """
        If a user source spends guzi to an target one, source must lose his
        guzis from his guzi_wallet and target should have guzi_wallet unchanged
        while his balance_income has increased of the amount
        """
        source = User("source", None)
        target = User("target", None)

        for i in range(10):
            source.create_daily_guzis(date(2010, 1, i + 1))

        self.assertEqual(len(source.guzi_wallet), 10)
        self.assertEqual(len(target.guzi_wallet), 0)
        self.assertEqual(len(target.balance.income), 0)

        source.spend_to(target, 7)

        self.assertEqual(len(source.guzi_wallet), 3)
        self.assertEqual(len(target.guzi_wallet), 0)
        self.assertEqual(len(target.balance.income), 7)
Esempio n. 4
0
    def test_spend_to_should_raise_error_if_amount_is_negative(self):
        user = User("id", None)

        with self.assertRaises(ValueError):
            user.spend_to(None, -10)
Esempio n. 5
0
    def test_spend_to_should_raise_error_if_user_cannot_afford_it(self):
        user = User("id", None)

        with self.assertRaises(ValueError):
            user.spend_to(None, 10)