66 from unittest .mock import patch
77
88from quickbooks .auth import Oauth1SessionManager
9- from quickbooks .exceptions import QuickbooksException , SevereException
9+ from quickbooks .exceptions import QuickbooksException , SevereException , AuthorizationException
1010from quickbooks import client
1111from quickbooks .objects .salesreceipt import SalesReceipt
1212
@@ -237,6 +237,17 @@ def test_download_nonexistent_pdf(self):
237237 receipt .Id = 666
238238 self .assertRaises (QuickbooksException , receipt .download_pdf )
239239
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+
240251
241252class MockResponse (object ):
242253 @property
@@ -258,6 +269,20 @@ def content(self):
258269 return ''
259270
260271
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+
261286class MockPdfResponse (object ):
262287 @property
263288 def status_code (self ):
0 commit comments