-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathtest_userclass.py
44 lines (36 loc) · 1.12 KB
/
test_userclass.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
from objectbox import *
from objectbox.model.idsync import sync_model
def test_userclass():
@Entity()
class Person:
id = Id()
firstName = String()
lastName = String()
def __init__(self):
self.counter = 0
def fullname(self):
return f"{self.firstName} {self.lastName}"
def tick(self):
self.counter += 1
model = Model()
model.entity(Person)
sync_model(model)
dbpath = "testdb"
Store.remove_db_files(dbpath)
store = Store(model=model, directory=dbpath)
box = store.box(Person)
id_alice = box.put(Person(firstName="Alice", lastName="Adkinson"))
box.put(Person(firstName="Bob", lastName="Bowman"))
box.put(Person(firstName="Cydia", lastName="Cervesa"))
assert box.count() == 3
alice = box.get(id_alice)
assert alice.fullname() == "Alice Adkinson"
assert alice.counter == 0
alice.tick()
alice.tick()
assert alice.counter == 2
alice = box.get(id_alice)
assert alice.counter == 0
id_empty = box.put(Person())
empty = box.get(id_empty)
assert empty.fullname() == " "