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 (77 lines) | stat: -rw-r--r-- 2,505 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
73
74
75
76
77
from tests.test_helper import *

class TestGraphQLClient(unittest.TestCase):
    def test_raise_exception_from_status_service_unavailable(self):
        response = {
            "errors": [
                {
                    "message": "error message",
                    "extensions": {
                        "errorClass": "SERVICE_AVAILABILITY"
                    }
                }
            ]
        }
        with self.assertRaises(ServiceUnavailableError):
            GraphQLClient.raise_exception_for_graphql_error(response)

    def test_raise_exception_from_status_for_upgrade_required(self):
        response = {
            "errors": [
                {
                    "message": "error message",
                    "extensions": {
                        "errorClass": "UNSUPPORTED_CLIENT"
                    }
                }
            ]
        }
        with self.assertRaises(UpgradeRequiredError):
            GraphQLClient.raise_exception_for_graphql_error(response)

    def test_raise_exception_from_too_many_requests(self):
        response = {
            "errors": [
                {
                    "message": "error message",
                    "extensions": {
                        "errorClass": "RESOURCE_LIMIT"
                    }
                }
            ]
        }
        with self.assertRaises(TooManyRequestsError):
            GraphQLClient.raise_exception_for_graphql_error(response)

    def test_does_not_raise_exception_from_validation_error(self):
        response = {
            "errors": [
                {
                    "message": "error message",
                    "extensions": {
                        "errorClass": "VALIDATION"
                    }
                }
            ]
        }
        GraphQLClient.raise_exception_for_graphql_error(response)

    def test_raise_exception_from_validation_error_and_legitimate_error(self):
        response = {
            "errors": [
                {
                    "message": "error message",
                    "extensions": {
                        "errorClass": "VALIDATION"
                    }
                },
                {
                    "message": "error message 2",
                    "extensions": {
                        "errorClass": "INTERNAL"
                    }
                }
            ]
        }
        with self.assertRaises(ServerError):
            GraphQLClient.raise_exception_for_graphql_error(response)