From 08358f69614b6dc0908640b22fee5880620cf8ef Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 17 Jun 2019 22:18:00 +1000 Subject: [PATCH] Run tests on custom validators --- InvenTree/InvenTree/tests.py | 38 ++++++++++++++++++++++++++++++++++++ InvenTree/order/__init__.py | 2 +- Makefile | 2 +- 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 InvenTree/InvenTree/tests.py diff --git a/InvenTree/InvenTree/tests.py b/InvenTree/InvenTree/tests.py new file mode 100644 index 0000000000..1631d7bd96 --- /dev/null +++ b/InvenTree/InvenTree/tests.py @@ -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") diff --git a/InvenTree/order/__init__.py b/InvenTree/order/__init__.py index c7ef040fb8..896e9facd5 100644 --- a/InvenTree/order/__init__.py +++ b/InvenTree/order/__init__.py @@ -1,3 +1,3 @@ """ The Order module is responsible for managing Orders -""" \ No newline at end of file +""" diff --git a/Makefile b/Makefile index e97ddc9732..cdef6b87c4 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ test: coverage: python3 InvenTree/manage.py check - coverage run InvenTree/manage.py test build company part stock order + coverage run InvenTree/manage.py test build company part stock order InvenTree coverage html documentation: