Skip to content

Commit

Permalink
Correct manager usage in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Sep 30, 2023
1 parent ec6bdd1 commit 891a05d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/xero/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def __init__(self, name, credentials, unit_price_4dps=False, user_agent=None):
from xero import __version__ as VERSION # noqa

self.credentials = credentials
self.name = name.capitalize() if name.islower() else name
self.name = name
self.base_url = credentials.base_url + XERO_API_URL
self.extra_params = {"unitdp": 4} if unit_price_4dps else {}
self.singular = singular(name)
Expand Down
40 changes: 20 additions & 20 deletions tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class ManagerTest(unittest.TestCase):
def test_serializer(self):
credentials = Mock(base_url="")
manager = Manager("contacts", credentials)
manager = Manager("Invoice", credentials)

example_invoice_input = {
"Date": datetime.datetime(2015, 6, 6, 16, 25, 2, 711109),
Expand Down Expand Up @@ -79,7 +79,7 @@ def test_serializer(self):

def test_serializer_phones_addresses(self):
credentials = Mock(base_url="")
manager = Manager("contacts", credentials)
manager = Manager("Contacts", credentials)

example_contact_input = {
"ContactID": "565acaa9-e7f3-4fbf-80c3-16b081ddae10",
Expand Down Expand Up @@ -139,7 +139,7 @@ def test_serializer_phones_addresses(self):

def test_serializer_nested_singular(self):
credentials = Mock(base_url="")
manager = Manager("contacts", credentials)
manager = Manager("Invoice", credentials)

example_invoice_input = {
"Date": datetime.datetime(2015, 6, 6, 16, 25, 2, 711109),
Expand Down Expand Up @@ -173,7 +173,7 @@ def test_serializer_nested_singular(self):
def test_filter(self):
"""The filter function should correctly handle various arguments"""
credentials = Mock(base_url="")
manager = Manager("contacts", credentials)
manager = Manager("Contacts", credentials)

uri, params, method, body, headers, singleobject = manager._filter(
order="LastName",
Expand Down Expand Up @@ -202,7 +202,7 @@ def test_filter(self):
self.assertEqual(params, {})
self.assertIsNone(headers)

manager = Manager("invoices", credentials)
manager = Manager("Invoices", credentials)
uri, params, method, body, headers, singleobject = manager._filter(
**{"Contact.ContactID": "3e776c4b-ea9e-4bb1-96be-6b0c7a71a37f"}
)
Expand All @@ -223,7 +223,7 @@ def test_filter(self):
def test_filter_ids(self):
"""The filter function should correctly handle various arguments"""
credentials = Mock(base_url="")
manager = Manager("contacts", credentials)
manager = Manager("Contacts", credentials)

uri, params, method, body, headers, singleobject = manager._filter(
IDs=[
Expand All @@ -243,7 +243,7 @@ def test_filter_ids(self):
def test_rawfilter(self):
"""The filter function should correctly handle various arguments"""
credentials = Mock(base_url="")
manager = Manager("invoices", credentials)
manager = Manager("Invoices", credentials)
uri, params, method, body, headers, singleobject = manager._filter(
Status="VOIDED", raw='Name.ToLower()=="test contact"'
)
Expand All @@ -254,7 +254,7 @@ def test_rawfilter(self):
def test_boolean_filter(self):
"""The filter function should correctly handle various arguments"""
credentials = Mock(base_url="")
manager = Manager("invoices", credentials)
manager = Manager("Invoices", credentials)
uri, params, method, body, headers, singleobject = manager._filter(
CanApplyToRevenue=True
)
Expand All @@ -264,14 +264,14 @@ def test_magnitude_filters(self):
"""The filter function should correctlu handle date arguments and gt, lt operators"""
credentials = Mock(base_url="")

manager = Manager("invoices", credentials)
manager = Manager("Invoices", credentials)
uri, params, method, body, headers, singleobject = manager._filter(
**{"Date__gt": datetime.datetime(2007, 12, 6)}
)

self.assertEqual(params, {"where": "Date>DateTime(2007,12,6)"})

manager = Manager("invoices", credentials)
manager = Manager("Invoices", credentials)
uri, params, method, body, headers, singleobject = manager._filter(
**{"Date__lte": datetime.datetime(2007, 12, 6)}
)
Expand All @@ -284,25 +284,25 @@ def test_unit4dps(self):
credentials = Mock(base_url="")

# test 4dps is disabled by default
manager = Manager("contacts", credentials)
manager = Manager("Contacts", credentials)
uri, params, method, body, headers, singleobject = manager._filter()
self.assertEqual(params, {}, "test 4dps not enabled by default")

# test 4dps is enabled by default
manager = Manager("contacts", credentials, unit_price_4dps=True)
manager = Manager("Contacts", credentials, unit_price_4dps=True)
uri, params, method, body, headers, singleobject = manager._filter()
self.assertEqual(params, {"unitdp": 4}, "test 4dps can be enabled explicitly")

# test 4dps can be disable explicitly
manager = Manager("contacts", credentials, unit_price_4dps=False)
manager = Manager("Contacts", credentials, unit_price_4dps=False)
uri, params, method, body, headers, singleobject = manager._filter()
self.assertEqual(params, {}, "test 4dps can be disabled explicitly")

def test_get_params(self):
"""The 'get' methods should pass GET parameters if provided."""

credentials = Mock(base_url="")
manager = Manager("reports", credentials)
manager = Manager("Reports", credentials)

# test no parameters or headers sent by default
uri, params, method, body, headers, singleobject = manager._get("ProfitAndLoss")
Expand All @@ -319,7 +319,7 @@ def test_get_params(self):
self.assertEqual(params, passed_params, "test params can be set")

# test params respect, but can override, existing configuration
manager = Manager("reports", credentials, unit_price_4dps=True)
manager = Manager("Reports", credentials, unit_price_4dps=True)
uri, params, method, body, headers, singleobject = manager._get(
"ProfitAndLoss", params=passed_params
)
Expand All @@ -334,17 +334,17 @@ def test_user_agent_inheritance(self):

# Default used when no user_agent set on manager and credentials has nothing to offer.
credentials = Mock(base_url="", user_agent=None)
manager = Manager("reports", credentials)
manager = Manager("Reports", credentials)
self.assertTrue(manager.user_agent.startswith("pyxero/"))

# Taken from credentials when no user_agent set on manager.
credentials = Mock(base_url="", user_agent="MY_COMPANY-MY_CONSUMER_KEY")
manager = Manager("reports", credentials)
manager = Manager("Reports", credentials)
self.assertEqual(manager.user_agent, "MY_COMPANY-MY_CONSUMER_KEY")

# Manager's user_agent used when explicitly set.
credentials = Mock(base_url="", user_agent="MY_COMPANY-MY_CONSUMER_KEY")
manager = Manager("reports", credentials, user_agent="DemoCompany-1234567890")
manager = Manager("Reports", credentials, user_agent="DemoCompany-1234567890")
self.assertEqual(manager.user_agent, "DemoCompany-1234567890")

@patch("xero.basemanager.requests.post")
Expand All @@ -353,7 +353,7 @@ def test_request_content_type(self, request):

# Default used when no user_agent set on manager and credentials has nothing to offer.
credentials = Mock(base_url="", user_agent=None)
manager = Manager("reports", credentials)
manager = Manager("Reports", credentials)
try:
manager._get_data(lambda: ("_", {}, "post", {}, {}, True))()
except XeroExceptionUnknown:
Expand All @@ -367,7 +367,7 @@ def test_request_body_format(self):

# Default used when no user_agent set on manager and credentials has nothing to offer.
credentials = Mock(base_url="", user_agent=None)
manager = Manager("reports", credentials)
manager = Manager("Reports", credentials)

body = manager.save_or_put({"bing": "bong"})[3]

Expand Down

0 comments on commit 891a05d

Please sign in to comment.