def test_charge_and_or_transfer_short(self, charge, get_tips_and_total):
        self.db.run("""
            UPDATE participants
               SET balance=1
             WHERE username='******'
        """)

        now = datetime.utcnow()
        amount = D('1.00')
        like_a_tip = {'amount': amount, 'tippee': 'mjallday', 'ctime': now,
                      'claimed_time': now}

        # success, success, claimed, failure
        tips = [like_a_tip, like_a_tip, like_a_tip, like_a_tip]
        get_tips_and_total.return_value = tips, amount

        ts_start = datetime.utcnow()

        # In real-life we wouldn't be able to catch an error as the charge
        # method will swallow any errors and return false. We don't handle this
        # return value within charge_and_or_transfer but instead continue on
        # trying to use the remaining credit in the user's account to payout as
        # many tips as possible.
        #
        # Here we're hacking the system and throwing the exception so execution
        # stops since we're only testing this part of the method. That smells
        # like we need to refactor.

        charge.side_effect = Exception()
        with self.assertRaises(Exception):
            billing.charge_and_or_transfer(ts_start, self.janet)
        assert charge.called_with(self.janet.username,
                                  self.janet_href,
                                  amount)
    def test_charge_and_or_transfer_short(self, charge, get_tips_and_total):
        alice = self.make_participant('alice', balance='1.00',
                                      balanced_account_uri=self.BALANCED_ACCOUNT_URI,
                                      is_suspicious=False)
        now = datetime.utcnow()
        amount = Decimal('1.00')
        like_a_tip = {'amount': amount, 'tippee': 'mjallday', 'ctime': now,
                      'claimed_time': now}

        # success, success, claimed, failure
        tips = [like_a_tip, like_a_tip, like_a_tip, like_a_tip]
        get_tips_and_total.return_value = tips, amount

        ts_start = datetime.utcnow()

        # In real-life we wouldn't be able to catch an error as the charge
        # method will swallow any errors and return false. We don't handle this
        # return value within charge_and_or_transfer but instead continue on
        # trying to use the remaining credit in the user's account to payout as
        # many tips as possible.
        #
        # Here we're hacking the system and throwing the exception so execution
        # stops since we're only testing this part of the method. That smells
        # like we need to refactor.

        charge.side_effect = Exception()
        with self.assertRaises(Exception):
            billing.charge_and_or_transfer(ts_start, alice.attrs_dict())
        self.assertTrue(charge.called_with(alice.username,
                                           self.BALANCED_ACCOUNT_URI,
                                           amount))
    def test_charge_and_or_transfer_short(self, charge, get_tips_and_total):
        alice = self.make_participant('alice', balance='1.00',
                                      balanced_account_uri=self.BALANCED_ACCOUNT_URI,
                                      is_suspicious=False)
        now = datetime.utcnow()
        amount = Decimal('1.00')
        like_a_tip = {'amount': amount, 'tippee': 'mjallday', 'ctime': now,
                      'claimed_time': now}

        # success, success, claimed, failure
        tips = [like_a_tip, like_a_tip, like_a_tip, like_a_tip]
        get_tips_and_total.return_value = tips, amount

        ts_start = datetime.utcnow()

        # In real-life we wouldn't be able to catch an error as the charge
        # method will swallow any errors and return false. We don't handle this
        # return value within charge_and_or_transfer but instead continue on
        # trying to use the remaining credit in the user's account to payout as
        # many tips as possible.
        #
        # Here we're hacking the system and throwing the exception so execution
        # stops since we're only testing this part of the method. That smells
        # like we need to refactor.

        charge.side_effect = Exception()
        with self.assertRaises(Exception):
            billing.charge_and_or_transfer(ts_start, alice.attrs_dict())
        self.assertTrue(charge.called_with(alice.username,
                                           self.BALANCED_ACCOUNT_URI,
                                           amount))
    def test_charge_and_or_transfer_short(self, charge, get_tips_and_total):
        self.db.run(
            """

            UPDATE participants
               SET balance=1
                 , balanced_customer_href=%s
                 , is_suspicious=False
             WHERE username='******'

        """, (self.BALANCED_CUSTOMER_HREF, ))

        now = datetime.utcnow()
        amount = D('1.00')
        like_a_tip = {
            'amount': amount,
            'tippee': 'mjallday',
            'ctime': now,
            'claimed_time': now
        }

        # success, success, claimed, failure
        tips = [like_a_tip, like_a_tip, like_a_tip, like_a_tip]
        get_tips_and_total.return_value = tips, amount

        ts_start = datetime.utcnow()

        # In real-life we wouldn't be able to catch an error as the charge
        # method will swallow any errors and return false. We don't handle this
        # return value within charge_and_or_transfer but instead continue on
        # trying to use the remaining credit in the user's account to payout as
        # many tips as possible.
        #
        # Here we're hacking the system and throwing the exception so execution
        # stops since we're only testing this part of the method. That smells
        # like we need to refactor.

        charge.side_effect = Exception()
        with self.assertRaises(Exception):
            billing.charge_and_or_transfer(ts_start, self.alice)
        assert charge.called_with(self.alice.username,
                                  self.BALANCED_CUSTOMER_HREF, amount)
    def test_charge_and_or_transfer_short(self, charge, get_tips_and_total):
        self.db.run(
            """

            UPDATE participants
               SET balance=1
                 , balanced_customer_href=%s
                 , is_suspicious=False
             WHERE username='******'

        """,
            (self.BALANCED_CUSTOMER_HREF,),
        )

        now = datetime.utcnow()
        amount = D("1.00")
        like_a_tip = {"amount": amount, "tippee": "mjallday", "ctime": now, "claimed_time": now}

        # success, success, claimed, failure
        tips = [like_a_tip, like_a_tip, like_a_tip, like_a_tip]
        get_tips_and_total.return_value = tips, amount

        ts_start = datetime.utcnow()

        # In real-life we wouldn't be able to catch an error as the charge
        # method will swallow any errors and return false. We don't handle this
        # return value within charge_and_or_transfer but instead continue on
        # trying to use the remaining credit in the user's account to payout as
        # many tips as possible.
        #
        # Here we're hacking the system and throwing the exception so execution
        # stops since we're only testing this part of the method. That smells
        # like we need to refactor.

        charge.side_effect = Exception()
        with self.assertRaises(Exception):
            billing.charge_and_or_transfer(ts_start, self.alice)
        assert charge.called_with(self.alice.username, self.BALANCED_CUSTOMER_HREF, amount)
