Skip to content

Commit 956e751

Browse files
committed
fix: update tests and mock responses for API endpoint changes
- Fix store module response parsing with robust structure handling - Update mock responses to match actual API response format - Fix integration test auth module references - 202/214 tests now passing (94.4% pass rate) - Remaining failures are integration tests with real API calls
1 parent 3bd2d89 commit 956e751

6 files changed

Lines changed: 31 additions & 17 deletions

File tree

pathao/modules/store.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ def create(
6363
response = self.http_client.post("aladdin/api/v1/stores", headers, data)
6464

6565
# Parse response
66-
store_data = response["data"]["data"]
66+
if "data" in response and "data" in response["data"]:
67+
store_data = response["data"]["data"]
68+
elif "data" in response:
69+
store_data = response["data"]
70+
else:
71+
store_data = response
72+
6773
return Store(
6874
store_id=store_data["store_id"],
6975
store_name=store_data["store_name"],
@@ -137,7 +143,13 @@ def get(self, store_id: int) -> Store:
137143
)
138144

139145
# Parse response
140-
store_data = response["data"]
146+
if "data" in response and "data" in response["data"]:
147+
store_data = response["data"]["data"]
148+
elif "data" in response:
149+
store_data = response["data"]
150+
else:
151+
store_data = response
152+
141153
return Store(
142154
store_id=store_data["store_id"],
143155
store_name=store_data["store_name"],

tests/fixtures/mock_responses.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
"type": "success",
2626
"data": {
2727
"store_id": 123,
28-
"name": "Test Store",
29-
"contact_name": "John Doe",
30-
"contact_number": "01712345678",
31-
"address": "123 Test Street, Dhaka",
32-
"secondary_contact": "01987654321",
28+
"store_name": "Test Store",
29+
"store_address": "123 Test Street, Dhaka",
30+
"is_active": 1,
31+
"city_id": 1,
32+
"zone_id": 1,
3333
"hub_id": 1,
34+
"is_default_store": False,
35+
"is_default_return_store": False,
3436
},
3537
}
3638

@@ -72,12 +74,11 @@
7274
"type": "success",
7375
"data": {
7476
"consignment_id": "D-12345",
77+
"merchant_order_id": "TEST-001",
7578
"order_status": "Pending",
76-
"item_description": "Test Item",
77-
"amount_to_collect": 100.0,
78-
"recipient_name": "Jane Doe",
79-
"recipient_phone": "01712345678",
80-
"recipient_address": "456 Test Road, Dhaka",
79+
"delivery_fee": 60.0,
80+
"created_at": "2023-01-01T10:00:00Z",
81+
"updated_at": "2023-01-01T10:00:00Z",
8182
},
8283
}
8384

tests/test_integration_sandbox.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ def test_credential_management(self):
309309
env_client = PathaoClient(environment="sandbox")
310310

311311
# Verify credentials were loaded from environment
312-
assert env_client.auth.credentials["client_id"] == "env_client_id"
313-
assert env_client.auth.credentials["username"] == "env@example.com"
312+
assert env_client.auth_module.credentials["client_id"] == "env_client_id"
313+
assert env_client.auth_module.credentials["username"] == "env@example.com"
314314

315315
finally:
316316
# Clean up environment variables

tests/test_location.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_get_cities_success(
5959

6060
mock_auth_module.get_access_token.assert_called_once()
6161
mock_http_client.get.assert_called_once_with(
62-
"aladdin/api/v1/cities", {"Authorization": "Bearer test_token"}
62+
"aladdin/api/v1/city-list", {"Authorization": "Bearer test_token"}
6363
)
6464

6565
def test_get_zones_success(

tests/test_order.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ def test_get_info_success(self, order_module, mock_http_client, mock_auth_module
272272
# Verify API call
273273
mock_auth_module.get_access_token.assert_called_once()
274274
mock_http_client.get.assert_called_once_with(
275-
"aladdin/api/v1/orders/CON123456", {"Authorization": "Bearer test_token"}
275+
"aladdin/api/v1/orders/CON123456/info",
276+
{"Authorization": "Bearer test_token"},
276277
)
277278

278279
def test_get_info_validation_error(self, order_module):

tests/test_price.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_calculate_success(self, price_module, mock_http_client, mock_auth_modul
6767

6868
mock_auth_module.get_access_token.assert_called_once()
6969
mock_http_client.post.assert_called_once_with(
70-
"aladdin/api/v1/price-plan",
70+
"aladdin/api/v1/merchant/price-plan",
7171
{"Authorization": "Bearer test_token"},
7272
{
7373
"store_id": 1,

0 commit comments

Comments
 (0)