File: test_sepa_direct_debit_account.py

package info (click to toggle)
python-braintree 4.31.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,576 kB
  • sloc: python: 28,946; makefile: 9; sh: 8
file content (61 lines) | stat: -rw-r--r-- 2,770 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from tests.test_helper import *
import time
from braintree.test.nonces import Nonces

class TestSepaDirectDebitAccount(unittest.TestCase):
    def test_find_returns_sepa_direct_debit_account(self):
        result = PaymentMethod.create({
            "customer_id": Customer.create().customer.id,
            "payment_method_nonce": Nonces.SepaDirectDebit
        })
        self.assertTrue(result.is_success)

        found_account = SepaDirectDebitAccount.find(result.payment_method.token)
        self.assertEqual(found_account.bank_reference_token, "a-fake-bank-reference-token")
        self.assertEqual(found_account.mandate_type, "RECURRENT")
        self.assertEqual(found_account.last_4, "1234")
        self.assertEqual(found_account.merchant_or_partner_customer_id, "a-fake-mp-customer-id")
        self.assertEqual(found_account.token, result.payment_method.token)
        self.assertTrue(found_account.global_id)

    def test_find_returns_subscriptions_associated_with_a_sepa_direct_debit_account(self):
        result = PaymentMethod.create({
            "customer_id": Customer.create().customer.id,
            "payment_method_nonce": Nonces.SepaDirectDebit
        })
        self.assertTrue(result.is_success)

        token = result.payment_method.token

        subscription1 = Subscription.create({
            "payment_method_token": token,
            "plan_id": TestHelper.trialless_plan["id"]
        }).subscription

        subscription2 = Subscription.create({
            "payment_method_token": token,
            "plan_id": TestHelper.trialless_plan["id"]
        }).subscription

        sepa_direct_debit_account = SepaDirectDebitAccount.find(result.payment_method.token)
        self.assertTrue(subscription1.id in [s.id for s in sepa_direct_debit_account.subscriptions])
        self.assertTrue(subscription2.id in [s.id for s in sepa_direct_debit_account.subscriptions])

    def test_find_raises_on_not_found_token(self):
        self.assertRaises(NotFoundError, SepaDirectDebitAccount.find, "non-existant-token")

    def test_delete_sepa_direct_debit_account(self):
        result = PaymentMethod.create({
            "customer_id": Customer.create().customer.id,
            "payment_method_nonce": Nonces.SepaDirectDebit
        })
        self.assertTrue(result.is_success)
        sepa_direct_debit_account_token = result.payment_method.token

        delete_result = SepaDirectDebitAccount.delete(sepa_direct_debit_account_token)
        self.assertTrue(delete_result.is_success)

        self.assertRaises(NotFoundError, SepaDirectDebitAccount.find, sepa_direct_debit_account_token)

    def test_delete_raises_on_not_found(self):
        self.assertRaises(NotFoundError, SepaDirectDebitAccount.delete, "non-existant-token")