def setUp(self): app = WSGITestHandler( extra_headers=[("Set-Cookie", "c1=v1; Path=/"), ("Set-Cookie", "c2=v2; Path=/")]) self.session = requests.session() self.session.mount('http://localhost', WSGIAdapter(app=app)) self.session.mount('https://localhost', WSGIAdapter(app=app))
def setUp(self): self.session = requests.session() adapter = WSGIAdapter(app=WSGITestHandler()) self.session.mount('http://localhost', adapter) self.session.mount('http://localhost:5000', adapter) self.session.mount('https://localhost', adapter) self.session.mount('https://localhost:5443', adapter)
def test_delete_cookies(): session = requests.session() set_app = WSGITestHandler(extra_headers=[( "Set-Cookie", "flimble=floop; Path=/"), ("Set-Cookie", "flamble=flaap; Path=/")]) delete_app = WSGITestHandler(extra_headers=[( "Set-Cookie", "flimble=; Expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/")]) session.mount('http://localhost/cookies/set', WSGIAdapter(app=set_app)) session.mount('http://localhost/cookies/delete', WSGIAdapter(app=delete_app)) session.get("http://localhost/cookies/set?flimble=floop&flamble=flaap") assert session.cookies['flimble'] == "floop" assert session.cookies['flamble'] == "flaap" session.get("http://localhost/cookies/delete?flimble") assert 'flimble' not in session.cookies assert session.cookies['flamble'] == "flaap"
def test_multiple_cookies(): app = WSGITestHandler(extra_headers=[( "Set-Cookie", "flimble=floop; Path=/"), ("Set-Cookie", "flamble=flaap; Path=/")]) session = requests.session() session.mount('http://localhost', WSGIAdapter(app=app)) session.get("http://localhost/cookies/set?flimble=floop&flamble=flaap") assert session.cookies['flimble'] == "floop" assert session.cookies['flamble'] == "flaap"
def test_multiple_cookies(self): app = WSGITestHandler(extra_headers=[ ("Set-Cookie", "flimble=floop; Path=/"), ("Set-Cookie", "flamble=flaap; Path=/"), ]) session = requests.session() session.mount("http://localhost", WSGIAdapter(app=app)) session.get("http://localhost/cookies/set?flimble=floop&flamble=flaap") self.assertEqual(session.cookies["flimble"], "floop") self.assertEqual(session.cookies["flamble"], "flaap")
def test_delete_cookies(self): session = requests.session() set_app = WSGITestHandler(extra_headers=[ ("Set-Cookie", "flimble=floop; Path=/"), ("Set-Cookie", "flamble=flaap; Path=/"), ]) delete_app = WSGITestHandler(extra_headers=[( "Set-Cookie", "flimble=; Expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/", )]) session.mount("http://localhost/cookies/set", WSGIAdapter(app=set_app)) session.mount("http://localhost/cookies/delete", WSGIAdapter(app=delete_app)) session.get("http://localhost/cookies/set?flimble=floop&flamble=flaap") self.assertEqual(session.cookies["flimble"], "floop") self.assertEqual(session.cookies["flamble"], "flaap") session.get("http://localhost/cookies/delete?flimble") self.assertNotIn("flimble", session.cookies) self.assertEqual(session.cookies["flamble"], "flaap")
def get_session(): session = Session() session.mount(base_url, WSGIAdapter(app=httpbin.app)) return session
def test_session(self, base_url='http://testserver'): """Test environment""" session = Session() session.mount(prefix=base_url, adapter=WSGIAdapter(self)) return session
import requests from wsgiadapter import WSGIAdapter from app import api s = requests.Session() s.mount("http://staging/", WSGIAdapter(api)) r = s.get("http://staging/") print(r)
def setUp(self): self.session = requests.session() self.session.mount('http://localhost', WSGIAdapter(app=WSGITestHandler())) self.session.mount('https://localhost', WSGIAdapter(app=WSGITestHandler()))