How to use the pypuppetdb.QueryBuilder.FromOperator function in pypuppetdb

To help you get started, we’ve selected a few pypuppetdb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github voxpupuli / pypuppetdb / tests / test_querybuilder.py View on Github external
def test_limit_offset(self):
        fr = FromOperator("facts")
        op = EqualsOperator("certname", "test01")
        fr.add_query(op)

        fr.add_offset(10)
        assert str(fr) == \
            '["from", "facts", ["=", "certname", "test01"], ["offset", 10]]'

        fr.add_limit(5)
        assert str(fr) == \
            '["from", "facts", ["=", "certname",' \
            ' "test01"], ["limit", 5], ["offset", 10]]'

        fr.add_limit(15)
        assert str(fr) == \
            '["from", "facts", ["=", "certname",' \
            ' "test01"], ["limit", 15], ["offset", 10]]'
github voxpupuli / pypuppetdb / tests / test_querybuilder.py View on Github external
def test_fromoperator(self):
        op = InOperator('certname')
        ex = ExtractOperator()
        ex.add_field(["certname", "facts"])
        fr = FromOperator("facts")
        fr.add_query(ex)
        fr.add_offset(10)
        op.add_query(fr)

        assert repr(op) == 'Query: ["in", "certname", ' \
            '["from", "facts", ["extract", ' \
            '["certname", "facts"]], ["offset", 10]]]'

        # last example on page
        # https://puppet.com/docs/puppetdb/5.1/api/query/v4/ast.html

        op = InOperator('certname')
        ex = ExtractOperator()
        ex.add_field('certname')
        fr = FromOperator('fact_contents')
        nd = AndOperator()
github voxpupuli / pypuppetdb / tests / test_querybuilder.py View on Github external
fr = FromOperator("facts")
        fr.add_query(ex)
        fr.add_offset(10)
        op.add_query(fr)

        assert repr(op) == 'Query: ["in", "certname", ' \
            '["from", "facts", ["extract", ' \
            '["certname", "facts"]], ["offset", 10]]]'

        # last example on page
        # https://puppet.com/docs/puppetdb/5.1/api/query/v4/ast.html

        op = InOperator('certname')
        ex = ExtractOperator()
        ex.add_field('certname')
        fr = FromOperator('fact_contents')
        nd = AndOperator()
        nd.add(EqualsOperator("path",
                              ["networking", "eth0", "macaddresses", 0]))
        nd.add(EqualsOperator("value", "aa:bb:cc:dd:ee:00"))
        ex.add_query(nd)
        fr.add_query(ex)
        op.add_query(fr)

        assert str(op) == '["in", "certname", ' \
                          '["from", "fact_contents", ' \
github voxpupuli / pypuppetdb / tests / test_querybuilder.py View on Github external
def test_order_by(self):
        fr = FromOperator("facts")
        op = EqualsOperator("certname", "test01")
        fr.add_query(op)

        o1 = ["certname"]
        o2 = ["certname", ["timestamp", "desc"], "facts"]
        o3inv = ['certname', ['timestamp', 'desc', ['oops']]]

        fr.add_order_by(o1)
        assert str(fr) == \
            '["from", "facts", ["=", "certname", ' \
            '"test01"], ["order_by", ["certname"]]]'

        fr.add_order_by(o2)
        assert repr(fr) == \
            'Query: ["from", "facts", ' \
            '["=", "certname", "test01"], ' \
github voxpupuli / pypuppetdb / tests / test_querybuilder.py View on Github external
def test_add_query(self):
        fr = FromOperator("facts")
        op = EqualsOperator("certname", "test01")
        fr.add_query(op)

        assert str(fr) == '["from", "facts", ["=", "certname", "test01"]]'

        fr2 = FromOperator("facts")
        op2 = "test, test, test"
        with pytest.raises(APIError):
            fr2.add_query(op2)
        fr2.add_query(op)
        with pytest.raises(APIError):
            fr2.add_query(op)

        fr3 = FromOperator("facts")
        op3 = ExtractOperator()
        op3.add_field(['certname', 'fact_environment', 'catalog_environment'])
        fr3.add_query(op3)

        assert str(fr3) == \
            '["from", "facts", ["extract", '\
            '["certname", "fact_environment", "catalog_environment"]]]'
github voxpupuli / pypuppetdb / tests / test_querybuilder.py View on Github external
def test_init_from(self):
        fr = FromOperator("facts")

        with pytest.raises(APIError):
            str(fr) == "unimportant_no_query"

        with pytest.raises(APIError):
            fr2 = FromOperator('invalid_entity')
github voxpupuli / pypuppetdb / tests / test_querybuilder.py View on Github external
def test_init_from(self):
        fr = FromOperator("facts")

        with pytest.raises(APIError):
            str(fr) == "unimportant_no_query"

        with pytest.raises(APIError):
            fr2 = FromOperator('invalid_entity')
github voxpupuli / pypuppetdb / tests / test_querybuilder.py View on Github external
def test_add_query(self):
        fr = FromOperator("facts")
        op = EqualsOperator("certname", "test01")
        fr.add_query(op)

        assert str(fr) == '["from", "facts", ["=", "certname", "test01"]]'

        fr2 = FromOperator("facts")
        op2 = "test, test, test"
        with pytest.raises(APIError):
            fr2.add_query(op2)
        fr2.add_query(op)
        with pytest.raises(APIError):
            fr2.add_query(op)

        fr3 = FromOperator("facts")
        op3 = ExtractOperator()
        op3.add_field(['certname', 'fact_environment', 'catalog_environment'])
        fr3.add_query(op3)

        assert str(fr3) == \
            '["from", "facts", ["extract", '\
            '["certname", "fact_environment", "catalog_environment"]]]'
github voxpupuli / pypuppetdb / tests / test_querybuilder.py View on Github external
def test_add_query(self):
        fr = FromOperator("facts")
        op = EqualsOperator("certname", "test01")
        fr.add_query(op)

        assert str(fr) == '["from", "facts", ["=", "certname", "test01"]]'

        fr2 = FromOperator("facts")
        op2 = "test, test, test"
        with pytest.raises(APIError):
            fr2.add_query(op2)
        fr2.add_query(op)
        with pytest.raises(APIError):
            fr2.add_query(op)

        fr3 = FromOperator("facts")
        op3 = ExtractOperator()
        op3.add_field(['certname', 'fact_environment', 'catalog_environment'])
github voxpupuli / pypuppetdb / pypuppetdb / QueryBuilder.py View on Github external
def add_query(self, query):
        if self.query is not None:
            raise APIError("Only one query is supported by ExtractOperator")
        elif isinstance(query, str):
            self.query = True
            self.arr.append(json.loads(query))
        elif isinstance(query, (ExtractOperator, FromOperator)):
            self.query = True
            self.arr.append(query.json_data())
        else:
            raise APIError("InOperator.add_query only supports "
                           "strings, ExtractOperator, and"