Unit Tests for curl_from_request
Before adoption: this commit came in with the history the project adopted, so no landing records it.
#139
authored by Mike Waldner · committed by Mike Waldner · parent 58d63d5 · Browse files · 1 file·+48 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+48 added−0 removed
- other:+48 added−0 removed
Provenance
- Commit
e46351c- Tree
0c7b54e- Author
Mike Waldner <mwaldner@gilt.com>- Committer
Mike Waldner <mwaldner@gilt.com>- Parent
58d63d5
1 file changed+48 added−0 removed
modified:test_requests.py+48 added
12 unmodified lines13 14 import requests15 16 from requests.sessions import Session17+from requests.utils import curl_from_request18 19 20 HTTPBIN_URL = 'http://httpbin.org/'21 HTTPSBIN_URL = 'https://httpbin.ep.io/'448 unmodified lines470 assert heads['User-agent'] in r2.content471 self.assertEqual(r2.status_code, 200)472 473 474+ def test_curl_HTTP_OK_GET(self):475+ curl_str = 'curl -L -X GET -H "Accept-Encoding:gzip" -H "User-Agent:python-requests.org" "http://httpbin.org//"'476+ r = requests.get(httpbin('/'))477+ self.assertEqual(curl_from_request(r.request), curl_str)478 479+480+ def test_curl_HTTP_OK_GET_WITH_PARAMS(self):481+ curl_str = 'curl -L -X GET -H "Accept-Encoding:gzip" -H "User-agent:Mozilla/5.0" "http://httpbin.org/user-agent"'482+483+ heads = {'User-agent': 'Mozilla/5.0'}484+ r = requests.get(httpbin('user-agent'), headers=heads)485+ self.assertEqual(curl_from_request(r.request), curl_str)486+487+488+ def test_curl_HTTP_OK_HEAD(self):489+ curl_str ='curl -L -I -H "Accept-Encoding:gzip" -H "User-Agent:python-requests.org" "http://httpbin.org//"'490+ r = requests.head(httpbin('/'))491+ self.assertEqual(curl_from_request(r.request), curl_str)492+493+494+ def test_curl_HTTP_OK_PATCH(self):495+ curl_str = 'curl -L -X PATCH -H "Accept-Encoding:gzip" -H "User-Agent:python-requests.org" "http://httpbin.org/patch"'496+ r = requests.patch(httpbin('patch'))497+ self.assertEqual(curl_from_request(r.request), curl_str)498+499+500+ def test_curl_AUTH_HTTPS_OK_GET(self):501+ curl_str = 'curl -L -u "user:pass" -X GET -H "Accept-Encoding:gzip" -H "User-Agent:python-requests.org" "https://httpbin.ep.io/basic-auth/user/pass"'502+ auth = ('user', 'pass')503+ r = requests.get(httpsbin('basic-auth', 'user', 'pass'), auth=auth)504+ self.assertEqual(curl_from_request(r.request), curl_str)505+506+507+ def test_curl_POSTBIN_GET_POST_FILES(self):508+ curl_str = 'curl -L -X POST -H "Accept-Encoding:gzip" -H "User-Agent:python-requests.org" -d "some=data" "http://httpbin.org/post"' 509+ post = requests.post(httpbin('post'), data={'some': 'data'})510+ self.assertEqual(curl_from_request(post.request), curl_str)511+512+ curl_str = 'curl -L -X POST -H "Accept-Encoding:gzip" -H "User-Agent:python-requests.org" -F "some=@test_requests.py" "https://httpbin.ep.io/post"' 513+ post2 = requests.post(httpsbin('post'), files={'some': open('test_requests.py')})514+ self.assertEqual(curl_from_request(post2.request), curl_str)515+516+ #TODO - This doesn't seem right with \ \517+ #curl_str = 'curl -L -X POST -H "Accept-Encoding:gzip" -H "User-Agent:python-requests.org" -d \'[{"some": "json"}]\' "http://httpbin.org/post"' 518+ #post3 = requests.post(httpbin('post'), data='[{"some": "json"}]')519+ #self.assertEqual(curl_from_request(post3.request), curl_str)520+521+522 if __name__ == '__main__':523 unittest.main()