11import unittest
22from unittest .mock import ANY , patch
33
4+ from heron import error
45from heron .resources import Category , EndUser , Merchant , Transaction
56
67from .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