Skip to content

Commit

Permalink
better mocked response
Browse files Browse the repository at this point in the history
  • Loading branch information
Timbo committed Nov 3, 2023
1 parent e620cc6 commit 2064690
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions tests/test_filesmanager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os.path
import unittest
from time import time
from unittest.mock import patch
from unittest.mock import Mock, patch

from xero import Xero
from xero.auth import OAuth2Credentials
Expand Down Expand Up @@ -32,8 +32,10 @@ def test_tenant_is_used_in_xero_request(self, r_get):
"client_id", "client_secret", token=self.expired_token, tenant_id="12345"
)
xero = Xero(credentials)
# Just return any old response
r_get.return_value = None
r_get.return_value = Mock(
status_code=200,
headers={"content-type": "text/html; charset=utf-8"},
)
xero.filesAPI.files.all()

self.assertEqual(r_get.call_args[1]["headers"]["Xero-tenant-id"], "12345")
Expand All @@ -44,7 +46,10 @@ def test_upload_file_as_path(self, r_get):
"client_id", "client_secret", token=self.expired_token, tenant_id="12345"
)
xero = Xero(credentials)
r_get.return_value = None
r_get.return_value = Mock(
status_code=200,
headers={"content-type": "text/html; charset=utf-8"},
)
xero.filesAPI.files.upload_file(path=self.filepath)

self.assertIn(self.filepath, r_get.call_args[1]["files"])
Expand All @@ -55,7 +60,10 @@ def test_upload_file_as_file(self, r_get):
"client_id", "client_secret", token=self.expired_token, tenant_id="12345"
)
xero = Xero(credentials)
r_get.return_value = None
r_get.return_value = Mock(
status_code=200,
headers={"content-type": "text/html; charset=utf-8"},
)

with open(self.filepath) as f:
xero.filesAPI.files.upload_file(
Expand Down

0 comments on commit 2064690

Please sign in to comment.