Skip to content

Commit

Permalink
Fixed mock object for simplejson case
Browse files Browse the repository at this point in the history
  • Loading branch information
laf-rge committed May 23, 2024
1 parent 5afd3f5 commit 9de4c9e
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import simplejson as json
from tests.integration.test_base import QuickbooksUnitTestCase

try:
Expand Down Expand Up @@ -141,7 +142,7 @@ def test_get_single_object(self, make_req):

@patch('quickbooks.client.QuickBooks.process_request')
def test_make_request(self, process_request):
process_request.return_value = MockResponse()
process_request.return_value = MockResponseSimpleJson()

qb_client = client.QuickBooks()
qb_client.company_id = "1234"
Expand Down Expand Up @@ -220,7 +221,7 @@ def test_download_pdf_not_authorized(self, process_request):
@patch('quickbooks.client.QuickBooks.process_request')
def test_make_request_file_closed(self, process_request):
file_path = '/path/to/file.txt'
process_request.return_value = MockResponse()
process_request.return_value = MockResponseSimpleJson()
with patch('builtins.open', mock_open(read_data=b'file content')) as mock_file:
qb_client = client.QuickBooks(auth_client=self.auth_client)
qb_client.make_request('POST',
Expand Down Expand Up @@ -253,6 +254,18 @@ def json(self):
def content(self):
return ''

class MockResponseSimpleJson:
def __init__(self, json_data=None, status_code=200):
self.json_data = json_data or {}
self.status_code = status_code

@property
def text(self):
return json.dumps(self.json_data) # Ensure this uses simplejson if necessary

def json(self):
return self.json_data


class MockUnauthorizedResponse(object):
@property
Expand Down

0 comments on commit 9de4c9e

Please sign in to comment.