Adding tests for unimplemented features
[osm/common.git] / osm_common / tests / test_dbmemory.py
index f73c317..a11dc1a 100644 (file)
@@ -23,8 +23,6 @@ def db_memory_with_data():
 
     return db
 
-
-
 def empty_exception_message():
     return 'database exception '
 
@@ -64,12 +62,14 @@ def test_db_connect():
     assert db.logger == logging.getLogger(logger_name)
     assert len(db.db) == 0
 
+def test_db_disconnect(db_memory):
+    db_memory.db_disconnect()
+
 @pytest.mark.parametrize("table, filter", [
     ("test", {}),
     ("test", {"_id": 1}),
     ("test", {"data": 1}),
-    ("test", {"_id": 1, "data": 1}),
-])
+    ("test", {"_id": 1, "data": 1})])
 def test_get_list_with_empty_db(db_memory, table, filter):
     result = db_memory.get_list(table, filter)
 
@@ -89,8 +89,7 @@ def test_get_list_with_empty_db(db_memory, table, filter):
     ("test_table", {}, []),
     ("test_table", {"_id": 1}, []),
     ("test_table", {"data": 1}, []),
-    ("test_table", {"_id": 1, "data": 1}, []),
-])
+    ("test_table", {"_id": 1, "data": 1}, [])])
 def test_get_list_with_non_empty_db(db_memory_with_data, table, filter, expected_data):
     result = db_memory_with_data.get_list(table, filter)
 
@@ -118,8 +117,7 @@ def test_get_list_exception(db_memory_with_data):
     ("test", {"data": 3}, {"_id": 3, "data": 3}),
     ("test", {"_id": 1, "data": 1}, {"_id": 1, "data": 1}),
     ("test", {"_id": 2, "data": 2}, {"_id": 2, "data": 2}),
-    ("test", {"_id": 3, "data": 3}, {"_id": 3, "data": 3}),
-])
+    ("test", {"_id": 3, "data": 3}, {"_id": 3, "data": 3})])
 def test_get_one(db_memory_with_data, table, filter, expected_data):
     result = db_memory_with_data.get_one(table, filter)
 
@@ -130,8 +128,7 @@ def test_get_one(db_memory_with_data, table, filter, expected_data):
     assert result in db_memory_with_data.db[table]
 
 @pytest.mark.parametrize("table, filter, expected_data", [
-    ("test", {}, {"_id": 1, "data": 1}),
-])
+    ("test", {}, {"_id": 1, "data": 1})])
 def test_get_one_with_multiple_results(db_memory_with_data, table, filter, expected_data):
     result = db_memory_with_data.get_one(table, filter, fail_on_more=False)
 
@@ -157,8 +154,7 @@ def test_get_one_with_multiple_results_exception(db_memory_with_data):
     ("test", {"_id": 4, "data": 4}),
     ("test_table", {"_id": 4}),
     ("test_table", {"data": 4}),
-    ("test_table", {"_id": 4, "data": 4}),
-])
+    ("test_table", {"_id": 4, "data": 4})])
 def test_get_one_with_non_empty_db_exception(db_memory_with_data, table, filter):
     with pytest.raises(DbException) as excinfo:
         db_memory_with_data.get_one(table, filter)
@@ -171,8 +167,7 @@ def test_get_one_with_non_empty_db_exception(db_memory_with_data, table, filter)
     ("test", {"_id": 4, "data": 4}),
     ("test_table", {"_id": 4}),
     ("test_table", {"data": 4}),
-    ("test_table", {"_id": 4, "data": 4}),
-])
+    ("test_table", {"_id": 4, "data": 4})])
 def test_get_one_with_non_empty_db_none(db_memory_with_data, table, filter):
     result = db_memory_with_data.get_one(table, filter, fail_on_empty=False)
     
@@ -184,8 +179,7 @@ def test_get_one_with_non_empty_db_none(db_memory_with_data, table, filter):
     ("test", {"_id": 4, "data": 4}),
     ("test_table", {"_id": 4}),
     ("test_table", {"data": 4}),
