From 6d2cd78d292427b191684deff5ed8a31ab7a0001 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 22 Jun 2021 10:36:04 +1000 Subject: [PATCH] Fixes for unit tests --- InvenTree/part/models.py | 2 +- InvenTree/part/test_part.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 43e54baf91..8ddf049216 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -382,7 +382,7 @@ class Part(MPTTModel): logger.info(f"Deleting unused image file '{previous.image}'") previous.image.delete(save=False) - self.clean() + self.full_clean() super().save(*args, **kwargs) diff --git a/InvenTree/part/test_part.py b/InvenTree/part/test_part.py index b8a379d241..e30c80549f 100644 --- a/InvenTree/part/test_part.py +++ b/InvenTree/part/test_part.py @@ -332,21 +332,24 @@ class PartSettingsTest(TestCase): """ # Create a part - Part.objects.create(name='Hello', description='A thing', IPN='IPN123') + Part.objects.create(name='Hello', description='A thing', IPN='IPN123', revision='A') # Attempt to create a duplicate item (should fail) with self.assertRaises(ValidationError): - Part.objects.create(name='Hello', description='A thing', IPN='IPN123') + part = Part(name='Hello', description='A thing', IPN='IPN123', revision='A') + part.validate_unique() # Attempt to create item with duplicate IPN (should be allowed by default) Part.objects.create(name='Hello', description='A thing', IPN='IPN123', revision='B') # And attempt again with the same values (should fail) with self.assertRaises(ValidationError): - Part.objects.create(name='Hello', description='A thing', IPN='IPN123', revision='B') + part = Part(name='Hello', description='A thing', IPN='IPN123', revision='B') + part.validate_unique() # Now update the settings so duplicate IPN values are *not* allowed InvenTreeSetting.set_setting('PART_ALLOW_DUPLICATE_IPN', False, self.user) with self.assertRaises(ValidationError): - Part.objects.create(name='Hello', description='A thing', IPN='IPN123', revision='C') + part = Part(name='Hello', description='A thing', IPN='IPN123', revision='C') + part.full_clean()