Esempio n. 1
0
def test_(url, config, expected):
    http = HTTP(None)
    mw_cls = loader.get_class("urlsession")
    middleware = mw_cls(http, **config)
    # No session yet
    r_url, r_body, r_headers = middleware.process_request(url, {}, {})
    assert not r_body  # Should not be set
    assert not r_headers  # Should not be set
    assert r_url == url  # Should not be changed due to empty session
    # Set session as number
    session_id = 123
    http.set_session_id(session_id)
    r_url, r_body, r_headers = middleware.process_request(url, {}, {})
    assert not r_body  # Should not be set
    assert not r_headers  # Should not be set
    r_expected = expected.format(session_id)
    assert r_url == r_expected  # Should not be changed due to empty session
    # Set session as string
    session_id = "12345"
    http.set_session_id(session_id)
    r_url, r_body, r_headers = middleware.process_request(url, {}, {})
    assert not r_body  # Should not be set
    assert not r_headers  # Should not be set
    r_expected = expected.format(session_id)
    assert r_url == r_expected  # Should not be changed due to empty session
Esempio n. 2
0
def test_basicauth():
    http = HTTP(None)
    mw_cls = loader.get_class("basicauth")
    middleware = mw_cls(http, user="******", password="******")
    url = "http://127.0.0.1"
    r_url, r_body, r_headers = middleware.process_post(url, {}, {})
    assert not r_body  # Should not be set
    assert r_headers == {"Authorization": "Basic dXNlcjpwYXNzd29yZA=="}
    assert r_url == url  # Should not be changed
Esempio n. 3
0
def test_(url, config, expected):
    http = HTTP(None)
    mw_cls = loader.get_class("urlrequestid")
    middleware = mw_cls(http, **config)
    for _ in range(3):
        r_url, r_body, r_headers = middleware.process_request(url, {}, {})
        assert not r_body  # Should not be set
        assert not r_headers  # Should not be set
        r_expected = expected.format(http.request_id)
        assert r_url == r_expected  # Should not be changed due to empty request
        http.request_id += 1
Esempio n. 4
0
def test_jsonsession(body, config, request_id, expected):
    http = HTTP(None)
    http.request_id = request_id
    mw_cls = loader.get_class("jsonrequestid")
    middleware = mw_cls(http, **config)
    url = "http://127.0.0.1"
    # POST
    r_url, r_body, r_headers = middleware.process_post(url, body.copy(), {})
    assert r_body == expected
    assert not r_headers  # Should not be set
    assert r_url == url  # Should not be changed
    # PUT
    r_url, r_body, r_headers = middleware.process_put(url, body.copy(), {})
    assert r_body == expected
    assert not r_headers  # Should not be set
    assert r_url == url  # Should not be changed
Esempio n. 5
0
def test_loader(name):
    t = loader.get_class(name)
    assert t is not None
    assert t.name == name
    assert issubclass(t, BaseMiddleware)