karrio-server-graph 2025.5rc1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. karrio/server/graph/__init__.py +1 -0
  2. karrio/server/graph/admin.py +3 -0
  3. karrio/server/graph/apps.py +5 -0
  4. karrio/server/graph/forms.py +59 -0
  5. karrio/server/graph/management/__init__.py +0 -0
  6. karrio/server/graph/management/commands/__init__.py +0 -0
  7. karrio/server/graph/management/commands/export_schema.py +9 -0
  8. karrio/server/graph/migrations/0001_initial.py +37 -0
  9. karrio/server/graph/migrations/0002_auto_20210512_1353.py +22 -0
  10. karrio/server/graph/migrations/__init__.py +0 -0
  11. karrio/server/graph/models.py +44 -0
  12. karrio/server/graph/schema.py +46 -0
  13. karrio/server/graph/schemas/__init__.py +2 -0
  14. karrio/server/graph/schemas/base/__init__.py +367 -0
  15. karrio/server/graph/schemas/base/inputs.py +582 -0
  16. karrio/server/graph/schemas/base/mutations.py +871 -0
  17. karrio/server/graph/schemas/base/types.py +1365 -0
  18. karrio/server/graph/serializers.py +388 -0
  19. karrio/server/graph/templates/graphql/graphiql.html +142 -0
  20. karrio/server/graph/templates/karrio/email_change_email.html +13 -0
  21. karrio/server/graph/templates/karrio/email_change_email.txt +13 -0
  22. karrio/server/graph/templates/karrio/password_reset_email.html +14 -0
  23. karrio/server/graph/tests/__init__.py +9 -0
  24. karrio/server/graph/tests/base.py +124 -0
  25. karrio/server/graph/tests/test_carrier_connections.py +219 -0
  26. karrio/server/graph/tests/test_metafield.py +404 -0
  27. karrio/server/graph/tests/test_rate_sheets.py +348 -0
  28. karrio/server/graph/tests/test_templates.py +677 -0
  29. karrio/server/graph/tests/test_user_info.py +71 -0
  30. karrio/server/graph/urls.py +10 -0
  31. karrio/server/graph/utils.py +304 -0
  32. karrio/server/graph/views.py +93 -0
  33. karrio/server/settings/graph.py +7 -0
  34. karrio_server_graph-2025.5rc1.dist-info/METADATA +29 -0
  35. karrio_server_graph-2025.5rc1.dist-info/RECORD +37 -0
  36. karrio_server_graph-2025.5rc1.dist-info/WHEEL +5 -0
  37. karrio_server_graph-2025.5rc1.dist-info/top_level.txt +2 -0
