Skip to content

Commit 2b85863

Browse files
committed
idsync: fix test_empty_model unit test #25
1 parent df7030c commit 2b85863

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

tests/test_idsync.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import json
88
from pprint import pprint
99
import os
10+
from os import path
1011
import tests.model
1112
import pytest
1213

@@ -17,7 +18,7 @@ class _TestEnv:
1718
"""
1819
def __init__(self):
1920
self.model_path = 'test.json'
20-
if os.path.exists(self.model_path):
21+
if path.exists(self.model_path):
2122
os.remove(self.model_path)
2223
self.model = None
2324
self.db_path = 'testdb'
@@ -47,21 +48,41 @@ def reset_ids(entity: _Entity):
4748
def env():
4849
return _TestEnv()
4950

50-
def test_empty(env):
51+
52+
def test_empty_model(env):
53+
""" Tests situations where the user attempts to sync an empty model. """
54+
55+
# JSON file didn't exist, user syncs an empty model -> no JSON file is generated
5156
model = Model()
52-
env.sync(model)
57+
assert not env.sync(model)
58+
assert not path.exists(env.model_path)
59+
60+
# Init the JSON file with an entity
61+
@Entity()
62+
class MyEntity:
63+
id = Id()
64+
model = Model()
65+
model.entity(MyEntity)
66+
assert env.sync(model) # Model JSON written
67+
68+
# JSON file exists, user syncs an empty model -> JSON file is written but entities are cleared (last ID/UID
69+
# retained)
70+
model = Model()
71+
assert env.sync(model)
72+
5373
doc = env.json()
5474
assert doc['_note1']
5575
assert doc['_note2']
5676
assert doc['_note3']
5777
assert len(doc['entities']) == 0
58-
assert doc['lastEntityId'] == '0:0'
59-
assert doc['lastIndexId'] == '0:0' # NOTE: objectbox-generator outputs ""
78+
# Last entity ID/UID will still be set at MyEntity's ID/UID
79+
# assert doc['lastEntityId'] == '0:0'
80+
# assert doc['lastIndexId'] == '0:0' # NOTE: objectbox-generator outputs ""
6081
assert doc['modelVersionParserMinimum'] >= 5
6182
# debug: pprint(doc)
6283
#
6384
# TODO: sync with objectbox-generator empty fbs
64-
# assert doc['modelVersion'] == 5
85+
# assert doc['modelVersion'] == 5
6586
# assert doc['lastIndex'] == ""
6687
# assert doc['lastRelationId'] == ""
6788
# assert len(doc['retiredEntityUids']) == 0

0 commit comments

Comments
 (0)