File: test_braintree_gateway.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 (72 lines) | stat: -rw-r--r-- 2,514 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
62
63
64
65
66
67
68
69
70
71
72
from tests.test_helper import *

from braintree.braintree_gateway import BraintreeGateway
from braintree.configuration import Configuration
from braintree.environment import Environment

class TestBraintreeGateway(unittest.TestCase):

    @staticmethod
    def get_gateway():
        config = Configuration("development", "integration_merchant_id",
                               public_key="integration_public_key",
                               private_key="integration_private_key")
        return BraintreeGateway(config)

    @unittest.skip("until we have a more stable ci env")
    def test_can_make_tokenize_credit_card_via_graphql(self):
        definition = """
          mutation ExampleServerSideSingleUseToken($input: TokenizeCreditCardInput!) {
            tokenizeCreditCard(input: $input) {
              paymentMethod {
                id
                usage
                details {
                  ... on CreditCardDetails {
                    bin
                    brandCode
                    last4
                    expirationYear
                    expirationMonth
                  }
                }
              }
            }
          }
        """
        variables = {
            "input" : {
                "creditCard" : {
                    "number" : "4005519200000004",
                    "expirationYear": "2024",
                    "expirationMonth": "05",
                    "cardholderName": "Joe Bloggs"
                }
            }
        }
        gateway = self.get_gateway()
        response = gateway.graphql_client.query(definition, variables)

        payment_method = response["data"]["tokenizeCreditCard"]["paymentMethod"]
        details = payment_method["details"]

        self.assertTrue("data" in response)
        self.assertTrue("id" in payment_method)
        self.assertEqual(details["bin"], "400551")
        self.assertEqual(details["last4"], "0004");
        self.assertEqual(details["brandCode"], "VISA");
        self.assertEqual(details["expirationMonth"], "05");
        self.assertEqual(details["expirationYear"], "2024");

    def test_can_make_graphql_queries_without_variables(self):
        definition = """
          query {
            ping
          }
        """
        gateway = self.get_gateway()
        response = gateway.graphql_client.query(definition)

        self.assertTrue("data" in response)
        self.assertTrue("ping" in response["data"])
        self.assertEqual("pong", response["data"]["ping"])