Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cb7c83a

Browse files
committed
Added test for download_pdf unauthorized condition
1 parent 786d521 commit cb7c83a

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
Changelog
2-
========
2+
=========
33

4-
* 0.7.5 (May 11th, 2018)
4+
* 0.7.5 (October 18th, 2018)
55
* Fixed bug with reporting authentication failure when attempting to download PDF (previously the error details were "lost")
6+
* Added get_new_access_tokens to Oauth2SessionManager
7+
*
68

79
* 0.7.4 (March 26th, 2018)
810
* Fixed bug in SendMixin send method.

tests/unit/test_client.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from unittest.mock import patch
77

88
from quickbooks.auth import Oauth1SessionManager
9-
from quickbooks.exceptions import QuickbooksException, SevereException
9+
from quickbooks.exceptions import QuickbooksException, SevereException, AuthorizationException
1010
from quickbooks import client
1111
from 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

241252
class 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+
261286
class MockPdfResponse(object):
262287
@property
263288
def status_code(self):

0 commit comments

Comments
 (0)