Skip to content

Commit

Permalink
add req/res.reset() in EsiClient.request() to be able to reuse operat…
Browse files Browse the repository at this point in the history
…ions.

Also add pyswagger version requirement on 0.8.27+.
Update test and setup to match these changes.
  • Loading branch information
Kyria committed Feb 14, 2017
1 parent 34589e5 commit ccafdfd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion esipy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
pass


__version__ = '0.1.2'
__version__ = '0.1.3'
10 changes: 9 additions & 1 deletion esipy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,16 @@ def request(self, req_and_resp, raw_body_only=None, opt={}):
:return: the final response.
"""
# reset the request and response to reuse existing req_and_resp
base_request, base_response = req_and_resp
base_request.reset()
base_response.reset()

# required because of inheritance
request, response = super(EsiClient, self).request(req_and_resp, opt)
request, response = super(EsiClient, self).request(
(base_request, base_response),
opt
)

# check cache here so we have all headers, formed url and params
cache_key = self.__make_cache_key(request)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ mock
future
python-memcached
diskcache
pyswagger
pyswagger>=0.8.27
requests
six
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# install requirements
install_requirements = [
"requests",
"pyswagger",
"pyswagger >= 0.8.27",
"six",
"pytz",
]
Expand Down
10 changes: 10 additions & 0 deletions test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,13 @@ def test_client_raw_body_only(self):
raw_body_only=False
)
self.assertIsNotNone(incursions.data)

def test_esipy_reuse_operation(self):
operation = self.app.op['get_incursions']()
with httmock.HTTMock(public_incursion):
incursions = self.client_no_auth.request(operation)
self.assertEqual(incursions.data[0].faction_id, 500019)

# this shouldn't create any errors
incursions = self.client_no_auth.request(operation)
self.assertEqual(incursions.data[0].faction_id, 500019)

0 comments on commit ccafdfd

Please sign in to comment.