def test_subapp_rule_resource(app): subapp = web.Application() subapp.router.add_get('/', make_handler()) rule = Domain('example.com') assert rule.get_info() == {'domain': 'example.com'} resource = app.add_domain('example.com', subapp) assert resource.canonical == 'example.com' assert resource.get_info() == {'rule': resource._rule, 'app': subapp} resource.add_prefix('/a') resource.raw_match('/b') assert len(resource) assert list(resource) assert repr(resource).startswith('<MatchedSubAppResource') with pytest.raises(RuntimeError): resource.url_for()
def test_subapp_rule_resource(app: Any) -> None: subapp = web.Application() subapp.router.add_get("/", make_handler()) rule = Domain("example.com") assert rule.get_info() == {"domain": "example.com"} resource = app.add_domain("example.com", subapp) assert resource.canonical == "example.com" assert resource.get_info() == {"rule": resource._rule, "app": subapp} resource.add_prefix("/a") resource.raw_match("/b") assert len(resource) assert list(resource) assert repr(resource).startswith("<MatchedSubAppResource") with pytest.raises(RuntimeError): resource.url_for()
def test_subapp_rule_resource(app): subapp = web.Application() subapp.router.add_get('/', make_handler()) rule = Domain('example.com') assert rule.get_info() == {'domain': 'example.com'} resource = app.add_domain('example.com', subapp) assert resource.canonical == 'example.com' assert resource.get_info() == {'rule': resource._rule, 'app': subapp} resource.add_prefix('/a') resource.raw_match('/b') assert len(resource) assert list(resource) assert repr(resource).startswith('<MatchedSubAppResource') with pytest.raises(RuntimeError): resource.url_for()
def test_match_domain(a: Any, b: Any, result: Any) -> None: if "*" in a: rule = MaskDomain(a) else: rule = Domain(a) assert rule.match_domain(b) is result
def test_domain_valid() -> None: assert Domain("example.com:81").canonical == "example.com:81" assert MaskDomain("*.example.com").canonical == r".*\.example\.com" assert Domain("пуни.код").canonical == "xn--h1ajfq.xn--d1alm"
def test_domain_validation_error(domain: Any, error: Any) -> None: with pytest.raises(error): Domain(domain)
def test_match_domain(a, b, result): if '*' in a: rule = MaskDomain(a) else: rule = Domain(a) assert rule.match_domain(b) is result
def test_domain_valid(): assert Domain('example.com:81').canonical == 'example.com:81' assert MaskDomain('*.example.com').canonical == r'.*\.example\.com' assert Domain('пуни.код').canonical == 'xn--h1ajfq.xn--d1alm'
def test_domain_validation_error(domain, error): with pytest.raises(error): Domain(domain)