return db
-
-
def empty_exception_message():
return 'database exception '
("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)
("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)
("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)
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)
("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)
("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)
("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)
("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)
("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)
("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
("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)
("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)
("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)
("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)
("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)
@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 = {}
("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)
("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)
("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
("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)
("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 = {}
("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
("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
("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)
("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)