diff --git a/tests/test_htmlpasrer.py b/tests/test_htmlpasrer.py new file mode 100644 index 0000000..76d0e8d --- /dev/null +++ b/tests/test_htmlpasrer.py @@ -0,0 +1,22 @@ +# MIT licensed +# Copyright (c) 2021 lilydjwg , et al. + +import pytest + +pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net] + +async def test_xpath_ok(get_version): + assert await get_version("unifiedremote", { + "source": "htmlparser", + "url": "http://httpbin.org/", + "xpath": '//pre[@class="version"]/text()', + }) != None + +async def test_xpath_missing_ok(get_version): + assert await get_version("unifiedremote", { + "source": "htmlparser", + "url": "http://httpbin.org/", + "xpath": '//pre[@class="test-is-ok"]/text()', + "missing_ok": True, + }) is None + \ No newline at end of file diff --git a/tests/test_httpheader.py b/tests/test_httpheader.py index ccff11b..4c38dd7 100644 --- a/tests/test_httpheader.py +++ b/tests/test_httpheader.py @@ -2,7 +2,8 @@ # Copyright (c) 2021 lilydjwg , et al. import pytest - +import pytest_httpbin +assert pytest_httpbin # for pyflakes pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net] async def test_redirection(get_version): @@ -12,3 +13,11 @@ async def test_redirection(get_version): "regex": r'urserver-([\d.]+).deb', }) != None +async def test_get_version_withtoken(get_version, httpbin): + assert await get_version("unifiedremote", { + "source": "httpheader", + "url": httpbin.url + "/basic-auth/username/superpassword", + "token": "Basic dXNlcm5hbWU6c3VwZXJwYXNzd29yZA==", + "header": "server", + "regex": r'([0-9.]+)*', + }) != None diff --git a/tests/test_regex.py b/tests/test_regex.py index 23737e9..2ef5c63 100644 --- a/tests/test_regex.py +++ b/tests/test_regex.py @@ -42,3 +42,20 @@ async def test_missing_ok(get_version, httpbin): "regex": "foobar", "missing_ok": True, }) is None + +async def test_regex_with_tokenBasic(get_version, httpbin): + assert await get_version("example", { + "source": "regex", + "url": httpbin.url + "/basic-auth/username/superpassword", + "token": "Basic dXNlcm5hbWU6c3VwZXJwYXNzd29yZA==", + "regex": r'"user":"([a-w]+)"', + }) == "username" + +async def test_regex_with_tokenBearer(get_version, httpbin): + assert await get_version("example", { + "source": "regex", + "url": httpbin.url + "/bearer", + "token": "Bearer username:password", + "regex": r'"token":"([a-w]+):.*"', + }) == "username" +