From: Vikram Oberoi Date: Thu, 27 Jun 2013 21:16:42 +0000 (-0400) Subject: Add test to verify .netrc authentication behavior. X-Git-Tag: 2.0~22^2~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d9c49ad30d1107591f3b5150da6f95ec90c63784;p=services%2Fpython-requests.git Add test to verify .netrc authentication behavior. Here's what should happen: - If no credentials are given, use netrc if there's a netrc entry. - If credentials are given, they should override netrc. --- diff --git a/test_requests.py b/test_requests.py index 7ad10ee..0758210 100755 --- a/test_requests.py +++ b/test_requests.py @@ -234,6 +234,34 @@ class RequestsTestCase(unittest.TestCase): r = s.get(url) self.assertEqual(r.status_code, 200) + def test_basicauth_with_netrc(self): + auth = ('user', 'pass') + wrong_auth = ('wronguser', 'wrongpass') + url = httpbin('basic-auth', 'user', 'pass') + + def get_netrc_auth_mock(url): + return auth + requests.sessions.get_netrc_auth = get_netrc_auth_mock + + # Should use netrc and work. + r = requests.get(url) + self.assertEqual(r.status_code, 200) + + # Given auth should override and fail. + r = requests.get(url, auth=wrong_auth) + self.assertEqual(r.status_code, 401) + + s = requests.session() + + # Should use netrc and work. + r = s.get(url) + self.assertEqual(r.status_code, 200) + + # Given auth should override and fail. + s.auth = wrong_auth + r = s.get(url) + self.assertEqual(r.status_code, 401) + def test_DIGEST_HTTP_200_OK_GET(self): auth = HTTPDigestAuth('user', 'pass')