Skip to content

Commit

Permalink
Add test-case for sort models behavior, refs #2893
Browse files Browse the repository at this point in the history
This is working well, need to adapt the code for the delete instance
code.
  • Loading branch information
coleifer committed May 14, 2024
1 parent c7c6201 commit b7e40dd
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/db_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,35 @@ class E(Model):
sorted_models = sort_models(list_of_models)
self.assertEqual(sorted_models, models)

def test_sort_models_multi_fk(self):
class Inventory(Model):
pass
class Sheet(Model):
inventory = ForeignKeyField(Inventory)
class Program(Model):
inventory = ForeignKeyField(Inventory)
class ProgramSheet(Model):
program = ForeignKeyField(Program)
sheet = ForeignKeyField(Sheet)
class ProgramPart(Model):
program_sheet = ForeignKeyField(ProgramSheet)
class Offal(Model):
program_sheet = ForeignKeyField(ProgramSheet)
sheet = ForeignKeyField(Sheet)

M = [Inventory, Sheet, Program, ProgramSheet, ProgramPart, Offal]
sorted_models = sort_models(M)
self.assertEqual(sorted_models, [
Inventory,
Program,
Sheet,
ProgramSheet,
Offal,
ProgramPart,
])
for list_of_models in permutations(M):
self.assertEqual(sort_models(list_of_models), sorted_models)


class TestDBProxy(BaseTestCase):
def test_proxy_context_manager(self):
Expand Down

0 comments on commit b7e40dd

Please sign in to comment.