Skip to content

Commit

Permalink
closing resources is good
Browse files Browse the repository at this point in the history
  • Loading branch information
andli committed Dec 16, 2020
1 parent 1f7df12 commit dbd0f1b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pymkm/pymkmapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def mkm_request(self, mkm_oauth, url, params=None):
# redirect to the given request URI, because a new Authorization
# header needs to be compiled for the redirected resource. (MKM API docs)
self.__handle_response(r)
mkm_oauth.close()
return r
except CardmarketError as err:
self.logger.error(f"{err.mkm_msg()} {url}")
Expand Down Expand Up @@ -360,6 +361,7 @@ def set_vacation_status(self, vacation_status=False, provided_oauth=None):

self.logger.debug(">> Setting vacation status to: " + str(vacation_status))
r = mkm_oauth.put(url, params={"onVacation": str(vacation_status).lower()})
mkm_oauth.close()
# cancelOrders
# relistItems

Expand All @@ -373,6 +375,7 @@ def set_display_language(self, display_language=1, provided_oauth=None):

self.logger.debug(">> Setting display language to: " + str(display_language))
r = mkm_oauth.put(url, params={"idDisplayLanguage": display_language})
mkm_oauth.close()

if self.__handle_response(r):
return r.json()
Expand Down Expand Up @@ -410,6 +413,7 @@ def add_stock(self, payload=None, provided_oauth=None):
data=xml_payload,
timeout=self.config["cardmarket_request_timeout"],
)
mkm_oauth.close()
inserted = r.json()
if "error" in inserted:
raise CardmarketError(inserted["error"])
Expand Down Expand Up @@ -468,6 +472,7 @@ def set_stock(self, payload=None, provided_oauth=None):
r = mkm_oauth.put(
url, data=xml_payload, timeout=self.config["cardmarket_request_timeout"]
)
mkm_oauth.close()
try:
json_response = r.json()
if len(json_response["updatedArticles"]) > 0:
Expand Down
4 changes: 2 additions & 2 deletions test/local_test_pymkm_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TestPyMkmApp(LocalTestCommon):
@patch("sys.stdout", new_callable=io.StringIO)
@patch("builtins.input", side_effect=["0"])
def test_app_starts(self, mock_input, mock_stdout, *args):
self.assertEquals(True, True)
self.assertEqual(True, True)
app = PyMkmApp()
app.start(self.parsed_args)
self.assertRegex(mock_stdout.getvalue(), r"╭─── PyMKM")
Expand All @@ -26,7 +26,7 @@ def test_app_starts(self, mock_input, mock_stdout, *args):
@patch("builtins.input", side_effect=["backupstock", "y", "restorestock", "y", "0"])
# TODO: instead of patching, trigger each depending on the stdout
def test_stock_update(self, mock_input, mock_stdout, *args):
self.assertEquals(True, True)
self.assertEqual(True, True)
app = PyMkmApp()
app.start(self.parsed_args)
out = mock_stdout.getvalue()
Expand Down

0 comments on commit dbd0f1b

Please sign in to comment.