当前位置: 首页>>代码示例>>Python>>正文


Python Payday.record_credit方法代码示例

本文整理汇总了Python中gittip.billing.payday.Payday.record_credit方法的典型用法代码示例。如果您正苦于以下问题:Python Payday.record_credit方法的具体用法?Python Payday.record_credit怎么用?Python Payday.record_credit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gittip.billing.payday.Payday的用法示例。


在下文中一共展示了Payday.record_credit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestBillingTransfer

# 需要导入模块: from gittip.billing.payday import Payday [as 别名]
# 或者: from gittip.billing.payday.Payday import record_credit [as 别名]

#.........这里部分代码省略.........
                self.payday.debit_participant(cur, subject.username, amount)
            conn.commit()

    def test_skim_credit(self):
        actual = skim_credit(Decimal('10.00'))
        assert actual == (Decimal('10.00'), Decimal('0.00')), actual

    def test_credit_participant(self):
        amount = Decimal('1.00')
        subject = self.make_participant('test_credit_participant', pending=0,
                                        balance=1)

        initial_amount = subject.pending

        with self.postgres.get_connection() as conn:
            cur = conn.cursor()
            self.payday.credit_participant(cur, subject.username, amount)
            conn.commit()

        self.session.refresh(subject)

        expected = initial_amount + amount
        actual = subject.pending
        assert_equals(actual, expected)

    def test_record_transfer(self):
        from gittip.models import Transfer
        amount = Decimal('1.00')
        subjects = ['jim', 'kate', 'bob']

        for subject in subjects:
            self.make_participant(subject, balance=1, pending=0)

        with self.postgres.get_connection() as conn:
            cur = conn.cursor()

            # Tip 'jim' twice
            for recipient in ['jim'] + subjects:
                self.payday.record_transfer( cur
                                           , self.tipper.username
                                           , recipient
                                           , amount
                                            )
            conn.commit()

        for subject in subjects:
            # 'jim' is tipped twice
            expected = amount * 2 if subject == 'jim' else amount
            transfers = Transfer.query.filter_by(tippee=subject).all()
            actual = sum(tip.amount for tip in transfers)
            assert_equals(actual, expected)

    def test_record_transfer_invalid_participant(self):
        amount = Decimal('1.00')

        with self.postgres.get_connection() as conn:
            cur = conn.cursor()
            with assert_raises(IntegrityError):
                self.payday.record_transfer(cur, 'idontexist', 'nori', amount)
            conn.commit()

    def test_mark_transfer(self):
        amount = Decimal('1.00')

        # Forces a load with current state in dict
        before_transfer = PaydayModel.query.first().attrs_dict()

        with self.postgres.get_connection() as conn:
            cur = conn.cursor()
            self.payday.mark_transfer(cur, amount)
            conn.commit()

        # Forces a load with current state in dict
        after_transfer = PaydayModel.query.first().attrs_dict()

        expected = before_transfer['ntransfers'] + 1
        actual = after_transfer['ntransfers']
        assert_equals(actual, expected)

        expected = before_transfer['transfer_volume'] + amount
        actual = after_transfer['transfer_volume']
        assert_equals(actual, expected)

    def test_record_credit_updates_balance(self):
        alice = self.make_participant("alice")
        self.payday.record_credit( amount=Decimal("-1.00")
                                 , fee=Decimal("0.41")
                                 , error=""
                                 , username="alice"
                                  )
        assert_equals(alice.balance, Decimal("0.59"))

    def test_record_credit_doesnt_update_balance_if_error(self):
        alice = self.make_participant("alice")
        self.payday.record_credit( amount=Decimal("-1.00")
                                 , fee=Decimal("0.41")
                                 , error="SOME ERROR"
                                 , username="alice"
                                  )
        assert_equals(alice.balance, Decimal("0.00"))
开发者ID:arnaldorusso,项目名称:www.gittip.com,代码行数:104,代码来源:test_billing_payday.py

示例2: TestBillingTransfer

# 需要导入模块: from gittip.billing.payday import Payday [as 别名]
# 或者: from gittip.billing.payday.Payday import record_credit [as 别名]

#.........这里部分代码省略.........
        assert actual == expected

        # this will fail because not enough balance
        with self.db.get_cursor() as cursor:
            with self.assertRaises(IntegrityError):
                self.payday.debit_participant(cursor, subject.username, amount)

    def test_skim_credit(self):
        actual = skim_credit(Decimal('10.00'))
        assert actual == (Decimal('10.00'), Decimal('0.00'))

    def test_credit_participant(self):
        amount = Decimal('1.00')
        subject = self.make_participant('test_credit_participant', pending=0,
                                        balance=1)

        initial_amount = subject.pending

        with self.db.get_cursor() as cursor:
            self.payday.credit_participant(cursor, subject.username, amount)

        subject = Participant.from_username('test_credit_participant') # reload

        expected = initial_amount + amount
        actual = subject.pending
        assert actual == expected

    def test_record_transfer(self):
        amount = Decimal('1.00')
        subjects = ['jim', 'kate', 'bob']

        for subject in subjects:
            self.make_participant(subject, balance=1, pending=0)

        with self.db.get_cursor() as cursor:
            # Tip 'jim' twice
            for recipient in ['jim'] + subjects:
                self.payday.record_transfer( cursor
                                           , self.tipper.username
                                           , recipient
                                           , amount
                                            )

        for subject in subjects:
            # 'jim' is tipped twice
            expected = amount * 2 if subject == 'jim' else amount
            actual = self.db.one( "SELECT sum(amount) FROM transfers "
                                  "WHERE tippee=%s"
                                , (subject,)
                                 )
            assert actual == expected

    def test_record_transfer_invalid_participant(self):
        amount = Decimal('1.00')

        with self.db.get_cursor() as cursor:
            with self.assertRaises(IntegrityError):
                self.payday.record_transfer( cursor
                                           , 'idontexist'
                                           , 'nori'
                                           , amount
                                            )

    def test_mark_transfer(self):
        amount = Decimal('1.00')

        # Forces a load with current state in dict
        before_transfer = self.fetch_payday()

        with self.db.get_cursor() as cursor:
            self.payday.mark_transfer(cursor, amount)

        # Forces a load with current state in dict
        after_transfer = self.fetch_payday()

        expected = before_transfer['ntransfers'] + 1
        actual = after_transfer['ntransfers']
        assert actual == expected

        expected = before_transfer['transfer_volume'] + amount
        actual = after_transfer['transfer_volume']
        assert actual == expected

    def test_record_credit_updates_balance(self):
        self.payday.record_credit( amount=Decimal("-1.00")
                                 , fee=Decimal("0.41")
                                 , error=""
                                 , username="alice"
                                  )
        alice = Participant.from_username('alice')
        assert alice.balance == Decimal("0.59")

    def test_record_credit_doesnt_update_balance_if_error(self):
        self.payday.record_credit( amount=Decimal("-1.00")
                                 , fee=Decimal("0.41")
                                 , error="SOME ERROR"
                                 , username="alice"
                                  )
        alice = Participant.from_username('alice')
        assert alice.balance == Decimal("0.00")
开发者ID:bradparks,项目名称:www.gittip.com,代码行数:104,代码来源:test_billing_payday.py


注:本文中的gittip.billing.payday.Payday.record_credit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。