Skip to content

Commit 4e2fe17

Browse files
committed
Refactor test suite to improve unit test coverage and mocking
- Update unit tests for PaymentsApi, SubscriptionsApi, PaymentMethodsApi, ApplePayDomainApi, and BizumApi - Add comprehensive mock responses and error handling tests - Remove deprecated integration test files - Standardize test structure and improve test method coverage - Enhance error handling and response validation in unit tests
1 parent a49159d commit 4e2fe17

14 files changed

+1409
-1142
lines changed

test/conftest.py

Lines changed: 0 additions & 77 deletions
This file was deleted.

test/test_api_client_integration.py

Lines changed: 0 additions & 160 deletions
This file was deleted.

test/test_apple_pay_domain_api.py

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,71 @@
1313

1414

1515
import unittest
16+
from unittest.mock import patch, MagicMock
1617

1718
from Monei.api.apple_pay_domain_api import ApplePayDomainApi
19+
from Monei.api_client import ApiClient
20+
from Monei.configuration import Configuration
21+
from Monei.exceptions import ApiException
1822

1923

2024
class TestApplePayDomainApi(unittest.TestCase):
2125
"""ApplePayDomainApi unit test stubs"""
2226

2327
def setUp(self) -> None:
24-
self.api = ApplePayDomainApi()
28+
configuration = Configuration()
29+
configuration.api_key = {"Authorization": "test_api_key"}
30+
self.api_client = ApiClient(configuration)
31+
self.api = ApplePayDomainApi(self.api_client)
2532

2633
def tearDown(self) -> None:
2734
pass
2835

29-
def test_register(self) -> None:
36+
@patch.object(ApiClient, "call_api")
37+
def test_register(self, mock_call_api) -> None:
3038
"""Test case for register
3139
32-
Register Domain
40+
Register Apple Pay Domain
3341
"""
34-
pass
42+
# Configure the mock to return a successful response
43+
mock_response = {
44+
"success": True
45+
}
46+
mock_call_api.return_value = mock_response
47+
48+
# Test the method
49+
domain_data = {
50+
"domainName": "example.com"
51+
}
52+
response = self.api.register(domain_data)
53+
54+
# Verify the response
55+
self.assertEqual(response, mock_response)
56+
mock_call_api.assert_called_once()
57+
58+
@patch.object(ApiClient, "call_api")
59+
def test_error_handling(self, mock_call_api) -> None:
60+
"""Test error handling in API calls"""
61+
# Configure the mock to raise an ApiException
62+
mock_call_api.side_effect = ApiException(
63+
status=400,
64+
reason="Bad Request",
65+
body='{"status":"ERROR","statusCode":400,"requestId":"req_123","message":"Invalid domain name"}'
66+
)
67+
68+
# Test the method
69+
domain_data = {
70+
"domainName": "invalid-domain"
71+
}
72+
73+
# Verify that the exception is raised
74+
with self.assertRaises(ApiException) as context:
75+
self.api.register(domain_data)
76+
77+
# Verify the exception details
78+
self.assertEqual(context.exception.status, 400)
79+
self.assertEqual(context.exception.reason, "Bad Request")
80+
self.assertIn("Invalid domain name", context.exception.body)
3581

3682

3783
if __name__ == '__main__':

test/test_apple_pay_domain_api_integration.py

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)