Add unit test for invalid characters

This commit is contained in:
Oliver Walters 2019-09-13 11:15:54 +10:00
parent 844f337d64
commit 8716281f7e

View File

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