コード例 #1
0
def test_normalize_filter():
    # ensure we can properly normalize queries FIXME[matt] move to the agent
    cases = [
        (None, {}),
        (
            {"team":"leafs"},
            {"team": "?"},
        ),
        (
            {"age": {"$gt" : 20}},
            {"age": {"$gt" : "?"}},
        ),
        (
            {"age": {"$gt" : 20}},
            {"age": {"$gt" : "?"}},
        ),
        (
            {"_id": {"$in" : [1, 2, 3]}},
            {"_id": {"$in" : "?"}},
        ),
        (
            {"_id": {"$nin" : [1, 2, 3]}},
            {"_id": {"$nin" : "?"}},
        ),

        (
            20,
            {},
        ),
        (
            {
                "status": "A",
                "$or": [ { "age": { "$lt": 30 } }, { "type": 1 } ]
            },
            {
                "status": "?",
                "$or": [ { "age": { "$lt": "?" } }, { "type": "?" } ]
            }
        )
    ]
    for i, expected in cases:
        out = normalize_filter(i)
        eq_(expected, out)
コード例 #2
0
ファイル: test.py プロジェクト: uniq10/dd-trace-py
def test_normalize_filter():
    # ensure we can properly normalize queries FIXME[matt] move to the agent
    cases = [
        (None, {}),
        (
            {'team': 'leafs'},
            {'team': '?'},
        ),
        (
            {'age': {'$gt': 20}},
            {'age': {'$gt': '?'}},
        ),
        (
            {'age': {'$gt': 20}},
            {'age': {'$gt': '?'}},
        ),
        (
            {'_id': {'$in': [1, 2, 3]}},
            {'_id': {'$in': '?'}},
        ),
        (
            {'_id': {'$nin': [1, 2, 3]}},
            {'_id': {'$nin': '?'}},
        ),

        (
            20,
            {},
        ),
        (
            {
                'status': 'A',
                '$or': [{'age': {'$lt': 30}}, {'type': 1}],
            },
            {
                'status': '?',
                '$or': [{'age': {'$lt': '?'}}, {'type': '?'}],
            },
        ),
    ]
    for i, expected in cases:
        out = normalize_filter(i)
        assert expected == out