Skip to content
This repository was archived by the owner on Jul 21, 2025. It is now read-only.

Commit a0a5f3f

Browse files
committed
push test coverage to 90%+
1 parent c6d0349 commit a0a5f3f

2 files changed

Lines changed: 36 additions & 20 deletions

File tree

test/test_end_user.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ def test_create(self):
2525
end_user = EndUser.create(**self.end_user_dict)
2626

2727
self.assertIsInstance(end_user, EndUser)
28-
self.assertIsNone(
29-
mock_post.assert_called_once_with(
30-
ANY, headers=ANY, json=self.request_payload, auth=ANY
31-
)
28+
mock_post.assert_called_once_with(
29+
ANY, headers=ANY, json=self.request_payload, auth=ANY
3230
)
3331

3432
def test_update(self):
@@ -39,16 +37,14 @@ def test_update(self):
3937
end_user = EndUser.update(**self.end_user_dict, status=new_status)
4038

4139
self.assertIsInstance(end_user, EndUser)
42-
self.assertIsNone(
43-
mock_post.assert_called_once_with(
44-
ANY,
45-
headers=ANY,
46-
json={
47-
"end_user": {
48-
**self.end_user_dict,
49-
"status": new_status,
50-
},
40+
mock_post.assert_called_once_with(
41+
ANY,
42+
headers=ANY,
43+
json={
44+
"end_user": {
45+
**self.end_user_dict,
46+
"status": new_status,
5147
},
52-
auth=ANY,
53-
)
48+
},
49+
auth=ANY,
5450
)

test/test_transaction.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
22
from unittest.mock import ANY, patch
33

4+
from heron import error
45
from heron.resources import Category, EndUser, Merchant, Transaction
56

67
from .mocks import MockResponse
@@ -171,6 +172,11 @@ def setUp(self):
171172
self.response_payload = {
172173
"transactions": [{**self.transaction_dict, **self.enrichments}] * 3
173174
}
175+
self.validation_error_payload = {
176+
"code": 422,
177+
"name": "Unprocessable Entity",
178+
"description": {},
179+
}
174180

175181
def test_list(self):
176182
with patch("requests.get") as mock_get:
@@ -183,8 +189,22 @@ def test_list(self):
183189
self.assertIsInstance(transaction.categories[0], Category)
184190
self.assertIsInstance(transaction.merchant, Merchant)
185191
self.assertIsInstance(transaction.payment_processor, Merchant)
186-
self.assertIsNone(
187-
mock_get.assert_called_once_with(
188-
ANY, headers=ANY, json=None, auth=ANY
189-
)
190-
)
192+
mock_get.assert_called_once_with(ANY, headers=ANY, json=None, auth=ANY)
193+
194+
def test_validation_error(self):
195+
with patch("requests.get") as mock_get:
196+
mock_get.return_value = MockResponse(self.validation_error_payload, 422)
197+
198+
with self.assertRaises(error.HeronValidationError):
199+
transactions = Transaction.list()
200+
self.assertIsNone(transactions)
201+
mock_get.assert_called_once_with(ANY, headers=ANY, json=None, auth=ANY)
202+
203+
def test_internal_server_error(self):
204+
with patch("requests.get") as mock_get:
205+
mock_get.return_value = MockResponse({}, 500)
206+
207+
with self.assertRaises(error.HeronError):
208+
transactions = Transaction.list()
209+
self.assertIsNone(transactions)
210+
mock_get.assert_called_once_with(ANY, headers=ANY, json=None, auth=ANY)

0 commit comments

Comments
 (0)