-    ("test_table", {"_id": 4, "data": 4}),
-])
+    ("test_table", {"_id": 4, "data": 4})])
 def test_get_one_with_empty_db_exception(db_memory, table, filter):
     with pytest.raises(DbException) as excinfo:
         db_memory.get_one(table, filter)
@@ -198,8 +192,7 @@ def test_get_one_with_empty_db_exception(db_memory, table, filter):
     ("test", {"_id": 4, "data": 4}),
     ("test_table", {"_id": 4}),
     ("test_table", {"data": 4}),
-    ("test_table", {"_id": 4, "data": 4}),
-])
+    ("test_table", {"_id": 4, "data": 4})])
 def test_get_one_with_empty_db_none(db_memory, table, filter):
     result = db_memory.get_one(table, filter, fail_on_empty=False)
     
@@ -221,8 +214,7 @@ def test_get_one_generic_exception(db_memory_with_data):
     ("test", {"_id": 1}, [{"_id": 2, "data": 2}, {"_id": 3, "data": 3}]), 
     ("test", {"_id": 2}, [{"_id": 1, "data": 1}, {"_id": 3, "data": 3}]), 
     ("test", {"_id": 1, "data": 1}, [{"_id": 2, "data": 2}, {"_id": 3, "data": 3}]),
-    ("test", {"_id": 2, "data": 2}, [{"_id": 1, "data": 1}, {"_id": 3, "data": 3}]),
-])
+    ("test", {"_id": 2, "data": 2}, [{"_id": 1, "data": 1}, {"_id": 3, "data": 3}])])
 def test_del_list_with_non_empty_db(db_memory_with_data, table, filter, expected_data):
     result = db_memory_with_data.del_list(table, filter)
 
@@ -240,8 +232,7 @@ def test_del_list_with_non_empty_db(db_memory_with_data, table, filter, expected
     ("test", {"data": 1}),
     ("test", {"data": 2}),
     ("test", {"_id": 1, "data": 1}),
-    ("test", {"_id": 2, "data": 2}),
-])
+    ("test", {"_id": 2, "data": 2})])
 def test_del_list_with_empty_db(db_memory, table, filter):
     result = db_memory.del_list(table, filter)
     assert result['deleted'] == 0
@@ -264,8 +255,7 @@ def test_del_list_generic_exception(db_memory_with_data):
     ("test", {"_id": 1, "data": 1}, {"_id": 1, "data": 1}),
     ("test", {"_id": 2}, {"_id": 2, "data": 2}),
     ("test", {"data": 2}, {"_id": 2, "data": 2}),
-    ("test", {"_id": 2, "data": 2}, {"_id": 2, "data": 2}),
-])
+    ("test", {"_id": 2, "data": 2}, {"_id": 2, "data": 2})])
 def test_del_one(db_memory_with_data, table, filter, data):
     result = db_memory_with_data.del_one(table, filter)
 
@@ -289,8 +279,7 @@ def test_del_one(db_memory_with_data, table, filter, data):
     ("test_table", {"data": 1}),
     ("test_table", {"data": 2}),
     ("test_table", {"_id": 1, "data": 1}),
-    ("test_table", {"_id": 2, "data": 2}),
-])
+    ("test_table", {"_id": 2, "data": 2})])
 def test_del_one_with_empty_db_exception(db_memory, table, filter):
     with pytest.raises(DbException) as excinfo:
         db_memory.del_one(table, filter)
@@ -311,8 +300,7 @@ def test_del_one_with_empty_db_exception(db_memory, table, filter):
     ("test_table", {"data": 1}),
     ("test_table", {"data": 2}),
     ("test_table", {"_id": 1, "data": 1}),
-    ("test_table", {"_id": 2, "data": 2}),
-])
+    ("test_table", {"_id": 2, "data": 2})])
 def test_del_one_with_empty_db_none(db_memory, table, filter):
     result = db_memory.del_one(table, filter, fail_on_empty=False)
 
