def test_single_quote_option():
    result = opa.compile('data.test.p == true', {}, ['q'], 'q', compile_func=opa.compile_command_line({
        'test.rego': '''package test

        p { data.q[x].a = "foo" }
        '''
    }))
    assert [c.sql(use_single_quotes=True) for c in result.sql.clauses] == ["WHERE ((q.a = 'foo'))"]
Beispiel #2
0
def query_opa(method, path, **kwargs):
    input = {
        'method': method,
        'path': path,
        'subject': make_subject(),
    }
    for key in kwargs:
        input[key] = kwargs[key]
    return opa.compile(q='data.example.allow = true',
                       input=input,
                       unknowns=['pets'])
def crunch(query, input, unknowns, from_table, policy, exp_defined, exp_sql):
    try:
        result = opa.compile(query, input, unknowns, from_table, compile_func=opa.compile_command_line({
            'test.rego': policy,
        }))
    except opa.TranslationError as e:
        if not isinstance(exp_defined, opa.TranslationError):
            raise
        assert str(exp_defined) in str(e)
    else:
        assert result.defined == exp_defined
        if result.defined:
            if exp_sql is None:
                assert result.sql is None
            else:
                assert [c.sql() for c in result.sql.clauses] == exp_sql
        else:
            assert result.sql is None
Beispiel #4
0
def crunch(query, input, unknowns, from_table, policy, exp_defined, exp_sql):
    clear_policies()
    put_policy(policy)
    try:
        result = opa.compile(query, input, unknowns, from_table)
    except opa.TranslationError as e:
        if not isinstance(exp_defined, opa.TranslationError):
            raise
        assert str(exp_defined) in str(e)
    else:
        assert result.defined == exp_defined
        if result.defined:
            if exp_sql is None:
                assert result.sql is None
            else:
                assert [c.sql() for c in result.sql.clauses] == exp_sql
        else:
            assert result.sql is None