mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 13:00:39 +03:00
Fix get_max_index to return 0 when nothing found
This commit is contained in:
parent
4d0ba713f3
commit
7d7016cc67
|
@ -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') \
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user