Skip to content

Commit 98ec62b

Browse files
committed
minor additions to test_userclass() #56
1 parent 4598b21 commit 98ec62b

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

tests/test_userclass.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,45 @@
11
from objectbox import *
22
from objectbox.model import *
33

4+
45
def test_userclass():
5-
66
@Entity(id=1, uid=1)
77
class Person:
88
id = Id(id=1, uid=1001)
99
firstName = Property(str, id=2, uid=1002)
1010
lastName = Property(str, id=3, uid=1003)
11+
1112
def __init__(self):
1213
self.counter = 0
14+
1315
def fullname(self):
1416
return f"{self.firstName} {self.lastName}"
17+
1518
def tick(self):
1619
self.counter += 1
17-
20+
1821
model = Model()
1922
model.entity(Person, last_property_id=IdUid(3, 1003))
20-
model.last_entity_id = IdUid(1,1)
23+
model.last_entity_id = IdUid(1, 1)
2124
dbpath = "testdb"
2225
Store.remove_db_files(dbpath)
23-
store = Store(model = model, directory = dbpath)
26+
27+
store = Store(model=model, directory=dbpath)
2428
box = store.box(Person)
25-
id_alice = box.put( Person(firstName="Alice", lastName="Adkinson"))
26-
id2 = box.put( Person(firstName="Bob", lastName="Bowman"))
27-
id3 = box.put( Person(firstName="Cydia", lastName="Cervesa"))
29+
id_alice = box.put(Person(firstName="Alice", lastName="Adkinson"))
30+
box.put(Person(firstName="Bob", lastName="Bowman"))
31+
box.put(Person(firstName="Cydia", lastName="Cervesa"))
2832
assert box.count() == 3
2933
alice = box.get(id_alice)
3034
assert alice.fullname() == "Alice Adkinson"
3135
assert alice.counter == 0
3236
alice.tick()
3337
alice.tick()
3438
assert alice.counter == 2
39+
40+
alice = box.get(id_alice)
41+
assert alice.counter == 0
42+
43+
id_empty = box.put(Person())
44+
empty = box.get(id_empty)
45+
assert empty.fullname() == " "

0 commit comments

Comments
 (0)