diff --git a/rsconcept/backend/apps/rsform/models/api_RSForm.py b/rsconcept/backend/apps/rsform/models/api_RSForm.py index 957e8bf1..76dfb4ff 100644 --- a/rsconcept/backend/apps/rsform/models/api_RSForm.py +++ b/rsconcept/backend/apps/rsform/models/api_RSForm.py @@ -77,7 +77,7 @@ class RSForm: def get_max_index(self, cst_type: CstType) -> int: ''' Get maximum alias index for specific CstType ''' - result: int = 1 + result: int = 0 items = Constituenta.objects \ .filter(schema=self.item, cst_type=cst_type) \ .order_by('-alias') \ diff --git a/rsconcept/backend/apps/rsform/tests/t_models.py b/rsconcept/backend/apps/rsform/tests/t_models.py index e77218f1..7b852e23 100644 --- a/rsconcept/backend/apps/rsform/tests/t_models.py +++ b/rsconcept/backend/apps/rsform/tests/t_models.py @@ -160,6 +160,14 @@ class TestRSForm(TestCase): self.assertFalse(schema2.constituents().exists()) self.assertEqual(schema1.constituents().count(), 2) + def test_get_max_index(self): + schema1 = RSForm.create(title='Test1') + Constituenta.objects.create(alias='X1', schema=schema1.item, order=1) + Constituenta.objects.create(alias='D2', cst_type=CstType.TERM, schema=schema1.item, order=2) + self.assertEqual(schema1.get_max_index(CstType.BASE), 1) + self.assertEqual(schema1.get_max_index(CstType.TERM), 2) + self.assertEqual(schema1.get_max_index(CstType.AXIOM), 0) + def test_insert_at(self): schema = RSForm.create(title='Test') cst1 = schema.insert_at(1, 'X1', CstType.BASE)