requests returns content as bytes so use bytes for test strings. Also changed api verison in test 1.1 to not confuse people

This commit is contained in:
Cash Costello 2014-01-14 11:14:14 -05:00
parent 9f7d38181e
commit c83304edf2

View file

@ -52,10 +52,10 @@ class TwythonAPITestCase(unittest.TestCase):
@responses.activate @responses.activate
def test_request_should_handle_relative_endpoint(self): def test_request_should_handle_relative_endpoint(self):
"""Test that request() accepts a twitter endpoint name for the endpoint argument""" """Test that request() accepts a twitter endpoint name for the endpoint argument"""
url = 'https://api.twitter.com/2.0/search/tweets.json' url = 'https://api.twitter.com/1.1/search/tweets.json'
self.register_response(responses.GET, url) self.register_response(responses.GET, url)
self.api.request('search/tweets', version='2.0') self.api.request('search/tweets', version='1.1')
self.assertEqual(1, len(responses.calls)) self.assertEqual(1, len(responses.calls))
self.assertEqual(url, responses.calls[0].request.url) self.assertEqual(url, responses.calls[0].request.url)
@ -151,11 +151,8 @@ class TwythonAPITestCase(unittest.TestCase):
mock_file = StringIO("Twython test image") mock_file = StringIO("Twython test image")
self.api.request(endpoint, method='POST', params={'image': mock_file}) self.api.request(endpoint, method='POST', params={'image': mock_file})
if not is_py2: self.assertIn(b'filename="image"', responses.calls[0].request.body)
responses.calls[0].request.body = responses.calls[0].request.body.decode("utf-8") self.assertIn(b"Twython test image", responses.calls[0].request.body)
self.assertIn('filename="image"', responses.calls[0].request.body)
self.assertIn("Twython test image", responses.calls[0].request.body)
@responses.activate @responses.activate
def test_request_should_put_params_in_body_when_post(self): def test_request_should_put_params_in_body_when_post(self):
@ -166,10 +163,7 @@ class TwythonAPITestCase(unittest.TestCase):
self.api.request(endpoint, method='POST', params={'status': 'this is a test'}) self.api.request(endpoint, method='POST', params={'status': 'this is a test'})
if not is_py2: self.assertIn(b'status=this+is+a+test', responses.calls[0].request.body)
responses.calls[0].request.body = responses.calls[0].request.body.decode("utf-8")
self.assertIn('status=this+is+a+test', responses.calls[0].request.body)
self.assertNotIn('status=this+is+a+test', responses.calls[0].request.url) self.assertNotIn('status=this+is+a+test', responses.calls[0].request.url)
@responses.activate @responses.activate