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


Python Payday.mark_charge_failed方法代码示例

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


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

示例1: TestBillingCharges

# 需要导入模块: from gittip.billing.payday import Payday [as 别名]
# 或者: from gittip.billing.payday.Payday import mark_charge_failed [as 别名]
class TestBillingCharges(TestPaydayBase):
    BALANCED_ACCOUNT_URI = u'/v1/marketplaces/M123/accounts/A123'
    BALANCED_TOKEN = u'/v1/marketplaces/M123/accounts/A123/cards/C123'
    STRIPE_CUSTOMER_ID = u'cus_deadbeef'

    def setUp(self):
        super(TestBillingCharges, self).setUp()
        self.payday = Payday(self.db)

    def test_mark_missing_funding(self):
        self.payday.start()
        before = self.fetch_payday()
        missing_count = before['ncc_missing']

        self.payday.mark_missing_funding()

        after = self.fetch_payday()
        assert after['ncc_missing'] == missing_count + 1

    def test_mark_charge_failed(self):
        self.payday.start()
        before = self.fetch_payday()
        fail_count = before['ncc_failing']

        with self.db.get_cursor() as cursor:
            self.payday.mark_charge_failed(cursor)

        after = self.fetch_payday()
        assert after['ncc_failing'] == fail_count + 1

    def test_mark_charge_success(self):
        self.payday.start()
        charge_amount, fee = 4, 2

        with self.db.get_cursor() as cursor:
            self.payday.mark_charge_success(cursor, charge_amount, fee)

        # verify paydays
        actual = self.fetch_payday()
        assert actual['ncharges'] == 1

    @mock.patch('stripe.Charge')
    def test_charge_on_stripe(self, ba):
        amount_to_charge = Decimal('10.00')  # $10.00 USD
        expected_fee = Decimal('0.61')
        charge_amount, fee, msg = self.payday.charge_on_stripe(
            self.alice.username, self.STRIPE_CUSTOMER_ID, amount_to_charge)

        assert charge_amount == amount_to_charge + fee
        assert fee == expected_fee
        assert ba.find.called_with(self.STRIPE_CUSTOMER_ID)
        customer = ba.find.return_value
        assert customer.debit.called_with( int(charge_amount * 100)
                                         , self.alice.username
                                          )

    @mock.patch('balanced.Account')
    def test_charge_on_balanced(self, ba):
        amount_to_charge = Decimal('10.00')  # $10.00 USD
        expected_fee = Decimal('0.61')
        charge_amount, fee, msg = self.payday.charge_on_balanced(
            self.alice.username, self.BALANCED_ACCOUNT_URI, amount_to_charge)
        assert charge_amount == amount_to_charge + fee
        assert fee == expected_fee
        assert ba.find.called_with(self.BALANCED_ACCOUNT_URI)
        customer = ba.find.return_value
        assert customer.debit.called_with( int(charge_amount * 100)
                                         , self.alice.username
                                          )

    @mock.patch('balanced.Account')
    def test_charge_on_balanced_small_amount(self, ba):
        amount_to_charge = Decimal('0.06')  # $0.06 USD
        expected_fee = Decimal('0.59')
        expected_amount = Decimal('10.00')
        charge_amount, fee, msg = \
            self.payday.charge_on_balanced(self.alice.username,
                                           self.BALANCED_ACCOUNT_URI,
                                           amount_to_charge)
        assert charge_amount == expected_amount
        assert fee == expected_fee
        customer = ba.find.return_value
        assert customer.debit.called_with( int(charge_amount * 100)
                                         , self.alice.username
                                          )

    @mock.patch('balanced.Account')
    def test_charge_on_balanced_failure(self, ba):
        amount_to_charge = Decimal('0.06')  # $0.06 USD
        error_message = 'Woah, crazy'
        ba.find.side_effect = balanced.exc.HTTPError(error_message)
        charge_amount, fee, msg = self.payday.charge_on_balanced(
            self.alice.username, self.BALANCED_ACCOUNT_URI, amount_to_charge)
        assert msg == error_message
开发者ID:bradparks,项目名称:www.gittip.com,代码行数:96,代码来源:test_billing_payday.py

示例2: TestBillingCharges

