From b7bbc972182a4e4660ee3eece7f5812abf450c47 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 14 Jan 2021 08:32:37 +1100 Subject: [PATCH] Add unit test --- InvenTree/InvenTree/helpers.py | 2 +- InvenTree/label/tests.py | 75 +++++++++++++++++++++++++++++++++- 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index e65e67951e..6b76c7d41b 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -467,7 +467,7 @@ def validateFilterString(value, model=None): # If a model is provided, verify that the provided filters can be used against it if model is not None: try: - query = model.objects.filter(**results) + model.objects.filter(**results) except FieldError as e: raise ValidationError( str(e), diff --git a/InvenTree/label/tests.py b/InvenTree/label/tests.py index a39b155ac3..442fdb53aa 100644 --- a/InvenTree/label/tests.py +++ b/InvenTree/label/tests.py @@ -1 +1,74 @@ -# Create your tests here. +# Tests for Part Parameters + +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +import os + +from django.test import TestCase +from django.conf import settings +from django.core.exceptions import ValidationError + +from InvenTree.helpers import validateFilterString + +from .models import StockItemLabel, StockLocationLabel +from stock.models import StockItem + + +class LabelTest(TestCase): + + def _test_default_labels(self): + """ + Test that the default label templates are copied across + """ + + labels = StockItemLabel.objects.all() + + self.assertTrue(labels.count() > 0) + + labels = StockLocationLabel.objects.all() + + self.assertTrue(labels.count() > 0) + + def _test_default_files(self): + """ + Test that label files exist in the MEDIA directory + """ + + item_dir = os.path.join( + settings.MEDIA_ROOT, + 'label', + 'inventree', + 'stockitem', + ) + + files = os.listdir(item_dir) + + self.assertTrue(len(files) > 0) + + loc_dir = os.path.join( + settings.MEDIA_ROOT, + 'label', + 'inventree', + 'stocklocation', + ) + + files = os.listdir(loc_dir) + + self.assertTrue(len(files) > 0) + + def test_filters(self): + """ + Test the label filters + """ + + filter_string = "part__pk=10" + + filters = validateFilterString(filter_string, model=StockItem) + + self.assertEqual(type(filters), dict) + + bad_filter_string = "part_pk=10" + + with self.assertRaises(ValidationError): + validateFilterString(bad_filter_string, model=StockItem)