How to use the pypuppetdb.QueryBuilder.EqualsOperator 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_multiple_add_query(self):
        with pytest.raises(APIError):
            op = SubqueryOperator('events')
            op.add_query(EqualsOperator('status', 'noop'))
            op.add_query(EqualsOperator('status', 'changed'))
github voxpupuli / pypuppetdb / tests / test_querybuilder.py View on Github external
def test_not_with_list(self):
        op = NotOperator()

        with pytest.raises(APIError):
            str(op.add([EqualsOperator('clientversion', '4.5.1'),
                        EqualsOperator('facterversion', '3.2.0')]))
github voxpupuli / pypuppetdb / tests / test_querybuilder.py View on Github external
def test_equal_operator(self):
        op = EqualsOperator("certname", "test01")
        assert str(op) == '["=", "certname", "test01"]'
        assert repr(op) == 'Query: ["=", "certname", "test01"]'
        assert str(op) == '["=", "certname", "test01"]'
        assert str(EqualsOperator("clientversion", 91))\
            == '["=", "clientversion", 91]'
        assert str(EqualsOperator("start_time", "2016-05-11T23:22:48.709Z"))\
            == '["=", "start_time", "2016-05-11T23:22:48.709Z"]'
        assert str(EqualsOperator("is_virtual", True))\
            == '["=", "is_virtual", true]'
        assert str(EqualsOperator("bios_version", ["6.00", 5.00]))\
            == '["=", "bios_version", ["6.00", 5.0]]'
        assert str(EqualsOperator(['parameter', 'ensure'], "present"))\
            == '["=", ["parameter", "ensure"], "present"]'
        assert str(EqualsOperator(u"latest_report?", True))\
            == '["=", "latest_report?", true]'
        assert str(EqualsOperator("report_timestamp",
                                  datetime.datetime(2016, 6, 11)))\
            == '["=", "report_timestamp", "2016-06-11 00:00:00"]'
github voxpupuli / pypuppetdb / tests / test_querybuilder.py View on Github external
def test_and_operator(self):
        op = AndOperator()
        op.add(EqualsOperator("operatingsystem", "CentOS"))
        op.add([EqualsOperator("architecture", "x86_64"),
                GreaterOperator("operatingsystemmajrelease", 6)])

        assert str(op) == '["and", ["=", "operatingsystem", "CentOS"], '\
            '["=", "architecture", "x86_64"], '\
            '[">", "operatingsystemmajrelease", 6]]'
        assert repr(op) == 'Query: ["and", '\
            '["=", "operatingsystem", "CentOS"], '\
            '["=", "architecture", "x86_64"], '\
            '[">", "operatingsystemmajrelease", 6]]'
        assert str(op) == '["and", ["=", "operatingsystem", "CentOS"], ' \
                          '["=", "architecture", "x86_64"], '\
            '[">", "operatingsystemmajrelease", 6]]'

        with pytest.raises(APIError):
            op.add({"query1": '["=", "catalog_environment", "production"]'})
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)
github voxpupuli / pypuppetdb / tests / test_querybuilder.py View on Github external
def test_events_endpoint(self):
        assert str(SubqueryOperator('events')) == \
            '["select_events"]'

        op = SubqueryOperator('events')
        op.add_query(EqualsOperator('status', 'noop'))

        assert repr(op) == 'Query: ["select_events", '\
            '["=", "status", "noop"]]'
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"], ' \
            '["order_by", ["certname", ' \
github voxpupuli / pypuppetdb / pypuppetdb / QueryBuilder.py View on Github external
def __init__(self, field, value):
        super(EqualsOperator, self).__init__("=", field, value)
github voxpupuli / puppetboard / puppetboard / dailychart.py View on Github external
def _build_query(env, start, end, certname=None):
    """Build a extract query with optional certname and environment."""
    query = ExtractOperator()
    query.add_field(FunctionOperator('count'))
    query.add_field('status')
    subquery = AndOperator()
    subquery.add(GreaterEqualOperator('producer_timestamp', start))
    subquery.add(LessOperator('producer_timestamp', end))
    if certname is not None:
        subquery.add(EqualsOperator('certname', certname))
    if env != '*':
        subquery.add(EqualsOperator('environment', env))
    query.add_query(subquery)
    query.add_group_by("status")
    return query