Fixes for unit tests

This commit is contained in:
Oliver 2021-06-22 10:36:04 +10:00
parent 9475af62ae
commit 6d2cd78d29
2 changed files with 8 additions and 5 deletions

View File

@ -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)

View File

@ -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()