Пример #6
0
    def test_charge_and_or_transfer_short(self, charge, get_tips_and_total):
        amount = Decimal(1.00)
        like_a_tip = {
            'amount': amount,
            'tippee': 'mjallday',
            'ctime': datetime.utcnow(),
            'claimed_time': datetime.utcnow(),
        }

        # success, success, claimed, failure
        tips = [like_a_tip, like_a_tip, like_a_tip, like_a_tip]
        get_tips_and_total.return_value = tips, amount

        ts_start = datetime.utcnow()
        participant = {
            'balance': 0,
            'id': self.participant_id,
            'balanced_account_uri': self.balanced_account_uri,
        }


        # In real-life we wouldn't be able to catch an error as the charge
        # method will swallow any errors and return false. We don't handle this
        # return value within charge_and_or_transfer but instead continue on
        # trying to use the remaining credit in the user's account to payout as
        # many tips as possible.
        #
        # Here we're hacking the system and throwing the exception so execution
        # stops since we're only testing this part of the method. That smells
        # like we need to refactor.

        charge.side_effect = Exception()
        with self.assertRaises(Exception):
            billing.charge_and_or_transfer(ts_start, participant)
        self.assertTrue(charge.called_with(self.participant_id,
                                           self.balanced_account_uri,
                                           amount))