Skip to content

Commit

Permalink
Some pyflakes fixes.
Browse files Browse the repository at this point in the history
They were just bothering me far too much with vim+syntastic.
  • Loading branch information
Ian Cordasco committed Aug 2, 2012
1 parent 2b33bc2 commit c71f48b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -37,7 +37,7 @@ cipyflakes:
${PYFLAKES_IF_AVAILABLE} ${PYFLAKES_WHITELIST}

citests:
nosetests ${CI_TESTS} --with-xunit --xunit-file=junit-report.xml
nosetests ${CI_TESTS} -v --with-xunit --xunit-file=junit-report.xml

ci: citests cipyflakes

Expand Down
35 changes: 24 additions & 11 deletions tests/test_requests.py
Expand Up @@ -52,15 +52,18 @@ def setUp(self):
# time.sleep(1)
_httpbin = True


class TestBaseMixin(object):

def assertCookieHas(self, cookie, **kwargs):
"""Assert that a cookie has various specified properties."""
for attr, expected_value in kwargs.items():
cookie_attr = getattr(cookie, attr)
message = 'Failed comparison for %s: %s != %s' % (attr, cookie_attr, expected_value)
message = 'Failed comparison for %s: %s != %s' % (attr,
cookie_attr, expected_value)
self.assertEqual(cookie_attr, expected_value, message)


class RequestsTestSuite(TestSetup, TestBaseMixin, unittest.TestCase):
"""Requests test cases."""

Expand Down Expand Up @@ -121,7 +124,8 @@ def test_HTTP_200_OK_GET_WITH_PARAMS(self):
def test_HTTP_200_OK_GET_WITH_MIXED_PARAMS(self):
heads = {'User-agent': 'Mozilla/5.0'}

r = get(httpbin('get') + '?test=true', params={'q': 'test'}, headers=heads)
r = get(httpbin('get') + '?test=true', params={'q': 'test'},
headers=heads)
self.assertEqual(r.status_code, 200)

# def test_unicode_headers(self):
Expand Down Expand Up @@ -761,7 +765,8 @@ def test_session_persistent_cookies(self):
self.assertEqual(c, _c)

# Have the server set a cookie.
r = get(httpbin('cookies', 'set', 'k', 'v'), allow_redirects=True, session=s)
r = get(httpbin('cookies', 'set', 'k', 'v'), allow_redirects=True,
session=s)
c = json.loads(r.text).get('cookies')

assert 'k' in c
Expand Down Expand Up @@ -826,7 +831,8 @@ def test_session_pickling(self):

def test_unpickled_session_requests(self):
s = requests.session()
r = get(httpbin('cookies', 'set', 'k', 'v'), allow_redirects=True, session=s)
r = get(httpbin('cookies', 'set', 'k', 'v'), allow_redirects=True,
session=s)
c = json.loads(r.text).get('cookies')
assert 'k' in c

Expand Down Expand Up @@ -955,24 +961,31 @@ def test_danger_mode_redirects(self):
s.config['danger_mode'] = True
s.get(httpbin('redirect', '4'))


def test_empty_response(self):
r = requests.get(httpbin('status', '404'))
r.text

def test_max_redirects(self):
"""Test the max_redirects config variable, normally and under safe_mode."""
"""Test the max_redirects config variable, normally and under
safe_mode.
"""
def unsafe_callable():
requests.get(httpbin('redirect', '3'), config=dict(max_redirects=2))
self.assertRaises(requests.exceptions.TooManyRedirects, unsafe_callable)
requests.get(httpbin('redirect', '3'),
config=dict(max_redirects=2))
self.assertRaises(requests.exceptions.TooManyRedirects,
unsafe_callable)

# add safe mode
response = requests.get(httpbin('redirect', '3'), config=dict(safe_mode=True, max_redirects=2))
response = requests.get(httpbin('redirect', '3'),
config=dict(safe_mode=True, max_redirects=2))
self.assertTrue(response.content is None)
self.assertTrue(isinstance(response.error, requests.exceptions.TooManyRedirects))
self.assertTrue(isinstance(response.error,
requests.exceptions.TooManyRedirects))

def test_connection_keepalive_and_close(self):
"""Test that we send 'Connection: close' when keep_alive is disabled."""
"""Test that we send 'Connection: close' when keep_alive is
disabled.
"""
# keep-alive should be on by default
r1 = requests.get(httpbin('get'))
# XXX due to proxying issues, test the header sent back by httpbin, rather than
Expand Down

0 comments on commit c71f48b

Please sign in to comment.