示例#1
0
from s_class import S


def access_require(S_rule, token_scopes):
    def christmas_deco(func):
        def wrapper(*args, **kwargs):
            if S_rule.validate(token_scopes):
                return func(*args, **kwargs)
            return "Get out of this you sneaky dwarf !"
        return wrapper
    return christmas_deco


super_token_scopes = ["AtLeastaMurloc", "Peon"]

@access_require(S("AtLeastaMurloc") & S("Peon"), super_token_scopes)
def superfunction(a, b):
    """ My super function """
    return a + b


if __name__ == "__main__":
    print(superfunction(1, 2))
示例#2
0
def test_2_and_ko():
    token_scopes = ["a", "b", "c"]
    s_a, s_b, s_d = S("a"), S("b"), S("d")
    s_comb = s_a & s_b & s_d
    logger.debug(s_comb.history)
    assert s_comb.validate(token_scopes) == False
示例#3
0
def test_or_and_ok():
    token_scopes = ["a", "b", "c"]
    s_a, s_b, s_c = S("a"), S("b"), S("c")
    s_comb = (s_a | s_b) & s_c
    logger.debug(s_comb.history)
    assert s_comb.validate(token_scopes) == True
示例#4
0
def test_2_or_ko():
    token_scopes = ["d"]
    s_a, s_b, s_c = S("a"), S("b"), S("c")
    s_comb = s_a | s_b | s_c
    logger.debug(s_comb.history)
    assert s_comb.validate(token_scopes) == False
示例#5
0
def test_1_and_ok():
    token_scopes = ["a", "b"]
    s_a, s_b = S("a"), S("b")
    s_comb = s_a & s_b
    logger.debug(s_comb.history)
    assert s_comb.validate(token_scopes) == True
示例#6
0
def test_set_from_list_or_string_list():
    assert type(S.set_from_list_or_string(["abc", "bcd"])) is set
    assert len(S.set_from_list_or_string(["abc", "bcd"])) == 2
示例#7
0
def test_set_from_list_raises():
    with pytest.raises(TypeError):
        S.set_from_list_or_string(("not supported tuple", ))
示例#8
0
def test_list_and_or_and_ko():
    token_scopes = ["a", "b", "c"]
    s_az, s_c, s_b, s_z = S(["a", "z"]), S("c"), S("b"), S("z")
    s_comb = (s_az & s_c) | (s_b & s_z)
    logger.debug(s_comb.history)
    assert s_comb.validate(token_scopes) == False
示例#9
0
def test_set_from_list_or_string_str():
    assert type(S.set_from_list_or_string("abc")) is set
    assert len(S.set_from_list_or_string("abc")) == 1
示例#10
0
def test_and_or_and_ok_and2():
    token_scopes = ["a", "b", "c"]
    s_a, s_c, s_b, s_z = S("a"), S("c"), S("b"), S("z")
    s_comb = (s_a & s_z) | (s_b & s_c)
    logger.debug(s_comb.history)
    assert s_comb.validate(token_scopes) == True
示例#11
0
def test_and_or_ko():
    token_scopes = ["a", "b", "c"]
    s_a, s_q, s_z = S("a"), S("q"), S("z")
    s_comb = (s_a & s_q) | s_z
    logger.debug(s_comb.history)
    assert s_comb.validate(token_scopes) == False
示例#12
0
def test_and_or_ok_or():
    token_scopes = ["a", "b", "c"]
    s_a, s_q, s_c = S("a"), S("q"), S("c")
    s_comb = (s_a & s_q) | s_c
    logger.debug(s_comb.history)
    assert s_comb.validate(token_scopes) == True
示例#13
0
def test_or_and_ko_and():
    token_scopes = ["a", "b", "c"]
    s_a, s_d, s_f = S("a"), S("d"), S("f")
    s_comb = (s_a | s_d) & s_f
    logger.debug(s_comb.history)
    assert s_comb.validate(token_scopes) == False
示例#14
0
def test_or_and_ko_or():
    token_scopes = ["a", "b", "c"]
    s_d, s_f, s_c = S("d"), S("f"), S("c")
    s_comb = (s_d | s_f) & s_c
    logger.debug(s_comb.history)
    assert s_comb.validate(token_scopes) == False