Example #1
0
def test_update_many_ok():
    """test_update_many_ok"""
    mongo_db_access = MongoDBAccess(CONFIG, "DEBUG")

    mongo_db_access.insert("testUpdateMany_ok", {
        "clave": "IPUpdateMany",
        "value": 0
    })
    mongo_db_access.insert("testUpdateMany_ok", {
        "clave": "IPUpdateMany",
        "value": 0
    })

    res_update = mongo_db_access.update_many("testUpdateMany_ok",\
                                                {"clave":"IPUpdateMany"}, {'value':1})
    res_find = mongo_db_access.find("testUpdateMany_ok",
                                    {"clave": "IPUpdateMany"})
    count_elements = 0
    for element_finding in res_find:
        count_elements += 1
        assert element_finding['value'] == 1

    assert res_update.modified_count == 2
    mongo_db_access.drop("testUpdateMany_ok")
    assert count_elements == 2
Example #2
0
def test_find_one_error_collection():
    """test_find_one_error_collection"""
    mongo_db_access = MongoDBAccess(CONFIG, "DEBUG")
    mongo_db_access.insert("testFindone_errorCollection", {"clave": "IPFind"})
    res = mongo_db_access.find_one("testFindone_errorCollectionXX",
                                   {"clave": "IP"})
    mongo_db_access.drop("testFindone_errorCollection")
    assert res is None
Example #3
0
def test_find_one_ok():
    """test_find_one_ok"""
    mongo_db_access = MongoDBAccess(CONFIG, "DEBUG")
    mongo_db_access.insert("testFindOne", {"clave": "IPFind", "value": 0})
    res = mongo_db_access.find_one("testFindOne", {"clave": "IPFind"})
    mongo_db_access.drop("testFindOne")

    assert res != None
Example #4
0
def test_update_many_error_find():
    """test_update_many_error_find"""
    mongo_db_access = MongoDBAccess(CONFIG, "DEBUG")
    mongo_db_access.insert("testUpdateManyErrorFind",\
                                         {"clave":"IPUpdateManyErrorF", "value":0})
    res = mongo_db_access.update_many("testUpdateManyErrorFind",\
                                      {"clave":"IPUpdateManyErrorFXX"}, {'value':1})
    mongo_db_access.drop("testUpdateManyErrorFind")

    assert res.modified_count == 0
Example #5
0
def test_update_one_error_find():
    """test_update_one_error_find"""
    mongo_db_access = MongoDBAccess(CONFIG, "DEBUG")
    mongo_db_access.insert("testUpdateone_errorFind",\
                                        {"clave":"IPUpdateOne", "value":0})
    res = mongo_db_access.update_one("testUpdateone_errorFind",\
                                     {"clave":"IPFind"}, {'valorX':"1234"})
    mongo_db_access.drop("testUpdateone_errorFind")

    assert res.modified_count == 0
Example #6
0
def test_find_one_error_db():
    """test_find_one_error_db"""
    mongo_db_access = MongoDBAccess(CONFIG_ERROR, "DEBUG")
    mongo_db_access.insert("testFindone_error_db", {
        "clave": "IPFind",
        "value": 0
    })
    res = mongo_db_access.find_one("testFindone_error_db", {"clave": "IPFind"})
    mongo_db_access.drop("testFindone_error_db")

    assert res is None
Example #7
0
def test_update_many_error_collect():
    """test_update_many_error_collection"""
    mongo_db_access = MongoDBAccess(CONFIG, "DEBUG")
    mongo_db_access.insert("testUpdateManyErrorColection",\
                                         {"clave":"IPUpdateMany", "value":0})
    mongo_db_access.insert("testUpdateManyErrorColection",\
                                        {"clave":"IPUpdateMany", "value":0})
    res = mongo_db_access.update_many("testUpdateManyErrorColectionXX",\
                                      {"clave":"IPManyUpdateError"}, {'valorX':"1234"})
    mongo_db_access.drop("testUpdateManyErrorColection")

    assert res.modified_count == 0
Example #8
0
def test_find_ok():
    """test_find_ok"""
    mongo_db_access = MongoDBAccess(CONFIG, "DEBUG")
    mongo_db_access.insert("testFind_ok", {"clave": "IPFind", "value": 0})
    mongo_db_access.insert("testFind_ok", {"clave": "IPFind", "value": 1})
    res = mongo_db_access.find("testFind_ok", {})
    count_elements = 0
    for element_finding in res:
        if element_finding != None:
            print "XXXXX"
        count_elements = +1
    mongo_db_access.drop("testFind_ok")

    assert count_elements > 0
Example #9
0
def test_find_error_filter():
    """test_find_error_filter"""
    mongo_db_access = MongoDBAccess(CONFIG, "DEBUG")
    mongo_db_access.insert("testFindErrorFilter", {
        "clave": "IPFind",
        "value": 0
    })
    res = mongo_db_access.find("testFindErrorFilter", {"xxx": "xxxx"})
    count_elements = 0
    for element_finding in res:
        if element_finding != None:
            count_elements += 1
    mongo_db_access.drop("testFindErrorFilter")

    assert count_elements == 0
Example #10
0
def test_update_one_ok():
    """test_update_one_ok"""
    mongo_db_access = MongoDBAccess(CONFIG, "DEBUG")
    mongo_db_access.insert("testUpdateOne", {
        "clave": "IPUpdateOne",
        "value": 0
    })
    res_update1 = mongo_db_access.update_one("testUpdateOne",
                                             {"clave": "IPUpdateOne"},
                                             {'value': 1})
    res_find1 = mongo_db_access.find_one("testUpdateOne",
                                         {"clave": "IPUpdateOne"})
    mongo_db_access.delete_one("testUpdateOne", {"clave": "IPUpdateOne"})
    mongo_db_access.drop("testUpdateOne")

    assert res_update1 != None
    assert res_find1['value'] == 1
Example #11
0
def test_insert_ok():
    """test_insert_ok"""
    mongo_db_access = MongoDBAccess(CONFIG, "DEBUG")
    res_insert = mongo_db_access.insert("testInsert_ok", {"clave": "IPInsert"})
    res_find1 = mongo_db_access.find_one("testInsert_ok",
                                         {"clave": "IPInsert"})

    assert res_insert != None
    assert res_find1['clave'] == "IPInsert"

    res_remove = mongo_db_access.delete_one("testInsert_ok",
                                            {"clave": "IPInsert"})
    res_find2 = mongo_db_access.find_one("testInsert_ok",
                                         {"clave": "IPInsert"})
    mongo_db_access.drop("testInsert_ok")

    assert res_remove.deleted_count == 1
    assert res_find2 is None