r = get(httpbin('user-agent'), headers=heads)
- assert heads['User-agent'] in r.text
+ self.assertTrue(heads['User-agent'] in r.text)
self.assertEqual(r.status_code, 200)
def test_HTTP_200_OK_GET_WITH_MIXED_PARAMS(self):
response = get(url)
- assert isinstance(response.url, str)
+ self.assertTrue(isinstance(response.url, str))
def test_unicode_get(self):
# Body wasn't valid url encoded data, so the server returns None as
# "form" and the raw body as "data".
- assert rbody.get('form') in (None, {})
+ self.assertTrue(rbody.get('form') in (None, {}))
self.assertEqual(rbody.get('data'), 'fooaowpeuf')
def test_file_post_data(self):
self.assertEqual(r.url, service('post'))
rbody = json.loads(r.text)
- assert rbody.get('form') in (None, {})
+ self.assertTrue(rbody.get('form') in (None, {}))
self.assertEqual(rbody.get('data'), filecontent.decode('ascii'))
os.remove(testfile.name)
rbody = json.loads(r.text)
- assert rbody.get('form') in (None, {})
+ self.assertTrue(rbody.get('form') in (None, {}))
self.assertEqual(rbody.get('data'), 'foobar')
def test_urlencoded_get_query_multivalued_param(self):
# Make 2 requests from Session object, should send header both times
r1 = get(httpbin('user-agent'), session=s)
- assert heads['User-agent'] in r1.text
+ self.assertTrue(heads['User-agent'] in r1.text)
r2 = get(httpbin('user-agent'), session=s)
- assert heads['User-agent'] in r2.text
+ self.assertTrue(heads['User-agent'] in r2.text)
new_heads = {'User-agent': 'blah'}
r3 = get(httpbin('user-agent'), headers=new_heads, session=s)
- assert new_heads['User-agent'] in r3.text
+ self.assertTrue(new_heads['User-agent'] in r3.text)
self.assertEqual(r2.status_code, 200)
url = service('headers')
response = get(url=url, hooks={'args': add_foo_header})
- assert 'foo' in response.text
+ self.assertTrue('foo' in response.text)
def test_multiple_hooks(self):
}
)
- assert 'foo' in response.text
- assert 'bar' in response.text
+ for text in ('foo', 'bar'):
+ self.assertTrue(text in response.text)
def test_allow_list_of_hooks_to_register_hook(self):
"""Issue 785: https://github.com/kennethreitz/requests/issues/785"""
def assert_hooks_are_callable(hooks):
for h in hooks['args']:
- assert callable(h) is True
+ self.assertTrue(callable(h))
hooks = [add_foo_header, add_bar_header]
r = requests.models.Request()
r = get(httpbin('cookies', 'set', 'k', 'v'), allow_redirects=True, session=s)
c = json.loads(r.text).get('cookies')
- assert 'k' in c
+ self.assertTrue('k' in c)
# And server-set cookie persistience.
r = get(httpbin('cookies'), session=s)
c = json.loads(r.text).get('cookies')
- assert 'k' in c
+ self.assertTrue('k' in c)
def test_session_persistent_params(self):
# Make 2 requests from Session object, should send header both times
r1 = get(httpbin('get'), session=s)
- assert params['a'] in r1.text
+ self.assertTrue(params['a'] in r1.text)
params2 = {'b': 'b_test'}
r2 = get(httpbin('get'), params=params2, session=s)
- assert params['a'] in r2.text
- assert params2['b'] in r2.text
+ for param in (params['a'], params2['b']):
+ self.assertTrue(param in r2.text)
params3 = {'b': 'b_test', 'a': None, 'c': 'c_test'}
r3 = get(httpbin('get'), params=params3, session=s)
- assert not params['a'] in r3.text
- assert params3['b'] in r3.text
- assert params3['c'] in r3.text
+ self.assertFalse(params['a'] in r3.text)
+
+ for param in (params3['b'], params3['c']):
+ self.assertTrue(param in r3.text)
def test_session_cookies_with_return_response_false(self):
s = requests.session()
allow_redirects=True, session=s)
rq.send(prefetch=True)
c = rq.response.json.get('cookies')
- assert 'k' in c
- assert 'k' in s.cookies
+ self.assertTrue('k' in c)
+ self.assertTrue('k' in s.cookies)
def test_session_pickling(self):
s = requests.session()
r = get(httpbin('cookies', 'set', 'k', 'v'), allow_redirects=True, session=s)
c = json.loads(r.text).get('cookies')
- assert 'k' in c
+ self.assertTrue('k' in c)
ds = pickle.loads(pickle.dumps(s))
r = get(httpbin('cookies'), session=ds)
c = json.loads(r.text).get('cookies')
- assert 'k' in c
+ self.assertTrue('k' in c)
ds1 = pickle.loads(pickle.dumps(requests.session()))
ds2 = pickle.loads(pickle.dumps(requests.session(prefetch=False)))
- assert ds1.prefetch
- assert not ds2.prefetch
+ self.assertTrue(ds1.prefetch)
+ self.assertFalse(ds2.prefetch)
def test_connection_error(self):
try:
except requests.ConnectionError:
pass
else:
- assert False
+ self.fail()
def test_connection_error_with_safe_mode(self):
config = {'safe_mode': True}
r = get('http://localhost:1/nope', allow_redirects=False, config=config)
- assert r.content is None
+ self.assertTrue(r.content is None)
# def test_invalid_content(self):
# # WARNING: if you're using a terrible DNS provider (comcast),
def test_cached_response(self):
r1 = get(httpbin('get'), prefetch=False)
- assert not r1._content
- assert r1.content
- assert r1.text
+ self.assertFalse(r1._content)
+ self.assertTrue(r1.content)
+ self.assertTrue(r1.text)
r2 = get(httpbin('get'), prefetch=True)
- assert r2._content
- assert r2.content
- assert r2.text
+ self.assertTrue(r2._content)
+ self.assertTrue(r2.content)
+ self.assertTrue(r2.text)
def test_iter_lines(self):
def test_permissive_iter_content(self):
"""Test that iter_content and iter_lines work even after the body has been fetched."""
r = get(httpbin('stream', '10'), prefetch=True)
- assert r._content_consumed
+ self.assertTrue(r._content_consumed)
# iter_lines should still work without crashing
self.assertEqual(len(list(r.iter_lines())), 10)