|
1 | 1 | from objectbox import * |
2 | 2 | from objectbox.model import * |
3 | 3 |
|
| 4 | + |
4 | 5 | def test_userclass(): |
5 | | - |
6 | 6 | @Entity(id=1, uid=1) |
7 | 7 | class Person: |
8 | 8 | id = Id(id=1, uid=1001) |
9 | 9 | firstName = Property(str, id=2, uid=1002) |
10 | 10 | lastName = Property(str, id=3, uid=1003) |
| 11 | + |
11 | 12 | def __init__(self): |
12 | 13 | self.counter = 0 |
| 14 | + |
13 | 15 | def fullname(self): |
14 | 16 | return f"{self.firstName} {self.lastName}" |
| 17 | + |
15 | 18 | def tick(self): |
16 | 19 | self.counter += 1 |
17 | | - |
| 20 | + |
18 | 21 | model = Model() |
19 | 22 | 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) |
21 | 24 | dbpath = "testdb" |
22 | 25 | Store.remove_db_files(dbpath) |
23 | | - store = Store(model = model, directory = dbpath) |
| 26 | + |
| 27 | + store = Store(model=model, directory=dbpath) |
24 | 28 | 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")) |
28 | 32 | assert box.count() == 3 |
29 | 33 | alice = box.get(id_alice) |
30 | 34 | assert alice.fullname() == "Alice Adkinson" |
31 | 35 | assert alice.counter == 0 |
32 | 36 | alice.tick() |
33 | 37 | alice.tick() |
34 | 38 | 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