Skip to content

Commit

Permalink
Merge pull request #76 from vintasoftware/status
Browse files Browse the repository at this point in the history
Adding status_code method to executor
  • Loading branch information
filipeximenes committed Nov 8, 2015
2 parents a035e1a + 7928928 commit e689acb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 24 deletions.
3 changes: 3 additions & 0 deletions tapioca/tapioca.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ def response(self):
raise Exception("This instance has no response object")
return self._response

def status_code(self):
return self.response().status_code

def _make_request(self, request_method, *args, **kwargs):
if 'url' not in kwargs:
kwargs['url'] = self._data
Expand Down
62 changes: 38 additions & 24 deletions tests/test_tapioca.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,44 @@ def test_dir_call_returns_executor_methods(self):
self.assertIn('open_docs', e_dir)
self.assertIn('open_in_browser', e_dir)

@responses.activate
def test_response_executor_object_has_a_response(self):
next_url = 'http://api.teste.com/next_batch'

responses.add(responses.GET, self.wrapper.test().data(),
body='{"data": [{"key": "value"}], "paging": {"next": "%s"}}' % next_url,
status=200,
content_type='application/json')

responses.add(responses.GET, next_url,
body='{"data": [{"key": "value"}], "paging": {"next": ""}}',
status=200,
content_type='application/json')

response = self.wrapper.test().get()
executor = response()

executor.response()

executor._response = None

def test_raises_error_if_executor_does_not_have_a_response_object(self):
client = self.wrapper

with self.assertRaises(Exception):
client().response()

@responses.activate
def test_response_executor_has_a_status_code(self):
responses.add(responses.GET, self.wrapper.test().data(),
body='{"data": {"key": "value"}}',
status=200,
content_type='application/json')

response = self.wrapper.test().get()

self.assertEqual(response().status_code(), 200)


class TestTapiocaExecutorRequests(unittest.TestCase):

Expand Down Expand Up @@ -355,27 +393,3 @@ def test_simple_pages_max_item_zero_iterator(self):
for item in response().pages(max_items=0):
self.assertIn(item.key().data(), 'value')
iterations_count += 1

@responses.activate
def test_response_executor_object_has_a_response(self):
next_url = 'http://api.teste.com/next_batch'

responses.add(responses.GET, self.wrapper.test().data(),
body='{"data": [{"key": "value"}], "paging": {"next": "%s"}}' % next_url,
status=200,
content_type='application/json')

responses.add(responses.GET, next_url,
body='{"data": [{"key": "value"}], "paging": {"next": ""}}',
status=200,
content_type='application/json')

response = self.wrapper.test().get()
executor = response()

executor.response()

executor._response = None

with self.assertRaises(Exception):
executor.response()

0 comments on commit e689acb

Please sign in to comment.