nvchecker/tests-old/test_regex.py

41 lines
1.2 KiB
Python
Raw Normal View History

2017-02-28 07:24:53 +00:00
# MIT licensed
2019-07-08 03:40:08 +00:00
# Copyright (c) 2013-2019 lilydjwg <lilydjwg@gmail.com>, et al.
2017-02-28 07:24:53 +00:00
import base64
2017-07-04 09:04:29 +00:00
import pytest
import pytest_httpbin
assert pytest_httpbin # for pyflakes
2017-07-04 09:04:29 +00:00
pytestmark = pytest.mark.asyncio
2015-11-04 15:43:35 +00:00
def base64_encode(s):
return base64.b64encode(s.encode('utf-8')).decode('ascii')
async def test_regex_httpbin_default_user_agent(get_version, httpbin):
2019-07-08 03:40:08 +00:00
ua = await get_version("example", {
"url": httpbin.url + "/get",
"regex": r'"User-Agent":\s*"([^"]+)"',
2019-07-08 03:40:08 +00:00
})
assert ua.startswith("lilydjwg/nvchecker")
async def test_regex_httpbin_user_agent(get_version, httpbin):
2017-07-04 09:04:29 +00:00
assert await get_version("example", {
"url": httpbin.url + "/get",
"regex": r'"User-Agent":\s*"(\w+)"',
2017-07-04 09:04:29 +00:00
"user_agent": "Meow",
}) == "Meow"
async def test_regex(get_version, httpbin):
assert await get_version("example", {
"url": httpbin.url + "/base64/" + base64_encode("version 1.12 released"),
"regex": r'version ([0-9.]+)',
}) == "1.12"
async def test_missing_ok(get_version, httpbin):
assert await get_version("example", {
"url": httpbin.url + "/base64/" + base64_encode("something not there"),
"regex": "foobar",
"missing_ok": True,
}) is None