Ejemplo n.º 1
0
    def test_create_daily_guzis_for_empty_total_accumulated(self):
        user = User("id", None)

        user.create_daily_guzis(date(2000, 1, 1))

        self.assertEqual(len(user.guzi_wallet), 1)
        self.assertEqual(len(user.guza_wallet), 1)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    def test_check_outdated_guzis_correctly_remove_outdated_guzas(self):
        user = User("id", None)
        user.create_daily_guzis(date(2010, 1, 1))

        self.assertEqual(len(user.guza_wallet), 1)
        self.assertEqual(len(user.total_accumulated), 0)

        user.check_outdated_guzis(date(2010, 2, 1))

        self.assertEqual(len(user.guza_wallet), 0)
        self.assertEqual(len(user.guza_trashbin), 1)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
    def test_create_daily_guzis_for_round_total_accumulated(self):
        user = User("id", None)
        # With 8 guzis in total_accumulated, user should get 3 Guzis/day
        user.total_accumulated += [
            1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888
        ]

        user.create_daily_guzis(date(2000, 1, 1))

        self.assertEqual(len(user.guzi_wallet), 3)
        self.assertEqual(len(user.guza_wallet), 3)
        self.assertEqual(user.guzi_wallet[0], "2000-01-01-id-guzi0000")
        self.assertEqual(user.guzi_wallet[1], "2000-01-01-id-guzi0001")
        self.assertEqual(user.guzi_wallet[2], "2000-01-01-id-guzi0002")
        self.assertEqual(user.guza_wallet[0], "2000-01-01-id-guza0000")
        self.assertEqual(user.guza_wallet[1], "2000-01-01-id-guza0001")
        self.assertEqual(user.guza_wallet[2], "2000-01-01-id-guza0002")
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
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)