# 需要导入模块: from gittip.billing.payday import Payday [as 别名]
# 或者: from gittip.billing.payday.Payday import mark_charge_failed [as 别名]
class TestBillingCharges(Harness):
    BALANCED_ACCOUNT_URI = u'/v1/marketplaces/M123/accounts/A123'
    BALANCED_TOKEN = u'/v1/marketplaces/M123/accounts/A123/cards/C123'
    STRIPE_CUSTOMER_ID = u'cus_deadbeef'

    def setUp(self):
        super(TestBillingCharges, self).setUp()
        self.payday = Payday(self.postgres)
        self.alice = self.make_participant('alice')

    def test_mark_missing_funding(self):
        self.payday.start()
        before = PaydayModel.query.first().attrs_dict()
        missing_count = before['ncc_missing']

        self.payday.mark_missing_funding()

        after = PaydayModel.query.first().attrs_dict()
        self.assertEqual(after['ncc_missing'], missing_count + 1)

    def test_mark_charge_failed(self):
        self.payday.start()
        before = PaydayModel.query.first().attrs_dict()
        fail_count = before['ncc_failing']

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

        after = PaydayModel.query.first().attrs_dict()
        self.assertEqual(after['ncc_failing'], fail_count + 1)

    def test_mark_charge_success(self):
        self.payday.start()
        charge_amount, fee = 4, 2

        with self.postgres.get_connection() as conn:
            cur = conn.cursor()
            self.payday.mark_charge_success(cur, charge_amount, fee)
            conn.commit()

        # verify paydays
        actual = PaydayModel.query.first().attrs_dict()
        self.assertEqual(actual['ncharges'], 1)

    @mock.patch('stripe.Charge')
    def test_charge_on_stripe(self, ba):
        amount_to_charge = Decimal('10.00')  # $10.00 USD
        expected_fee = Decimal('0.61')
        charge_amount, fee, msg = self.payday.charge_on_stripe(
            self.alice.username, self.STRIPE_CUSTOMER_ID, amount_to_charge)

        assert_equals(charge_amount, amount_to_charge + fee)
        assert_equals(fee, expected_fee)
        self.assertTrue(ba.find.called_with(self.STRIPE_CUSTOMER_ID))
        customer = ba.find.return_value
        self.assertTrue(
            customer.debit.called_with( int(charge_amount * 100)
                                      , self.alice.username
                                       )
        )

    @mock.patch('balanced.Account')
    def test_charge_on_balanced(self, ba):
        amount_to_charge = Decimal('10.00')  # $10.00 USD
        expected_fee = Decimal('0.61')
        charge_amount, fee, msg = self.payday.charge_on_balanced(
            self.alice.username, self.BALANCED_ACCOUNT_URI, amount_to_charge)
        self.assertEqual(charge_amount, amount_to_charge + fee)
        self.assertEqual(fee, expected_fee)
        self.assertTrue(ba.find.called_with(self.BALANCED_ACCOUNT_URI))
        customer = ba.find.return_value
        self.assertTrue(
            customer.debit.called_with( int(charge_amount * 100)
                                      , self.alice.username
                                       )
        )

    @mock.patch('balanced.Account')
    def test_charge_on_balanced_small_amount(self, ba):
        amount_to_charge = Decimal('0.06')  # $0.06 USD
        expected_fee = Decimal('0.59')
        expected_amount = Decimal('10.00')
        charge_amount, fee, msg = \
            self.payday.charge_on_balanced(self.alice.username,
                                           self.BALANCED_ACCOUNT_URI,
                                           amount_to_charge)
        assert_equals(charge_amount, expected_amount)
        assert_equals(fee, expected_fee)
        customer = ba.find.return_value
        self.assertTrue(
            customer.debit.called_with( int(charge_amount * 100)
                                      , self.alice.username
                                       )
        )

    @mock.patch('balanced.Account')
    def test_charge_on_balanced_failure(self, ba):
        amount_to_charge = Decimal('0.06')  # $0.06 USD
#.........这里部分代码省略.........
开发者ID:arnaldorusso,项目名称:www.gittip.com,代码行数:103,代码来源:test_billing_payday.py

示例3: TestBillingCharges

