update: add new tests

This commit is contained in:
Maud LAURENT 2021-05-07 15:41:41 +02:00
parent 588d824077
commit 23fd48c281
3 changed files with 49 additions and 1 deletions

22
tests/test_htmlpasrer.py Normal file
View file

@ -0,0 +1,22 @@
# MIT licensed
# Copyright (c) 2021 lilydjwg <lilydjwg@gmail.com>, 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

View file

@ -2,7 +2,8 @@
# Copyright (c) 2021 lilydjwg <lilydjwg@gmail.com>, 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

View file

@ -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"