Skip to content

Commit 39ce56f

Browse files
committed
Update tests and todo description
1 parent 52a1126 commit 39ce56f

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- [x] Customize prefix in validator (default=`!`)
99
- [x] relationship entity no longer required `model` key since the program will search it for you, but can also be
1010
overridden by providing a model data instead as it saves performance time
11-
- [ ] Add test case for overriding default reference prefix
11+
- [x] Add test case for overriding default reference prefix
1212
- [ ] Update README description
1313
- [ ] add docstrings
1414
- [ ] Refactor test instances and test cases

tests/test_seeder.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,45 @@ def test_hybrid_seed_parent_to_child_with_ref_relationship_no_model(self):
228228
seeder = HybridSeeder(session)
229229
self.assertIsNone(seeder.seed(ins.HYBRID_SEED_PARENT_TO_CHILD_WITH_REF_RELATIONSHIP_NO_MODEL))
230230
print(session.new, session.dirty)
231+
232+
class TestSeederCostumizedPrefix(unittest.TestCase):
233+
def setUp(self) -> None:
234+
self.engine = create_engine('sqlite://')
235+
self.Session = sessionmaker(bind=self.engine)
236+
Base.metadata.create_all(self.engine)
237+
238+
def test_seeder_parent_to_child(self):
239+
import json
240+
custom_instance = json.dumps(ins.PARENT_TO_CHILD)
241+
custom_instance = custom_instance.replace('!', '@')
242+
custom_instance = json.loads(custom_instance)
243+
244+
with self.Session() as session:
245+
seeder = Seeder(session, ref_prefix='@')
246+
seeder.seed(custom_instance)
247+
employee = seeder.instances[0]
248+
self.assertIsNotNone(employee.company)
249+
250+
def test_hybrid_seeder_parent_to_child_with_ref_column(self):
251+
import json
252+
custom_instance = json.dumps(ins.HYBRID_SEED_PARENT_TO_CHILD_WITH_REF_COLUMN)
253+
custom_instance = custom_instance.replace('!', '@')
254+
custom_instance = json.loads(custom_instance)
255+
256+
with self.Session() as session:
257+
seeder = HybridSeeder(session, ref_prefix='@')
258+
seeder.seed(custom_instance)
259+
employee = seeder.instances[1]
260+
self.assertIsNotNone(employee.company)
261+
262+
def test_hybrid_seeder_parent_to_child_with_ref_relationship(self):
263+
import json
264+
custom_instance = json.dumps(ins.HYBRID_SEED_PARENT_TO_CHILD_WITH_REF_RELATIONSHIP)
265+
custom_instance = custom_instance.replace('!', '@')
266+
custom_instance = json.loads(custom_instance)
267+
268+
with self.Session() as session:
269+
seeder = HybridSeeder(session, ref_prefix='@')
270+
seeder.seed(custom_instance)
271+
employee = seeder.instances[1]
272+
self.assertIsNotNone(employee.company)

0 commit comments

Comments
 (0)