예제 #1
0
def test_update_max_4(monty_update, mongo_update):
    docs = [{"a": {"b": 5}}]
    spec = {"$max": {"a": bson.MaxKey()}}

    monty_c = monty_update(docs, spec)
    mongo_c = mongo_update(docs, spec)

    assert next(mongo_c) == next(monty_c)
    monty_c.rewind()
    assert next(monty_c) == {"a": bson.MaxKey()}
def test_qop_lte_13(monty_find, mongo_find, mongo_version):
    oid_0 = bson.ObjectId(b"000000000000")
    max_k = bson.MaxKey()
    min_k = bson.MinKey()
    docs = [
        {
            "a": oid_0
        },
        {
            "a": max_k
        },
        {
            "a": min_k
        },
        {
            "a": 55
        },
    ]
    spec = {"a": {"$lte": min_k}}

    monty_c = monty_find(docs, spec)
    mongo_c = mongo_find(docs, spec)

    count = 4 if mongo_version[0] == 3 else 1

    assert count_documents(mongo_c, spec) == count
    assert count_documents(monty_c, spec) == count_documents(mongo_c, spec)
    for i in range(count):
        assert next(mongo_c) == next(monty_c)
예제 #3
0
def test_sort_8(monty_sort, mongo_sort):
    docs = [{"a": bson.MinKey()}, {"a": bson.MaxKey()}]
    sort = [("a", -1)]

    monty_c = monty_sort(docs, sort)
    mongo_c = mongo_sort(docs, sort)

    for i in range(len(docs)):
        assert next(mongo_c)["_id"] == next(monty_c)["_id"]
def test_qop_lt_12(monty_find, mongo_find):
    min_k = bson.MinKey()
    max_k = bson.MaxKey()
    docs = [{"a": min_k}, {"a": max_k}]
    spec = {"a": {"$lt": max_k}}

    monty_c = monty_find(docs, spec)
    mongo_c = mongo_find(docs, spec)

    assert count_documents(mongo_c, spec) == 1
    assert count_documents(monty_c, spec) == count_documents(mongo_c, spec)
    assert next(mongo_c) == next(monty_c)
def test_qop_gte_12(monty_find, mongo_find):
    min_k = bson.MinKey()
    max_k = bson.MaxKey()
    docs = [{"a": min_k}, {"a": max_k}]
    spec = {"a": {"$gte": min_k}}

    monty_c = monty_find(docs, spec)
    mongo_c = mongo_find(docs, spec)

    assert count_documents(mongo_c, spec) == 2
    assert count_documents(monty_c, spec) == count_documents(mongo_c, spec)
    for i in range(2):
        assert next(mongo_c) == next(monty_c)
예제 #6
0
def test_weighted_24():
    data = bson.MaxKey()
    assert Weighted(data) == (127, data)
예제 #7
0
def test_sort_19(monty_sort, mongo_sort):
    docs = [
        {
            "a": ["x", True]
        },
        {
            "a": None
        },
        {
            "a": []
        },
        {
            "a": [5, []]
        },
        {
            "a": {
                "s": 7
            }
        },
        {
            "a": {
                "s": [9]
            }
        },
        {
            "a": {
                "s": 10
            }
        },
        {
            "a": 6
        },
        {
            "a": 4
        },
        {
            "a": [5, None]
        },
        {
            "a": [5, [1]]
        },
        {
            "a": [bson.Decimal128("4.5"),
                  bson.Binary(b"0")]
        },
        {
            "a": [{
                "s": 5
            }, False]
        },
        {
            "a": [{
                "s": 9
            }]
        },
        {
            "a": [True, "y"]
        },
        {
            "a": bson.Binary(b"a")
        },
        {
            "a": b"bytes"
        },
        {
            "a": ["abc"]
        },
        {
            "a": "banana"
        },
        {
            "a": "appple"
        },
        {
            "a": [bson.Regex("^a", "ix")]
        },
        {
            "a": bson.Regex("^b")
        },
        {
            "a": bson.Code("x", {"m": 0})
        },
        {
            "a": bson.Code("y")
        },
        {
            "a": bson.Code("y", {})
        },
        {
            "a": bson.Code("y", {"m": 0})
        },
        {
            "a": bson.MinKey()
        },
        {
            "a": bson.MaxKey()
        },
        {
            "a": bson.Timestamp(0, 1)
        },
        {
            "a": bson.Timestamp(1, 1)
        },
        {
            "a": bson.ObjectId(b"000000000000")
        },
        {
            "a": bson.ObjectId(b"000000000001")
        },
        {
            "a": datetime(1900, 1, 1)
        },
        {
            "a": datetime(1900, 1, 2)
        },
    ]
    sort = [("_id", 1), ("a", 1)]

    monty_c = monty_sort(docs, sort)
    mongo_c = mongo_sort(docs, sort)

    for i in range(len(docs)):
        assert next(mongo_c)["_id"] == next(monty_c)["_id"]