Merge remote-tracking branch 'inventree/master'

This commit is contained in:
Oliver Walters 2019-09-13 11:20:39 +10:00
commit 9681372a84
2 changed files with 16 additions and 1 deletions

View File

@ -22,7 +22,7 @@ def validate_tree_name(value):
for c in "!@#$%^&*'\"\\/[]{}<>,|+=~`\"": for c in "!@#$%^&*'\"\\/[]{}<>,|+=~`\"":
if c in str(value): if c in str(value):
raise ValidationError({'name': _('Illegal character in name')}) raise ValidationError(_('Illegal character in name ({x})'.format(x=c)))
def validate_overage(value): def validate_overage(value):

View File

@ -1,4 +1,5 @@
from django.test import TestCase from django.test import TestCase
from django.core.exceptions import ValidationError
from .models import Part, PartCategory from .models import Part, PartCategory
@ -93,6 +94,20 @@ class CategoryTest(TestCase):
self.assertEqual(self.electronics.item_count, self.electronics.partcount()) self.assertEqual(self.electronics.item_count, self.electronics.partcount())
def test_invalid_name(self):
# Test that an illegal character is prohibited in a category name
cat = PartCategory(name='test/with/illegal/chars', description='Test category', parent=None)
with self.assertRaises(ValidationError) as err:
cat.full_clean()
cat.save()
self.assertIn('Illegal character in name', str(err.exception.error_dict.get('name')))
cat.name = 'good name'
cat.save()
def test_delete(self): def test_delete(self):
""" Test that category deletion moves the children properly """ """ Test that category deletion moves the children properly """