示例#1
0
 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))
示例#2
0
 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)
示例#3
0
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"
示例#4
0
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"
示例#5
0
    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")
示例#6
0
    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")
示例#7
0
def get_session():
    session = Session()
    session.mount(base_url, WSGIAdapter(app=httpbin.app))
    return session
示例#8
0
文件: api.py 项目: m3xan1k/tiny_web
 def test_session(self, base_url='http://testserver'):
     """Test environment"""
     session = Session()
     session.mount(prefix=base_url, adapter=WSGIAdapter(self))
     return session
示例#9
0
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)
示例#10
0
 def setUp(self):
     self.session = requests.session()
     self.session.mount('http://localhost', WSGIAdapter(app=WSGITestHandler()))
     self.session.mount('https://localhost', WSGIAdapter(app=WSGITestHandler()))