This repository was archived by the owner on Dec 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathstorage_test.py
54 lines (42 loc) · 1.62 KB
/
storage_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
from fusionengine import JsonStorage
def test_jsonstorage(cleanup):
my_db = JsonStorage("my_db.json")
# Insert
print("------------------- INSERT -------------------")
my_db.insert({"first_name": "john", "last_name": "wick", "gold": 50})
my_db.insert({"first_name": "alexander", "last_name": "wick", "gold": 20})
print(my_db.storage)
print("------------------- INSERT/ -------------------")
# Read
print("------------------- READ -------------------")
print(my_db.search({"last_name": "wick"}))
print(my_db.search({"last_name": "wick"}, get_index=True))
if (
search_result := my_db.search(
{"first_name": "alexander", "last_name": "wick"}, True, True
)
) != None:
alex, alex_index = search_result
if search_result := my_db.search({"first_name": "john"}, True, True):
_, john_index = search_result
print("------------------- READ/ -------------------")
# Update
print("------------------- UPDATE -------------------")
alex["gold"] += 20
my_db.update(alex_index, alex)
print(my_db.storage)
print("------------------- UPDATE/ -------------------")
# Delete
print("------------------- DELETE -------------------")
my_db.delete(john_index)
print(my_db.storage)
print("------------------- DELETE/ -------------------")
# Saving to disk
print("------------------- SAVE -------------------")
print(my_db.save())
print("------------------- SAVE/ -------------------")
if cleanup:
os.remove(my_db.file_path)
if __name__ == "__main__":
test_jsonstorage(cleanup=True)