From 7ef0e7941e15c8c26e3ba9f5927c1736191fb1fe Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 29 Dec 2021 02:24:57 +0100 Subject: [PATCH] expand tests TDD for the win? --- InvenTree/InvenTree/tests.py | 40 +++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/InvenTree/InvenTree/tests.py b/InvenTree/InvenTree/tests.py index 06dcad9797..91b94deb1c 100644 --- a/InvenTree/InvenTree/tests.py +++ b/InvenTree/InvenTree/tests.py @@ -237,52 +237,68 @@ class TestSerialNumberExtraction(TestCase): e = helpers.extract_serial_numbers - sn = e("1-5", 5) - self.assertEqual(len(sn), 5) + sn = e("1-5", 5, 1) + self.assertEqual(len(sn), 5, 1) for i in range(1, 6): self.assertIn(i, sn) - sn = e("1, 2, 3, 4, 5", 5) + sn = e("1, 2, 3, 4, 5", 5, 1) self.assertEqual(len(sn), 5) - sn = e("1-5, 10-15", 11) + sn = e("1-5, 10-15", 11, 1) self.assertIn(3, sn) self.assertIn(13, sn) - sn = e("1+", 10) + sn = e("1+", 10, 1) self.assertEqual(len(sn), 10) self.assertEqual(sn, [_ for _ in range(1, 11)]) - sn = e("4, 1+2", 4) + sn = e("4, 1+2", 4, 1) self.assertEqual(len(sn), 4) self.assertEqual(sn, ["4", 1, 2, 3]) + sn = e("~", 1, 1) + self.assertEqual(len(sn), 1) + self.assertEqual(sn, [1]) + + sn = e("~", 1, 3) + self.assertEqual(len(sn), 1) + self.assertEqual(sn, [3]) + + sn = e("~+", 2, 5) + self.assertEqual(len(sn), 2) + self.assertEqual(sn, [5, 6]) + + sn = e("~+3", 2, 5) + self.assertEqual(len(sn), 4) + self.assertEqual(sn, [5, 6, 7, 8]) + def test_failures(self): e = helpers.extract_serial_numbers # Test duplicates with self.assertRaises(ValidationError): - e("1,2,3,3,3", 5) + e("1,2,3,3,3", 5, 1) # Test invalid length with self.assertRaises(ValidationError): - e("1,2,3", 5) + e("1,2,3", 5, 1) # Test empty string with self.assertRaises(ValidationError): - e(", , ,", 0) + e(", , ,", 0, 1) # Test incorrect sign in group with self.assertRaises(ValidationError): - e("10-2", 8) + e("10-2", 8, 1) # Test invalid group with self.assertRaises(ValidationError): - e("1-5-10", 10) + e("1-5-10", 10, 1) with self.assertRaises(ValidationError): - e("10, a, 7-70j", 4) + e("10, a, 7-70j", 4, 1) class TestVersionNumber(TestCase):