From e94592e42d83568fc21b16ae40a0c78a3cdd0aea Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 7 Apr 2020 12:09:25 +1000 Subject: [PATCH] Moar unit testing plz --- InvenTree/InvenTree/tests.py | 18 ++++++++++++++++++ Makefile | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/tests.py b/InvenTree/InvenTree/tests.py index 1fc660c7d8..75ece9748d 100644 --- a/InvenTree/InvenTree/tests.py +++ b/InvenTree/InvenTree/tests.py @@ -1,12 +1,18 @@ + +import os + from django.test import TestCase import django.core.exceptions as django_exceptions from django.core.exceptions import ValidationError from .validators import validate_overage, validate_part_name from . import helpers +from .settings import STATIC_ROOT from mptt.exceptions import InvalidMove +from decimal import Decimal + from stock.models import StockLocation @@ -48,6 +54,13 @@ class ValidatorTest(TestCase): class TestHelpers(TestCase): """ Tests for InvenTree helper functions """ + def test_is_image(self): + img = os.path.abspath(os.path.join(STATIC_ROOT, 'img/blank_image.png')) + self.assertTrue(helpers.TestIfImage(img)) + + css = os.path.abspath(os.path.join(STATIC_ROOT, 'css/inventree.css')) + self.assertFalse(helpers.TestIfImage(css)) + def test_image_url(self): """ Test if a filename looks like an image """ @@ -90,6 +103,11 @@ class TestHelpers(TestCase): self.assertEqual(helpers.getMediaUrl('xx/yy.png'), '/media/xx/yy.png') + def testDecimal2String(self): + + self.assertEqual(helpers.decimal2string(Decimal('1.2345000')), '1.2345') + self.assertEqual(helpers.decimal2string('test'), 'test') + class TestQuoteWrap(TestCase): """ Tests for string wrapping """ diff --git a/Makefile b/Makefile index cb38a601d8..32e1675b45 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ test: # Run code coverage coverage: cd InvenTree && python3 manage.py check - coverage run InvenTree/manage.py test build common company order part stock InvenTree + cd InvenTree && coverage run manage.py test build common company order part stock InvenTree coverage html # Install packages required to generate code docs