node-http-proxy/test/test_proxy.py

27 lines
943 B
Python
Raw Normal View History

import requests
import os
# TODO - Make this configurable based on config file test section.
http_proxy = "http://127.0.0.1:8124"
def test_proxy_basic():
2019-01-27 16:43:32 +00:00
resp = requests.get("http://httpbin.org", proxies={"http": http_proxy})
2019-01-26 18:17:00 +00:00
assert resp.status_code == 200
def test_proxy_block_page():
for i in range(2):
requests.get("http://httpbin.org", proxies={"http": http_proxy})
assert requests.get("http://httpbin.org", proxies={"http": http_proxy}).status_code == 403
2019-02-13 21:26:05 +00:00
# TODO - Use a sqlite driver here to check that httpbin.org is in the blocked table.
# Or mock the sqlite client.
2019-02-13 21:26:05 +00:00
def test_blocked_file():
"""
Tests that the host configured to be blocked is successfully blocked.
TODO - Mock the blocked file to be used by the proxy to not have to hardcode the host.
"""
2019-02-13 21:26:05 +00:00
resp = requests.get("http://wikipedia.org", proxies={"http": http_proxy})
assert resp.status_code == 403