From ad3ab2e9933406072a5bdcb77dfff50a5b814315 Mon Sep 17 00:00:00 2001 From: Oliver Zander Date: Fri, 17 Oct 2025 10:28:08 +0200 Subject: [PATCH] made tests robust against changing order --- input/tests/models.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/input/tests/models.py b/input/tests/models.py index 0e7f50c..7d608bd 100755 --- a/input/tests/models.py +++ b/input/tests/models.py @@ -11,6 +11,15 @@ class ModelTestCase(TestCase): def setUpTestData(cls): cls.account = Account.objects.create(code='1234', description='blabla') + def assertLen(self, value, length, msg=None): + self.assertEqual(len(value), length, msg) + + def assertStartsWith(self, value, start, msg=None): + self.assertTrue(f'{value}'.startswith(f'{start}'), msg) + + def assertEndsWith(self, value, end, msg=None): + self.assertTrue(f'{value}'.endswith(f'{end}'), msg) + def test_set_granted(self): """ test if the model function set_granted() works as intended """ obj = HonoraryCertificate.objects.create(realname='hurzel', email='hurzel@web.de') @@ -72,17 +81,18 @@ class ModelTestCase(TestCase): acc = self.account startdate = date(2022, 1, 1) obj = Project.objects.create(account=acc, name='testproject', start=startdate) - self.assertEqual(obj.pid, "123400000001") - self.assertEqual(obj.account.code, "1234") + self.assertLen(obj.pid, len(acc.code) + 8) + self.assertStartsWith(obj.pid, acc.code) + self.assertEndsWith(obj.pid, obj.id) obj2 = Project.objects.create(account=acc, name='testproject2', start=startdate) - self.assertEqual(obj2.pid, "123400000002") + self.assertEndsWith(obj2.pid, obj.id + 1) olddate = date(2021, 12, 31) - obj4 = Project.objects.create(account=acc, name='testproject2', start=olddate) + Project.objects.create(account=acc, name='testproject2', start=olddate) - obj3 = Project.objects.create(account=acc, name='testproject2', start=startdate) - self.assertEqual(obj3.pid, "123400000004") + obj4 = Project.objects.create(account=acc, name='testproject2', start=startdate) + self.assertEndsWith(obj4.pid, obj.id + 3) def test_literature(self): obj = Literature.objects.create(cost='100', notes='jolo', selfbuy_give_data=False)