@@ -331,8 +319,7 @@ def test_del_one_with_empty_db_none(db_memory, table, filter):
     ("test_table", {"data": 1}),
     ("test_table", {"data": 2}),
     ("test_table", {"_id": 1, "data": 1}),
-    ("test_table", {"_id": 2, "data": 2}),
-])
+    ("test_table", {"_id": 2, "data": 2})])
 def test_del_one_with_non_empty_db_exception(db_memory_with_data, table, filter):
     with pytest.raises(DbException) as excinfo:
         db_memory_with_data.del_one(table, filter)
@@ -352,8 +339,7 @@ def test_del_one_with_non_empty_db_exception(db_memory_with_data, table, filter)
     ("test_table", {"data": 1}),
     ("test_table", {"data": 2}),
     ("test_table", {"_id": 1, "data": 1}),
-    ("test_table", {"_id": 2, "data": 2}),
-])
+    ("test_table", {"_id": 2, "data": 2})])
 def test_del_one_with_non_empty_db_none(db_memory_with_data, table, filter):
     result = db_memory_with_data.del_one(table, filter, fail_on_empty=False)
 
@@ -361,8 +347,7 @@ def test_del_one_with_non_empty_db_none(db_memory_with_data, table, filter):
 
 @pytest.mark.parametrize("fail_on_empty", [
     (True),
-    (False),
-])
+    (False)])
 def test_del_one_generic_exception(db_memory_with_data, fail_on_empty):
     table = 'test'
     filter = {}
@@ -382,8 +367,7 @@ def test_del_one_generic_exception(db_memory_with_data, fail_on_empty):
     ("test", {"data": 1}, {"_id": 3, "data": 42}),
     ("test", {"data": 3}, {"_id": 3, "data": 42}),
     ("test", {"_id": 1, "data": 1}, {"_id": 3, "data": 42}),
-    ("test", {"_id": 3, "data": 3}, {"_id": 3, "data": 42}),
-])
+    ("test", {"_id": 3, "data": 3}, {"_id": 3, "data": 42})])
 def test_replace(db_memory_with_data, table, filter, indata):
     result = db_memory_with_data.replace(table, filter, indata)
 
@@ -403,8 +387,7 @@ def test_replace(db_memory_with_data, table, filter, indata):
     ("test_table", {}, {'_id': 2, 'data': 1}),
     ("test_table", {}, {'_id': 1, 'data': 2}),
     ("test_table", {'_id': 1}, {'_id': 1, 'data': 1}),
-    ("test_table", {'_id': 1, 'data': 1}, {'_id': 1, 'data': 1}),
-])
+    ("test_table", {'_id': 1, 'data': 1}, {'_id': 1, 'data': 1})])
 def test_replace_without_data_exception(db_memory, table, filter, indata):
     with pytest.raises(DbException) as excinfo:
         db_memory.replace(table, filter, indata, fail_on_empty=True)
@@ -421,8 +404,7 @@ def test_replace_without_data_exception(db_memory, table, filter, indata):
     ("test_table", {}, {'_id': 2, 'data': 1}),
     ("test_table", {}, {'_id': 1, 'data': 2}),
     ("test_table", {'_id': 1}, {'_id': 1, 'data': 1}),
-    ("test_table", {'_id': 1, 'data': 1}, {'_id': 1, 'data': 1}),
-])
+    ("test_table", {'_id': 1, 'data': 1}, {'_id': 1, 'data': 1})])
 def test_replace_without_data_none(db_memory, table, filter, indata):
     result = db_memory.replace(table, filter, indata, fail_on_empty=False)
     assert result == None
@@ -432,8 +414,7 @@ def test_replace_without_data_none(db_memory, table, filter, indata):
     ("test_table", {}, {'_id': 2, 'data': 1}),
     ("test_table", {}, {'_id': 1, 'data': 2}),
     ("test_table", {'_id': 1}, {'_id': 1, 'data': 1}),
