karrio-server-proxy 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.
File without changes
@@ -0,0 +1,3 @@
1
+ from django.contrib import admin
2
+
3
+ # Register your models here.
@@ -0,0 +1,5 @@
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class ProxyConfig(AppConfig):
5
+ name = 'karrio.server.proxy'
File without changes
@@ -0,0 +1,3 @@
1
+ from django.db import models
2
+
3
+ # Create your models here.
@@ -0,0 +1,3 @@
1
+ from rest_framework.routers import DefaultRouter
2
+
3
+ router = DefaultRouter(trailing_slash=False)
@@ -0,0 +1,8 @@
1
+ import logging
2
+
3
+ logging.disable(logging.CRITICAL)
4
+
5
+ from karrio.server.proxy.tests.test_rating import *
6
+ from karrio.server.proxy.tests.test_shipping import *
7
+ from karrio.server.proxy.tests.test_tracking import *
8
+ from karrio.server.proxy.tests.test_pickup import *
@@ -0,0 +1,293 @@
1
+ import json
2
+ from unittest.mock import patch, ANY
3
+ from django.urls import reverse
4
+ from rest_framework import status
5
+ from karrio.core.models import PickupDetails, ConfirmationDetails, ChargeDetails
6
+ from karrio.server.core.tests import APITestCase
7
+
8
+
9
+ class TesPickup(APITestCase):
10
+ def test_schedule_pickup(self):
11
+ url = reverse(
12
+ "karrio.server.proxy:pickup-schedule",
13
+ kwargs=dict(carrier_name="canadapost"),
14
+ )
15
+
16
+ with patch("karrio.server.core.gateway.utils.identity") as mock:
17
+ mock.return_value = SCHEDULE_RETURNED_VALUE
18
+ response = self.client.post(f"{url}", PICKUP_DATA)
19
+ response_data = json.loads(response.content)
20
+
21
+ self.assertEqual(response.status_code, status.HTTP_201_CREATED)
22
+ self.assertDictEqual(response_data, PICKUP_RESPONSE)
23
+
24
+ def test_udpate_pickup(self):
25
+ url = reverse(
26
+ "karrio.server.proxy:pickup-details",
27
+ kwargs=dict(carrier_name="canadapost"),
28
+ )
29
+
30
+ with patch("karrio.server.core.gateway.utils.identity") as mock:
31
+ mock.return_value = UPDATE_RETURNED_VALUE
32
+ response = self.client.post(f"{url}", PICKUP_UPDATE_DATA)
33
+ response_data = json.loads(response.content)
34
+
35
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
36
+ self.assertDictEqual(response_data, PICKUP_UPDATE_RESPONSE)
37
+
38
+ def test_cancel_pickup(self):
39
+ url = reverse(
40
+ "karrio.server.proxy:pickup-cancel",
41
+ kwargs=dict(carrier_name="canadapost"),
42
+ )
43
+
44
+ with patch("karrio.server.core.gateway.utils.identity") as mock:
45
+ mock.return_value = CANCEL_RETURNED_VALUE
46
+ response = self.client.post(f"{url}", PICKUP_CANCEL_DATA)
47
+ response_data = json.loads(response.content)
48
+
49
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
50
+ self.assertDictEqual(response_data, PICKUP_CANCEL_RESPONSE)
51
+
52
+
53
+ PICKUP_DATA = {
54
+ "pickup_date": "2020-10-25",
55
+ "address": {
56
+ "address_line1": "125 Church St",
57
+ "person_name": "John Doe",
58
+ "company_name": "A corp.",
59
+ "phone_number": "514 000 0000",
60
+ "city": "Moncton",
61
+ "country_code": "CA",
62
+ "postal_code": "E1C4Z8",
63
+ "residential": False,
64
+ "state_code": "NB",
65
+ "email": "john@a.com",
66
+ "validate_location": False,
67
+ "validation": None,
68
+ },
69
+ "parcels": [
70
+ {
71
+ "weight": 0.2,
72
+ "width": 10,
73
+ "height": 10,
74
+ "length": 1,
75
+ "packaging_type": "envelope",
76
+ "is_document": True,
77
+ "weight_unit": "KG",
78
+ "dimension_unit": "CM",
79
+ }
80
+ ],
81
+ "ready_time": "13:00",
82
+ "closing_time": "17:00",
83
+ "instruction": "Should not be folded",
84
+ "package_location": "At the main entrance hall",
85
+ }
86
+
87
+ PICKUP_UPDATE_DATA = {
88
+ "pickup_date": "2020-10-23",
89
+ "confirmation_number": "27241",
90
+ "address": {
91
+ "address_line1": "125 Church St",
92
+ "person_name": "John Doe",
93
+ "company_name": "A corp.",
94
+ "phone_number": "514 000 0000",
95
+ "city": "Moncton",
96
+ "country_code": "CA",
97
+ "postal_code": "E1C4Z8",
98
+ "residential": False,
99
+ "state_code": "NB",
100
+ "email": "john@a.com",
101
+ "validate_location": False,
102
+ "validation": None,
103
+ },
104
+ "parcels": [
105
+ {
106
+ "weight": 0.2,
107
+ "width": 10,
108
+ "height": 10,
109
+ "length": 1,
110
+ "packaging_type": "envelope",
111
+ "is_document": True,
112
+ "weight_unit": "KG",
113
+ "dimension_unit": "CM",
114
+ }
115
+ ],
116
+ "ready_time": "14:30",
117
+ "closing_time": "17:00",
118
+ "instruction": "Should not be folded",
119
+ "package_location": "At the main entrance hall",
120
+ }
121
+
122
+ PICKUP_CANCEL_DATA = {"confirmation_number": "00110215"}
123
+
124
+
125
+ SCHEDULE_RETURNED_VALUE = (
126
+ PickupDetails(
127
+ carrier_id="canadapost",
128
+ carrier_name="canadapost",
129
+ confirmation_number="27241",
130
+ pickup_date="2020-10-25",
131
+ pickup_charge=ChargeDetails(name="Pickup fees", amount=0.0, currency="CAD"),
132
+ ready_time="13:00",
133
+ closing_time="17:00",
134
+ ),
135
+ [],
136
+ )
137
+
138
+ UPDATE_RETURNED_VALUE = (
139
+ PickupDetails(
140
+ carrier_id="canadapost",
141
+ carrier_name="canadapost",
142
+ confirmation_number="27241",
143
+ pickup_date="2020-10-23",
144
+ ready_time="14:30",
145
+ closing_time="17:00",
146
+ ),
147
+ [],
148
+ )
149
+
150
+ CANCEL_RETURNED_VALUE = (
151
+ ConfirmationDetails(
152
+ carrier_id="canadapost",
153
+ carrier_name="canadapost",
154
+ operation="Cancel Pickup",
155
+ success=True,
156
+ ),
157
+ [],
158
+ )
159
+
160
+
161
+ PICKUP_RESPONSE = {
162
+ "messages": [],
163
+ "pickup": {
164
+ "id": ANY,
165
+ "object_type": "pickup",
166
+ "carrier_name": "canadapost",
167
+ "carrier_id": "canadapost",
168
+ "confirmation_number": "27241",
169
+ "pickup_date": "2020-10-25",
170
+ "pickup_charge": {"name": "Pickup fees", "amount": 0.0, "currency": "CAD"},
171
+ "ready_time": "13:00",
172
+ "closing_time": "17:00",
173
+ "test_mode": True,
174
+ "address": {
175
+ "id": None,
176
+ "object_type": "address",
177
+ "postal_code": "E1C4Z8",
178
+ "city": "Moncton",
179
+ "federal_tax_id": None,
180
+ "state_tax_id": None,
181
+ "person_name": "John Doe",
182
+ "company_name": "A corp.",
183
+ "country_code": "CA",
184
+ "email": "john@a.com",
185
+ "phone_number": "+1 514-000-0000",
186
+ "state_code": "NB",
187
+ "street_number": None,
188
+ "residential": False,
189
+ "address_line1": "125 Church St",
190
+ "address_line2": "",
191
+ "validate_location": False,
192
+ "validation": None,
193
+ },
194
+ "parcels": [
195
+ {
196
+ "id": None,
197
+ "object_type": "parcel",
198
+ "weight": 0.2,
199
+ "width": 10.0,
200
+ "height": 10.0,
201
+ "length": 1.0,
202
+ "packaging_type": "envelope",
203
+ "package_preset": None,
204
+ "description": None,
205
+ "content": None,
206
+ "is_document": True,
207
+ "items": [],
208
+ "weight_unit": "KG",
209
+ "dimension_unit": "CM",
210
+ "freight_class": None,
211
+ "reference_number": None,
212
+ "options": {},
213
+ }
214
+ ],
215
+ "instruction": "Should not be folded",
216
+ "package_location": "At the main entrance hall",
217
+ "options": {},
218
+ "metadata": {},
219
+ "meta": {"ext": "canadapost"},
220
+ },
221
+ }
222
+
223
+ PICKUP_UPDATE_RESPONSE = {
224
+ "messages": [],
225
+ "pickup": {
226
+ "id": None,
227
+ "object_type": "pickup",
228
+ "carrier_name": "canadapost",
229
+ "carrier_id": "canadapost",
230
+ "confirmation_number": "27241",
231
+ "pickup_date": "2020-10-23",
232
+ "pickup_charge": None,
233
+ "ready_time": "14:30",
234
+ "closing_time": "17:00",
235
+ "test_mode": True,
236
+ "address": {
237
+ "id": None,
238
+ "object_type": "address",
239
+ "postal_code": "E1C4Z8",
240
+ "city": "Moncton",
241
+ "federal_tax_id": None,
242
+ "state_tax_id": None,
243
+ "person_name": "John Doe",
244
+ "company_name": "A corp.",
245
+ "country_code": "CA",
246
+ "email": "john@a.com",
247
+ "phone_number": "+1 514-000-0000",
248
+ "state_code": "NB",
249
+ "street_number": None,
250
+ "residential": False,
251
+ "address_line1": "125 Church St",
252
+ "address_line2": "",
253
+ "validate_location": False,
254
+ "validation": None,
255
+ },
256
+ "parcels": [
257
+ {
258
+ "id": None,
259
+ "object_type": "parcel",
260
+ "weight": 0.2,
261
+ "width": 10.0,
262
+ "height": 10.0,
263
+ "length": 1.0,
264
+ "packaging_type": "envelope",
265
+ "package_preset": None,
266
+ "description": None,
267
+ "content": None,
268
+ "is_document": True,
269
+ "items": [],
270
+ "weight_unit": "KG",
271
+ "dimension_unit": "CM",
272
+ "freight_class": None,
273
+ "reference_number": None,
274
+ "options": {},
275
+ }
276
+ ],
277
+ "instruction": "Should not be folded",
278
+ "package_location": "At the main entrance hall",
279
+ "options": {},
280
+ "metadata": {},
281
+ "meta": {},
282
+ },
283
+ }
284
+
285
+ PICKUP_CANCEL_RESPONSE = {
286
+ "messages": [],
287
+ "confirmation": {
288
+ "carrier_id": "canadapost",
289
+ "carrier_name": "canadapost",
290
+ "operation": "Cancel Pickup",
291
+ "success": True,
292
+ },
293
+ }
@@ -0,0 +1,100 @@
1
+ import json
2
+ from unittest.mock import patch, ANY
3
+ from django.urls import reverse
4
+ from rest_framework import status
5
+ from karrio.core.models import RateDetails, ChargeDetails
6
+ from karrio.server.core.tests import APITestCase
7
+
8
+
9
+ class TestRating(APITestCase):
10
+ def test_fetch_shipment_rates(self):
11
+ url = reverse("karrio.server.proxy:shipment-rates")
12
+ data = RATING_DATA
13
+
14
+ with patch("karrio.server.core.gateway.utils.identity") as mock:
15
+ mock.return_value = RETURNED_VALUE
16
+ response = self.client.post(f"{url}", data)
17
+ response_data = json.loads(response.content)
18
+
19
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
20
+ self.assertDictEqual(response_data, RATING_RESPONSE)
21
+
22
+
23
+ RATING_DATA = {
24
+ "shipper": {
25
+ "postal_code": "V6M2V9",
26
+ "city": "Vancouver",
27
+ "country_code": "CA",
28
+ "state_code": "BC",
29
+ "residential": True,
30
+ "address_line1": "5840 Oak St",
31
+ },
32
+ "recipient": {
33
+ "postal_code": "E1C4Z8",
34
+ "city": "Moncton",
35
+ "country_code": "CA",
36
+ "state_code": "NB",
37
+ "residential": False,
38
+ "address_line1": "125 Church St",
39
+ },
40
+ "parcels": [
41
+ {
42
+ "weight": 1,
43
+ "weight_unit": "KG",
44
+ "package_preset": "canadapost_corrugated_small_box",
45
+ }
46
+ ],
47
+ "services": ["canadapost_priority"],
48
+ "carrier_ids": ["canadapost"],
49
+ }
50
+
51
+ RETURNED_VALUE = (
52
+ [
53
+ RateDetails(
54
+ carrier_id="canadapost",
55
+ carrier_name="canadapost",
56
+ currency="CAD",
57
+ transit_days=2,
58
+ service="canadapost_priority",
59
+ total_charge=106.71,
60
+ extra_charges=[
61
+ ChargeDetails(amount=101.83, currency="CAD", name="Base charge"),
62
+ ChargeDetails(amount=2.7, currency="CAD", name="Fuel surcharge"),
63
+ ChargeDetails(amount=-11.74, currency="CAD", name="SMB Savings"),
64
+ ChargeDetails(amount=-9.04, currency="CAD", name="Discount"),
65
+ ],
66
+ )
67
+ ],
68
+ [],
69
+ )
70
+
71
+ RATING_RESPONSE = {
72
+ "messages": [],
73
+ "rates": [
74
+ {
75
+ "id": ANY,
76
+ "object_type": "rate",
77
+ "carrier_name": "canadapost",
78
+ "carrier_id": "canadapost",
79
+ "currency": "CAD",
80
+ "estimated_delivery": ANY,
81
+ "service": "canadapost_priority",
82
+ "total_charge": 106.71,
83
+ "transit_days": 2,
84
+ "extra_charges": [
85
+ {"name": "Base charge", "amount": 101.83, "currency": "CAD"},
86
+ {"name": "Fuel surcharge", "amount": 2.7, "currency": "CAD"},
87
+ {"name": "SMB Savings", "amount": -11.74, "currency": "CAD"},
88
+ {"name": "Discount", "amount": -9.04, "currency": "CAD"},
89
+ ],
90
+ "meta": {
91
+ "ext": "canadapost",
92
+ "carrier": "canadapost",
93
+ "rate_provider": "canadapost",
94
+ "service_name": "CANADAPOST PRIORITY",
95
+ "carrier_connection_id": ANY,
96
+ },
97
+ "test_mode": True,
98
+ }
99
+ ],
100
+ }