6
6
from unittest .mock import patch
7
7
8
8
from quickbooks .auth import Oauth1SessionManager
9
- from quickbooks .exceptions import QuickbooksException , SevereException
9
+ from quickbooks .exceptions import QuickbooksException , SevereException , AuthorizationException
10
10
from quickbooks import client
11
11
from quickbooks .objects .salesreceipt import SalesReceipt
12
12
@@ -237,6 +237,17 @@ def test_download_nonexistent_pdf(self):
237
237
receipt .Id = 666
238
238
self .assertRaises (QuickbooksException , receipt .download_pdf )
239
239
240
+ @patch ('quickbooks.client.QuickBooks.process_request' )
241
+ def test_download_pdf_not_authorized (self , process_request ):
242
+ qb_client = client .QuickBooks (sandbox = True )
243
+ qb_client .company_id = "1234"
244
+ receipt = SalesReceipt ()
245
+ receipt .Id = 1
246
+
247
+ process_request .return_value = MockUnauthorizedResponse ()
248
+
249
+ self .assertRaises (AuthorizationException , receipt .download_pdf , qb_client )
250
+
240
251
241
252
class MockResponse (object ):
242
253
@property
@@ -258,6 +269,20 @@ def content(self):
258
269
return ''
259
270
260
271
272
+ class MockUnauthorizedResponse (object ):
273
+ @property
274
+ def text (self ):
275
+ return "UNAUTHORIZED"
276
+
277
+ @property
278
+ def status_code (self ):
279
+ try :
280
+ import httplib # python 2
281
+ except ImportError :
282
+ import http .client as httplib # python 3
283
+ return httplib .UNAUTHORIZED
284
+
285
+
261
286
class MockPdfResponse (object ):
262
287
@property
263
288
def status_code (self ):
0 commit comments