# 需要导入模块: from gittip.billing.payday import Payday [as 别名]
# 或者: from gittip.billing.payday.Payday import mark_charge_failed [as 别名]
class TestBillingCharges(Harness):
    BALANCED_ACCOUNT_URI = u"/v1/marketplaces/M123/accounts/A123"
    BALANCED_TOKEN = u"/v1/marketplaces/M123/accounts/A123/cards/C123"
    STRIPE_CUSTOMER_ID = u"cus_deadbeef"

    def setUp(self):
        super(TestBillingCharges, self).setUp()
        self.payday = Payday(self.postgres)
        self.alice = self.make_participant("alice")

    def test_mark_missing_funding(self):
        self.payday.start()
        before = PaydayModel.query.first().attrs_dict()
        missing_count = before["ncc_missing"]

        self.payday.mark_missing_funding()

        after = PaydayModel.query.first().attrs_dict()
        self.assertEqual(after["ncc_missing"], missing_count + 1)

    def test_mark_charge_failed(self):
        self.payday.start()
        before = PaydayModel.query.first().attrs_dict()
        fail_count = before["ncc_failing"]

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

        after = PaydayModel.query.first().attrs_dict()
        self.assertEqual(after["ncc_failing"], fail_count + 1)

    def test_mark_charge_success(self):
        self.payday.start()
        charge_amount, fee = 4, 2

        with self.postgres.get_connection() as conn:
            cur = conn.cursor()
            self.payday.mark_charge_success(cur, charge_amount, fee)
            conn.commit()

        # verify paydays
        actual = PaydayModel.query.first().attrs_dict()
        self.assertEqual(actual["ncharges"], 1)

    @mock.patch("stripe.Charge")
    def test_charge_on_stripe(self, ba):
        amount_to_charge = Decimal("10.00")  # $10.00 USD
        expected_fee = (amount_to_charge + FEE_CHARGE[0]) * FEE_CHARGE[1]
        expected_fee = (amount_to_charge - expected_fee.quantize(FEE_CHARGE[0], rounding=ROUND_UP)) * -1
        charge_amount, fee, msg = self.payday.charge_on_stripe(self.alice.id, self.STRIPE_CUSTOMER_ID, amount_to_charge)

        assert_equals(charge_amount, amount_to_charge + fee)
        assert_equals(fee, expected_fee)
        self.assertTrue(ba.find.called_with(self.STRIPE_CUSTOMER_ID))
        customer = ba.find.return_value
        self.assertTrue(customer.debit.called_with(int(charge_amount * 100), self.alice.id))

    @mock.patch("balanced.Account")
    def test_charge_on_balanced(self, ba):
        amount_to_charge = Decimal("10.00")  # $10.00 USD
        expected_fee = (amount_to_charge + FEE_CHARGE[0]) * FEE_CHARGE[1]
        expected_fee = (amount_to_charge - expected_fee.quantize(FEE_CHARGE[0], rounding=ROUND_UP)) * -1
        charge_amount, fee, msg = self.payday.charge_on_balanced(
            self.alice.id, self.BALANCED_ACCOUNT_URI, amount_to_charge
        )
        self.assertEqual(charge_amount, amount_to_charge + fee)
        self.assertEqual(fee, expected_fee)
        self.assertTrue(ba.find.called_with(self.BALANCED_ACCOUNT_URI))
        customer = ba.find.return_value
        self.assertTrue(customer.debit.called_with(int(charge_amount * 100), self.alice.id))

    @mock.patch("balanced.Account")
    def test_charge_on_balanced_small_amount(self, ba):
        amount_to_charge = Decimal("0.06")  # $0.06 USD
        expected_fee = Decimal("0.68")
        expected_amount = Decimal("10.00")
        charge_amount, fee, msg = self.payday.charge_on_balanced(
            self.alice.id, self.BALANCED_ACCOUNT_URI, amount_to_charge
        )
        assert_equals(charge_amount, expected_amount)
        assert_equals(fee, expected_fee)
        customer = ba.find.return_value
        self.assertTrue(customer.debit.called_with(int(charge_amount * 100), self.alice.id))

    @mock.patch("balanced.Account")
    def test_charge_on_balanced_failure(self, ba):
        amount_to_charge = Decimal("0.06")  # $0.06 USD
        error_message = "Woah, crazy"
        ba.find.side_effect = balanced.exc.HTTPError(error_message)
        charge_amount, fee, msg = self.payday.charge_on_balanced(
            self.alice.id, self.BALANCED_ACCOUNT_URI, amount_to_charge
        )
        assert_equals(msg, error_message)
开发者ID:lyndsysimon,项目名称:www.gittip.com,代码行数:97,代码来源:test_billing_payday.py


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