-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathtest_model.py
More file actions
83 lines (66 loc) · 1.89 KB
/
test_model.py
File metadata and controls
83 lines (66 loc) · 1.89 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from objectbox.model import *
from objectbox import *
from objectbox.model.idsync import sync_model
import os
import os.path
def test_reuse_model():
@Entity()
class MyEntity:
id = Id()
name = String()
model = Model()
model.entity(MyEntity)
model_filepath = "test-model.json"
if os.path.exists(model_filepath):
os.remove(model_filepath)
sync_model(model, model_filepath)
db1path = "test-db1"
db2path = "test-db2"
Store.remove_db_files(db1path)
Store.remove_db_files(db2path)
store1 = Store(model=model, directory=db1path)
store2 = Store(model=model, directory=db2path)
store1.close()
store2.close()
def test_reuse_entity():
@Entity()
class MyEntity:
id = Id()
name = String()
m1 = Model()
m1.entity(MyEntity)
model_filepath = "test-model1.json"
if os.path.exists(model_filepath):
os.remove(model_filepath)
sync_model(m1, model_filepath)
db1path = "test-db1"
db2path = "test-db2"
Store.remove_db_files(db1path)
Store.remove_db_files(db2path)
store1 = Store(model=m1, directory=db1path)
box1 = store1.box(MyEntity)
box1.put(MyEntity(name="foo"))
assert box1.count() == 1
m2 = Model()
@Entity()
class MyEntity2:
id = Id()
name = String()
value = Int64()
m2.entity(MyEntity2)
m2.entity(MyEntity)
model_filepath = "test-model2.json"
if os.path.exists(model_filepath):
os.remove(model_filepath)
sync_model(m2, model_filepath)
store2 = Store(model=m2, directory=db2path)
box2 = store2.box(MyEntity)
box2.put(MyEntity(name="bar"))
box2.put(MyEntity(name="bar"))
box2.put(MyEntity(name="bar"))
assert box2.count() == 3
box1.put(MyEntity(name="foo"))
box1.put(MyEntity(name="foo"))
assert box1.count() == 3
store1.close()
store2.close()