diff --git a/InvenTree/plugin/test_helpers.py b/InvenTree/plugin/test_helpers.py new file mode 100644 index 0000000000..9ed0ff16fe --- /dev/null +++ b/InvenTree/plugin/test_helpers.py @@ -0,0 +1,23 @@ +"""Unit tests for helpers.py""" + +from django.test import TestCase + +from .helpers import render_template + + +class HelperTests(TestCase): + """Tests for helpers""" + + def test_render_template(self): + """Check if render_template helper works""" + class ErrorSource: + slug = 'sampleplg' + + # working sample + response = render_template(ErrorSource(), 'sample/sample.html', {'abc': 123} ) + self.assertEqual(response, '

123

') + + # Wrong sample + response = render_template(ErrorSource(), 'sample/wrongsample.html', {'abc': 123} ) + self.assertTrue('lert alert-block alert-danger' in response) + self.assertTrue('Template file sample/wrongsample.html' in response) diff --git a/InvenTree/templates/sample/sample.html b/InvenTree/templates/sample/sample.html new file mode 100644 index 0000000000..0db05e3152 --- /dev/null +++ b/InvenTree/templates/sample/sample.html @@ -0,0 +1 @@ +

{{abc}}

\ No newline at end of file