Ejemplo n.º 1
0
def test_parses_empty_rules():
    assert len(HttpRules(None)) == 2
    assert len(HttpRules("")) == 2
    assert len(HttpRules(" ")) == 2
    assert len(HttpRules("\t")) == 2
    assert len(HttpRules("\n")) == 2

    assert HttpRules.parse_rule(None) is None
    assert HttpRules.parse_rule("") is None
    assert HttpRules.parse_rule(" ") is None
    assert HttpRules.parse_rule("\t") is None
    assert HttpRules.parse_rule("\n") is None
Ejemplo n.º 2
0
def parse_ok(line, verb, scope, param1, param2):
    rule = HttpRules.parse_rule(line)
    assert rule.verb == verb

    if rule.scope is None:
        assert scope is None
    else:
        assert rule.scope.pattern == re.compile(scope).pattern

    if param1 is None:
        assert True
    elif hasattr(rule.param1, "match"):
        assert rule.param1.pattern == re.compile(param1).pattern
    else:
        assert rule.param1 == param1

    if param2 is None:
        assert True
    elif hasattr(rule.param2, "match"):
        assert rule.param2.pattern == re.compile(param2).pattern
    else:
        assert rule.param2 == param2
Ejemplo n.º 3
0
def parse_fail(line):
    try:
        HttpRules.parse_rule(line)
    except Exception:
        return
    assert False