File: test_customer.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 (45 lines) | stat: -rw-r--r-- 1,946 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
from tests.test_helper import *

class TestCustomer(unittest.TestCase):
    def test_create_raise_exception_with_bad_keys(self):
        with self.assertRaisesRegex(KeyError, "'Invalid keys: bad_key'"):
            Customer.create({"bad_key": "value"})

    def test_create_raise_exception_with_bad_nested_keys(self):
        with self.assertRaisesRegex(KeyError, "'Invalid keys: credit_card\[bad_key\]'"):
            Customer.create({"credit_card": {"bad_key": "value"}})

    def test_update_raise_exception_with_bad_keys(self):
        with self.assertRaisesRegex(KeyError, "'Invalid keys: bad_key'"):
            Customer.update("id", {"bad_key": "value"})

    def test_update_raise_exception_with_bad_nested_keys(self):
        with self.assertRaisesRegex(KeyError, "'Invalid keys: credit_card\[bad_key\]'"):
            Customer.update("id", {"credit_card": {"bad_key": "value"}})

    def test_finding_empty_id_raises_not_found_exception(self):
        with self.assertRaises(NotFoundError):
            Customer.find(" ")

    def test_finding_none_raises_not_found_exception(self):
        with self.assertRaises(NotFoundError):
            Customer.find(None)

    def test_initialize_sets_paypal_accounts(self):
        customer = Customer("gateway", {
            "paypal_accounts": [
                {"token": "token1"},
                {"token": "token2"}
            ],
            "sepa_debit_accounts": [
                {"token": "sdd1"},
                {"token": "sdd2"}
            ]
        })

        self.assertEqual(2, len(customer.paypal_accounts))
        self.assertEqual("token1", customer.paypal_accounts[0].token)
        self.assertEqual("token2", customer.paypal_accounts[1].token)
        self.assertEqual(2, len(customer.sepa_direct_debit_accounts))
        self.assertEqual("sdd1", customer.sepa_direct_debit_accounts[0].token)
        self.assertEqual("sdd2", customer.sepa_direct_debit_accounts[1].token)