File: test_graphql_client.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 (50 lines) | stat: -rw-r--r-- 1,674 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
from unittest import TestCase

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

class TestGraphQLClient(TestCase):

    @staticmethod
    def get_graphql_client(environment):
        config = Configuration(environment, "integration_merchant_id",
                               public_key="integration_public_key",
                               private_key="integration_private_key")
        return config.graphql_client()

    def test_graphql_makes_valid_queries_without_variables(self):
        definition = '''
          query {
            ping
          }
        '''
        graphql_client = self.get_graphql_client(Environment.Development)
        response = graphql_client.query(definition)

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

    def test_graphql_makes_valid_queries_with_variables(self):
        definition = '''
          mutation CreateClientToken($input: CreateClientTokenInput!) {
            createClientToken(input: $input) {
            clientToken
            }
          }
        '''

        variables = {
            "input": {
                "clientToken": {
                    "merchantAccountId": "ABC123"
                }
            }
        }

        graphql_client = self.get_graphql_client(Environment.Development)
        response = graphql_client.query(definition, variables)

        self.assertTrue("data" in response)
        self.assertTrue("createClientToken" in response["data"])
        self.assertTrue("clientToken" in response["data"]["createClientToken"])