mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Run tests on custom validators
This commit is contained in:
parent
b9dc4a0c2f
commit
08358f6961
38
InvenTree/InvenTree/tests.py
Normal file
38
InvenTree/InvenTree/tests.py
Normal file
@ -0,0 +1,38 @@
|
||||
from django.test import TestCase
|
||||
import django.core.exceptions as django_exceptions
|
||||
|
||||
from .validators import validate_overage, validate_part_name
|
||||
|
||||
class ValidatorTest(TestCase):
|
||||
|
||||
""" Simple tests for custom field validators """
|
||||
|
||||
def test_part_name(self):
|
||||
""" Test part name validator """
|
||||
|
||||
validate_part_name('hello world')
|
||||
|
||||
with self.assertRaises(django_exceptions.ValidationError):
|
||||
validate_part_name('This | name is not } valid')
|
||||
|
||||
def test_overage(self):
|
||||
""" Test overage validator """
|
||||
|
||||
validate_overage("100%")
|
||||
validate_overage("10")
|
||||
validate_overage("45.2 %")
|
||||
|
||||
with self.assertRaises(django_exceptions.ValidationError):
|
||||
validate_overage("-1")
|
||||
|
||||
with self.assertRaises(django_exceptions.ValidationError):
|
||||
validate_overage("-2.04 %")
|
||||
|
||||
with self.assertRaises(django_exceptions.ValidationError):
|
||||
validate_overage("105%")
|
||||
|
||||
with self.assertRaises(django_exceptions.ValidationError):
|
||||
validate_overage("xxx %")
|
||||
|
||||
with self.assertRaises(django_exceptions.ValidationError):
|
||||
validate_overage("aaaa")
|
Loading…
Reference in New Issue
Block a user