@@ -0,0 +1,124 @@
1
+ import json
2
+ import logging
3
+ import dataclasses
4
+ from django.urls import reverse
5
+ from rest_framework import status
6
+ from django.contrib.auth import get_user_model
7
+ from rest_framework.test import APITestCase as BaseAPITestCase, APIClient
8
+
9
+ from karrio.server.user.models import Token
10
+ import karrio.server.providers.models as providers
11
+
12
+ logger = logging.getLogger(__name__)
13
+
14
+
15
+ @dataclasses.dataclass
16
+ class Result:
17
+ data: dict = None
18
+ status_code: str = None
19
+
20
+
21
+ class GraphTestCase(BaseAPITestCase):
22
+ def setUp(self) -> None:
23
+ self.maxDiff = None
24
+ logging.basicConfig(level=logging.DEBUG)
25
+ # Setup user and API Token.
26
+ self.user = get_user_model().objects.create_superuser(
27
+ "admin@example.com", "test"
28
+ )
29
+ self.token = Token.objects.create(user=self.user, test_mode=False)
30
+
31
+ # Setup API client.
32
+ self.client = APIClient()
33
+ self.client.credentials(HTTP_AUTHORIZATION="Token " + self.token.key)
34
+
35
+ # Setup test carrier connections.
36
+ self.carrier = providers.Carrier.objects.create(
37
+ carrier_code="canadapost",
38
+ carrier_id="canadapost",
39
+ test_mode=False,
40
+ created_by=self.user,
41
+ credentials=dict(
42
+ username="6e93d53968881714",
43
+ customer_number="2004381",
44
+ contract_id="42708517",
45
+ password="0bfa9fcb9853d1f51ee57a",
46
+ ),
47
+ capabilities=["pickup", "rating", "tracking", "shipping"],
48
+ )
49
+ self.ups_carrier = providers.Carrier.objects.create(
50
+ carrier_code="ups",
51
+ carrier_id="ups_package",
52
+ test_mode=False,
53
+ created_by=self.user,
54
+ credentials=dict(
55
+ client_id="test",
56
+ client_secret="test",
57
+ account_number="000000",
58
+ ),
59
+ capabilities=["pickup", "rating", "tracking", "shipping"],
60
+ )
61
+ self.fedex_carrier = providers.Carrier.objects.create(
62
+ carrier_code="fedex",
63
+ carrier_id="fedex_express",
64
+ test_mode=False,
65
+ credentials=dict(
66
+ api_key="test",
67
+ secret_key="password",
68
+ account_number="000000",
69
+ track_api_key="test",
70
+ track_secret_key="password",
71
+ ),
72
+ capabilities=["pickup", "rating", "tracking", "shipping"],
73
+ is_system=True,
74
+ )
75
+ self.dhl_carrier = providers.Carrier.objects.create(
76
+ carrier_code="dhl_universal",
77
+ carrier_id="dhl_universal",
78
+ test_mode=False,
79
+ is_system=True,
80
+ credentials=dict(
81
+ consumer_key="test",
82
+ consumer_secret="password",
83
+ ),
84
+ capabilities=["tracking"],
85
+ )
86
+
87
+ def query(
88
+ self, query: str, operation_name: str = None, variables: dict = None, org_id: str = None
89
+ ) -> Result:
90
+ url = reverse("karrio.server.graph:graphql")
91
+ data = dict(
92
+ query=query,
93
+ variables=variables,
94
+ operation_name=operation_name,
95
+ )
96
+
97
+ response = self.client.post(url, data, **(
98
+ { "x-org-id": org_id } if org_id else {}
99
+ ))
100
+
101
+ return Result(
102
+ status_code=response.status_code,
103
+ data=json.loads(response.content),
104
+ )
105
+
106
+ def getJWTToken(self, email: str, password: str) -> str:
107
+ url = reverse("jwt-obtain-pair")
108
+ data = dict(
109
+ email=email,
110
+ password=password,
111
+ )
112
+ response = self.client.post(url, data)
113
+
114
+ return response.data.get("access")
115
+
116
+ def assertResponseNoErrors(self, result: Result):
117
+ if (
118
+ result.status_code != status.HTTP_200_OK
119
+ or result.data.get("errors") is not None
120
+ ):
121
+ print(result.data)
122
+
123
+ self.assertEqual(result.status_code, status.HTTP_200_OK)
124
+ assert result.data.get("errors") is None
@@ -0,0 +1,219 @@
1
+ import karrio.lib as lib
2
+ from unittest.mock import ANY
3
+ from karrio.server.graph.tests.base import GraphTestCase
4
+
5
+
6
+ class TestSystemConnections(GraphTestCase):
7
+ def test_query_system_connections(self):
8
+ response = self.query(
9
+ """
10
+ query get_system_connections {
11
+ system_connections {
12
+ id
13
+ carrier_id
14
+ carrier_name
15
+ test_mode
16
+ active
17
+ }
18
+ }
19
+ """,
20
+ operation_name="get_system_connections",
21
+ )
22
+ response_data = response.data
23
+
24
+ self.assertResponseNoErrors(response)
25
+ self.assertDictEqual(
26
+ lib.to_dict(response_data),
27
+ SYSTEM_CONNECTIONS,
28
+ )
29
+
30
+
31
+ class TestUserConnections(GraphTestCase):
32
+ def test_query_user_connections(self):
33
+ response = self.query(
34
+ """
35
+ query get_user_connections {
36
+ user_connections {
37
+ id
38
+ carrier_id
39
+ carrier_name
40
+ test_mode
41
+ active
42
+ credentials
43
+ }
44
+ }
45
+ """,
46
+ operation_name="get_user_connections",
47
+ )
48
+ response_data = response.data
49
+
50
+ self.assertResponseNoErrors(response)
51
+ self.assertDictEqual(
52
+ lib.to_dict(response_data),
53
+ USER_CONNECTIONS,
54
+ )
55
+
56
+ def test_create_user_connection(self):
57
+ response = self.query(
58
+ """
59
+ mutation create_connection($data: CreateCarrierConnectionMutationInput!) {
60
+ create_carrier_connection(input: $data) {
61
+ connection {
62
+ id
63
+ carrier_id
64
+ carrier_name
65
+ test_mode
66
+ active
67
+ credentials
68
+ }
69
+ }
70
+ }
71
+ """,
72
+ operation_name="create_connection",
73
+ variables=CONNECTION_DATA,
74
+ )
75
+ response_data = response.data
76
+
77
+ self.assertResponseNoErrors(response)
78
+ self.assertDictEqual(response_data, CONNECTION_RESPONSE)
79
+
80
+ def test_update_user_connection(self):
81
+ response = self.query(
82
+ """
83
+ mutation update_connection($data: UpdateCarrierConnectionMutationInput!) {
84
+ update_carrier_connection(input: $data) {
85
+ connection {
86
+ carrier_id
87
+ credentials
88
+ }
89
+ }
90
+ }
91
+ """,
92
+ operation_name="update_connection",
93
+ variables={
94
+ "data": {
95
+ "id": self.carrier.id,
96
+ **CONNECTION_UPDATE_DATA["data"],
97
+ },
98
+ },
99
+ )
100
+ response_data = response.data
101
+
102
+ self.assertResponseNoErrors(response)
103
+ self.assertDictEqual(
104
+ lib.to_dict(response_data),
105
+ lib.to_dict(CONNECTION_UPDATE_RESPONSE),
106
+ )
107
+
108
+
109
+ SYSTEM_CONNECTIONS = {
110
+ "data": {
111
+ "system_connections": [
112
+ {
113
+ "active": True,
114
+ "carrier_id": "dhl_universal",
115
+ "carrier_name": "dhl_universal",
116
+ "id": ANY,
117
+ "test_mode": False,
118
+ },
119
+ {
120
+ "active": True,
121
+ "carrier_id": "fedex_express",
122
+ "carrier_name": "fedex",
123
+ "id": ANY,
124
+ "test_mode": False,
125
+ },
126
+ ]
127
+ }
128
+ }
129
+
130
+ USER_CONNECTIONS = {
131
+ "data": {
132
+ "user_connections": [
133
+ {
134
+ "active": True,
135
+ "carrier_id": "ups_package",
136
+ "carrier_name": "ups",
137
+ "credentials": {
138
+ "account_number": "000000",
139
+ "client_id": "test",
140
+ "client_secret": "test",
141
+ },
142
+ "id": ANY,
143
+ "test_mode": False,
144
+ },
145
+ {
146
+ "active": True,
147
+ "carrier_id": "canadapost",
148
+ "carrier_name": "canadapost",
149
+ "credentials": {
150
+ "contract_id": "42708517",
151
+ "customer_number": "2004381",
152
+ "password": "0bfa9fcb9853d1f51ee57a",
153
+ "username": "6e93d53968881714",
154
+ },
155
+ "id": ANY,
156
+ "test_mode": False,
157
+ },
158
+ ]
159
+ }
160
+ }
161
+
162
+ CONNECTION_DATA = {
163
+ "data": {
164
+ "carrier_name": "sendle",
165
+ "carrier_id": "sendle",
166
+ "credentials": {
167
+ "sendle_id": "test_sendle_id",
168
+ "api_key": "test_api_key",
169
+ },
170
+ }
171
+ }
172
+
173
+ CONNECTION_RESPONSE = {
174
+ "data": {
175
+ "create_carrier_connection": {
176
+ "connection": {
177
+ "id": ANY,
178
+ "active": True,
179
+ "carrier_id": "sendle",
180
+ "carrier_name": "sendle",
181
+ "test_mode": False,
182
+ "credentials": {
183
+ "api_key": "test_api_key",
184
+ "sendle_id": "test_sendle_id",
185
+ "account_country_code": None,
186
+ },
187
+ }
188
+ }
189
+ }
190
+ }
191
+
192
+ CONNECTION_UPDATE_DATA = {
193
+ "data": {
194
+ "carrier_id": "canadapost_updated",
195
+ "credentials": {
196
+ "username": "6e93d53968881714_updated",
197
+ "customer_number": "2004381_updated",
198
+ "contract_id": "42708517_updated",
199
+ "password": "0bfa9fcb9853d1f51ee57a_updated",
200
+ },
201
+ }
202
+ }
203
+
204
+ CONNECTION_UPDATE_RESPONSE = {
205
+ "data": {
206
+ "update_carrier_connection": {
207
+ "connection": {
208
+ "carrier_id": "canadapost_updated",
209
+ "credentials": {
210
+ "account_country_code": "CA",
211
+ "contract_id": "42708517_updated",
212
+ "customer_number": "2004381_updated",
213
+ "password": "0bfa9fcb9853d1f51ee57a_updated",
214
+ "username": "6e93d53968881714_updated",
215
+ },
216
+ }
217
+ }
218
+ }
219
+ }