From 8716281f7ef781ad02a3f1d853e59a9b0a5de1b4 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 13 Sep 2019 11:15:54 +1000 Subject: [PATCH] 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 """