-    ("test_table", {'_id': 1, 'data': 1}, {'_id': 1, 'data': 1}),
-])
+    ("test_table", {'_id': 1, 'data': 1}, {'_id': 1, 'data': 1})])
 def test_replace_with_data_exception(db_memory_with_data, table, filter, indata):
     with pytest.raises(DbException) as excinfo:
         db_memory_with_data.replace(table, filter, indata, fail_on_empty=True)
@@ -445,16 +426,14 @@ def test_replace_with_data_exception(db_memory_with_data, table, filter, indata)
     ("test_table", {}, {'_id': 2, 'data': 1}),
     ("test_table", {}, {'_id': 1, 'data': 2}),
     ("test_table", {'_id': 1}, {'_id': 1, 'data': 1}),
-    ("test_table", {'_id': 1, 'data': 1}, {'_id': 1, 'data': 1}),
-])
+    ("test_table", {'_id': 1, 'data': 1}, {'_id': 1, 'data': 1})])
 def test_replace_with_data_none(db_memory_with_data, table, filter, indata):
     result = db_memory_with_data.replace(table, filter, indata, fail_on_empty=False)
     assert result == None
 
 @pytest.mark.parametrize("fail_on_empty", [
     (True),
-    (False),
-])
+    (False)])
 def test_replace_generic_exception(db_memory_with_data, fail_on_empty):
     table = 'test'
     filter = {}
@@ -483,8 +462,7 @@ def test_replace_generic_exception(db_memory_with_data, fail_on_empty):
     ("test_table", "1", {"data_1": 1, "data_2": 2}),
     ("test_table", "1", {"data_1": 2, "data_2": 1}),
     ("test_table", "2", {"data_1": 1, "data_2": 2}),
-    ("test_table", "2", {"data_1": 2, "data_2": 1}),
-])
+    ("test_table", "2", {"data_1": 2, "data_2": 1})])
 def test_create_with_empty_db_with_id(db_memory, table, id, data):
     data_to_insert = data
     data_to_insert['_id'] = id
@@ -513,8 +491,7 @@ def test_create_with_empty_db_with_id(db_memory, table, id, data):
     ("test_table", "4", {"data_1": 1, "data_2": 2}),
     ("test_table", "5", {"data_1": 2, "data_2": 1}),
     ("test_table", "4", {"data_1": 1, "data_2": 2}),
-    ("test_table", "5", {"data_1": 2, "data_2": 1}),
-])
+    ("test_table", "5", {"data_1": 2, "data_2": 1})])
 def test_create_with_non_empty_db_with_id(db_memory_with_data, table, id, data):
     data_to_insert = data
     data_to_insert['_id'] = id
@@ -543,8 +520,7 @@ def test_create_with_non_empty_db_with_id(db_memory_with_data, table, id, data):
     ("test_table", {"data_1": 1, "data_2": 2}),
     ("test_table", {"data_1": 2, "data_2": 1}),
     ("test_table", {"data_1": 1, "data_2": 2}),
-    ("test_table", {"data_1": 2, "data_2": 1}),
-])
+    ("test_table", {"data_1": 2, "data_2": 1})])
 def test_create_with_empty_db_without_id(db_memory, table, data):
     returned_id = db_memory.create(table, data)
 
@@ -573,8 +549,7 @@ def test_create_with_empty_db_without_id(db_memory, table, data):
     ("test_table", {"data_1": 1, "data_2": 2}),
     ("test_table", {"data_1": 2, "data_2": 1}),
     ("test_table", {"data_1": 1, "data_2": 2}),
-    ("test_table", {"data_1": 2, "data_2": 1}),
-])
+    ("test_table", {"data_1": 2, "data_2": 1})])
 def test_create_with_non_empty_db_without_id(db_memory_with_data, table, data):
     returned_id = db_memory_with_data.create(table, data)