From 844f337d64f2aa59e479028022f8c1ae57719778 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 13 Sep 2019 11:15:11 +1000 Subject: [PATCH 1/2] Fix ValidationError call for validate_tree_name function --- InvenTree/InvenTree/validators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/validators.py b/InvenTree/InvenTree/validators.py index 36eda4d451..4fbcf44b1c 100644 --- a/InvenTree/InvenTree/validators.py +++ b/InvenTree/InvenTree/validators.py @@ -22,7 +22,7 @@ def validate_tree_name(value): for c in "!@#$%^&*'\"\\/[]{}<>,|+=~`\"": 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): From 8716281f7ef781ad02a3f1d853e59a9b0a5de1b4 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 13 Sep 2019 11:15:54 +1000 Subject: [PATCH 2/2] Add unit test for invalid characters --- InvenTree/part/test_category.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/InvenTree/part/test_category.py b/InvenTree/part/test_category.py index db95836107..abd5669016 100644 --- a/InvenTree/part/test_category.py +++ b/InvenTree/part/test_category.py @@ -1,4 +1,5 @@ from django.test import TestCase +from django.core.exceptions import ValidationError from .models import Part, PartCategory @@ -93,6 +94,20 @@ class CategoryTest(TestCase): 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): """ Test that category deletion moves the children properly """