mirror of
https://github.com/inventree/InvenTree.git
synced 2025-12-14 08:19:54 +00:00
Add fixtures / unit testing for the stock item testing framework
This commit is contained in:
@@ -5,10 +5,11 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.test import TestCase
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
import os
|
||||
|
||||
from .models import Part
|
||||
from .models import Part, PartTestTemplate
|
||||
from .models import rename_part_image, match_part_names
|
||||
from .templatetags import inventree_extras
|
||||
|
||||
@@ -105,3 +106,61 @@ class PartTest(TestCase):
|
||||
matches = match_part_names('M2x5 LPHS')
|
||||
|
||||
self.assertTrue(len(matches) > 0)
|
||||
|
||||
|
||||
class TestTemplateTest(TestCase):
|
||||
|
||||
fixtures = [
|
||||
'category',
|
||||
'part',
|
||||
'location',
|
||||
'test_templates',
|
||||
]
|
||||
|
||||
def test_template_count(self):
|
||||
|
||||
chair = Part.objects.get(pk=10000)
|
||||
|
||||
# Tests for the top-level chair object (nothing above it!)
|
||||
self.assertEqual(chair.test_templates.count(), 5)
|
||||
self.assertEqual(chair.getTestTemplates().count(), 5)
|
||||
self.assertEqual(chair.getTestTemplates(required=True).count(), 4)
|
||||
self.assertEqual(chair.getTestTemplates(required=False).count(), 1)
|
||||
|
||||
# Test the lowest-level part which has more associated tests
|
||||
variant = Part.objects.get(pk=10004)
|
||||
|
||||
self.assertEqual(variant.getTestTemplates().count(), 7)
|
||||
self.assertEqual(variant.getTestTemplates(include_parent=False).count(), 1)
|
||||
self.assertEqual(variant.getTestTemplates(required=True).count(), 5)
|
||||
|
||||
def test_uniqueness(self):
|
||||
# Test names must be unique for this part and also parts above
|
||||
|
||||
variant = Part.objects.get(pk=10004)
|
||||
|
||||
with self.assertRaises(ValidationError):
|
||||
PartTestTemplate.objects.create(
|
||||
part=variant,
|
||||
test_name='Record weight'
|
||||
)
|
||||
|
||||
with self.assertRaises(ValidationError):
|
||||
PartTestTemplate.objects.create(
|
||||
part=variant,
|
||||
test_name='Check that chair is especially green'
|
||||
)
|
||||
|
||||
# Also should fail if we attempt to create a test that would generate the same key
|
||||
with self.assertRaises(ValidationError):
|
||||
PartTestTemplate.objects.create(
|
||||
part=variant,
|
||||
test_name='ReCoRD weiGHT '
|
||||
)
|
||||
|
||||
# But we should be able to create a new one!
|
||||
n = variant.getTestTemplates().count()
|
||||
|
||||
PartTestTemplate.objects.create(part=variant, test_name='A Sample Test')
|
||||
|
||||
self.assertEqual(variant.getTestTemplates().count(), n + 1)
|
||||
Reference in New Issue
Block a user