PyWebBrowser/tests/url_test.py

84 lines
1.8 KiB
Python

import pytest
from browser import URL
@pytest.mark.parametrize(
"url_string,scheme,host,port,path",
[
(
"http://example.com",
"http",
"example.com",
80,
"/",
),
(
"http://example.com/",
"http",
"example.com",
80,
"/",
),
(
"https://example.com/",
"https",
"example.com",
443,
"/",
),
(
"http://example.com:5000/",
"http",
"example.com",
5000,
"/",
),
(
"http://example.com:5000/test/example",
"http",
"example.com",
5000,
"/test/example",
),
(
"https://example.com:5000/test/example",
"https",
"example.com",
5000,
"/test/example",
),
],
)
def test_url_parsing(url_string, scheme, host, port, path):
url = URL(url_string)
assert url.scheme == scheme
assert url.host == host
assert url.port == port
assert url.path == path
@pytest.mark.parametrize(
"http_server,url_string",
[
(80, "http://127.0.0.1/"),
(5000, "http://127.0.0.1:5000/"),
],
indirect=["http_server"],
)
def test_http_request(http_server, url_string):
url = URL(url_string)
assert url.request() == "test"
@pytest.mark.parametrize(
"https_server,url_string",
[
(443, "https://127.0.0.1/"),
(5000, "https://127.0.0.1:5000/"),
],
indirect=["https_server"],
)
def test_https_request(https_server, url_string):
url = URL(url_string)
assert url.request() == "test"