def get_clients(str1, str2, ns):
    client_dict = {
        "mongo":
        lambda: pymongo.MongoClient(
            ns['mongo_host'], ns['mongo_port'], maxPoolSize=1),
        "mm":
        lambda: MongoModel("DocLayer"),
        "doclayer":
        lambda: pymongo.MongoClient(
            ns['doclayer_host'], ns['doclayer_port'], maxPoolSize=1)
    }
    if 'mongo' in [ns['1'], ns['2']] and 'mm' in [ns['1'], ns['2']]:
        client_dict['mm'] = lambda: MongoModel("MongoDB")

    instance_id = str(random.random())[2:] if ns['instance_id'] == 0 else str(
        ns['instance_id'])
    print 'Instance: ' + instance_id

    client1 = client_dict[str1]()
    client2 = client_dict[str2]()
    return (client1, client2, instance_id)
Пример #2
0
def run_and_compare(dl_collection, test):
    mm = MongoModel('DocLayer')
    mm_collection = mm['test']['test']

    (selector, update) = test

    update = util.deep_convert_to_ordered(update)

    dl_collection.delete_many({})

    def up(c, s, u):
        c.update_one(s, u, upsert=True)

    mm_err = dl_err = False
    try:
        up(mm_collection, selector, update)
    except MongoModelException:
        mm_err = True
    try:
        up(dl_collection, selector, update)
    except OperationFailure:
        dl_err = True
    assert mm_err == dl_err, "Expected both to fail or succeed but, mm: {}, dl: {}".format(
        mm_err, dl_err)

    mm_ret = [
        util.deep_convert_to_unordered(i) for i in mm_collection.find({})
    ]
    mm_ret.sort()
    dl_ret = [
        util.deep_convert_to_unordered(i) for i in dl_collection.find({})
    ]
    dl_ret.sort()

    for doc in mm_ret:
        del doc['_id']

    for doc in dl_ret:
        del doc['_id']

    assert mm_ret == dl_ret
Пример #3
0
def run_and_match(dl_collection, test):
    mm = MongoModel('DocLayer')
    mm_collection = mm['test']['test']

    dl_collection.delete_many({})

    (doc, queries) = test

    doc = util.deep_convert_to_ordered(doc)

    mm_collection.insert_one(doc)
    dl_collection.insert_one(doc)

    for query in queries:
        ret1 = [util.deep_convert_to_unordered(i) for i in mm_collection.find(query)]
        ret1.sort()
        ret2 = [util.deep_convert_to_unordered(i) for i in dl_collection.find(query)]
        ret2.sort()

        assert len(ret1) == len(ret2), "Number returned docs don't match, mm: {}, dl: {}".format(len(ret1), len(ret2))
        for i in range(0, len(ret1)):
            assert ret1[i] == ret2[i], "Mismatch at {}, mm: {}, dl: {}".format(i, ret1[i], ret2[i])