forked from csernazs/pytest-httpserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_proxy.py
More file actions
24 lines (17 loc) · 908 Bytes
/
test_proxy.py
File metadata and controls
24 lines (17 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import requests
from pytest_httpserver import HTTPProxy
def test_proxy_http(httpproxy: HTTPProxy):
httpproxy.expect_request("/proxy/http://example.com/path/file.html").respond_with_data("Hello world!")
with requests.Session() as session:
session.proxies = {"http": httpproxy.get_proxy_url()}
resp = session.get("http://example.com/path/file.html", )
assert resp.status_code == 200
assert resp.text == "Hello world!"
def test_proxy_https(httpproxy: HTTPProxy):
httpproxy.expect_request("/proxy/https://example.com/path/file.html").respond_with_data("Hello world!")
with requests.Session() as session:
session.verify = httpproxy.ca_cert
session.proxies = {"https": httpproxy.get_proxy_url()}
resp = session.get("https://example.com/path/file.html")
assert resp.status_code == 200
assert resp.text == "Hello world!"