mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Test template fix (#8031)
* Fix restriction for PartTestTemplate - limit_choices_to should be "testable", not "trackable" - ref: https://github.com/inventree/InvenTree/pull/7888 * Add migration file * Fix validation check * Fix API filter * Fix for test fixture * Fix another test * Fixture data * Fix comment * More fixes * More fixes * Moar fix plz thx
This commit is contained in:
parent
368d59ee55
commit
3961e48fe8
@ -55,6 +55,7 @@ class BuildTestBase(TestCase):
|
|||||||
description="Why does it matter what my description is?",
|
description="Why does it matter what my description is?",
|
||||||
assembly=True,
|
assembly=True,
|
||||||
trackable=True,
|
trackable=True,
|
||||||
|
testable=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# create one build with one required test template
|
# create one build with one required test template
|
||||||
@ -63,6 +64,7 @@ class BuildTestBase(TestCase):
|
|||||||
description="Why does it matter what my description is?",
|
description="Why does it matter what my description is?",
|
||||||
assembly=True,
|
assembly=True,
|
||||||
trackable=True,
|
trackable=True,
|
||||||
|
testable=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
cls.test_template_required = PartTestTemplate.objects.create(
|
cls.test_template_required = PartTestTemplate.objects.create(
|
||||||
@ -98,6 +100,7 @@ class BuildTestBase(TestCase):
|
|||||||
description="Why does it matter what my description is?",
|
description="Why does it matter what my description is?",
|
||||||
assembly=True,
|
assembly=True,
|
||||||
trackable=True,
|
trackable=True,
|
||||||
|
testable=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
cls.test_template_non_required = PartTestTemplate.objects.create(
|
cls.test_template_non_required = PartTestTemplate.objects.create(
|
||||||
|
@ -415,7 +415,7 @@ class PartTestTemplateFilter(rest_filters.FilterSet):
|
|||||||
fields = ['enabled', 'key', 'required', 'requires_attachment', 'requires_value']
|
fields = ['enabled', 'key', 'required', 'requires_attachment', 'requires_value']
|
||||||
|
|
||||||
part = rest_filters.ModelChoiceFilter(
|
part = rest_filters.ModelChoiceFilter(
|
||||||
queryset=Part.objects.filter(trackable=True),
|
queryset=Part.objects.filter(testable=True),
|
||||||
label='Part',
|
label='Part',
|
||||||
field_name='part',
|
field_name='part',
|
||||||
method='filter_part',
|
method='filter_part',
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
creation_date: '2018-01-01'
|
creation_date: '2018-01-01'
|
||||||
tree_id: 0
|
tree_id: 0
|
||||||
purchaseable: True
|
purchaseable: True
|
||||||
|
testable: False
|
||||||
level: 0
|
level: 0
|
||||||
lft: 0
|
lft: 0
|
||||||
rght: 0
|
rght: 0
|
||||||
@ -78,6 +79,7 @@
|
|||||||
salable: true
|
salable: true
|
||||||
assembly: true
|
assembly: true
|
||||||
trackable: true
|
trackable: true
|
||||||
|
testable: true
|
||||||
tree_id: 0
|
tree_id: 0
|
||||||
level: 0
|
level: 0
|
||||||
lft: 0
|
lft: 0
|
||||||
@ -136,7 +138,8 @@
|
|||||||
name: 'Chair Template'
|
name: 'Chair Template'
|
||||||
description: 'A chair, which is actually just a template part'
|
description: 'A chair, which is actually just a template part'
|
||||||
is_template: True
|
is_template: True
|
||||||
trackable: true
|
trackable: false
|
||||||
|
testable: true
|
||||||
creation_date: '2027-10-10'
|
creation_date: '2027-10-10'
|
||||||
salable: true
|
salable: true
|
||||||
category: 7
|
category: 7
|
||||||
@ -151,7 +154,8 @@
|
|||||||
name: 'Blue Chair'
|
name: 'Blue Chair'
|
||||||
description: 'A variant chair part which is blue'
|
description: 'A variant chair part which is blue'
|
||||||
variant_of: 10000
|
variant_of: 10000
|
||||||
trackable: true
|
trackable: false
|
||||||
|
testable: true
|
||||||
creation_date: '2028-11-11'
|
creation_date: '2028-11-11'
|
||||||
category: 7
|
category: 7
|
||||||
tree_id: 1
|
tree_id: 1
|
||||||
@ -166,7 +170,8 @@
|
|||||||
description: 'A variant chair part which is red'
|
description: 'A variant chair part which is red'
|
||||||
variant_of: 10000
|
variant_of: 10000
|
||||||
IPN: "R.CH"
|
IPN: "R.CH"
|
||||||
trackable: true
|
trackable: false
|
||||||
|
testable: true
|
||||||
salable: true
|
salable: true
|
||||||
creation_date: '2029-12-12'
|
creation_date: '2029-12-12'
|
||||||
category: 7
|
category: 7
|
||||||
@ -183,7 +188,8 @@
|
|||||||
variant_of: 10000
|
variant_of: 10000
|
||||||
is_template: true
|
is_template: true
|
||||||
category: 7
|
category: 7
|
||||||
trackable: true
|
trackable: false
|
||||||
|
testable: true
|
||||||
creation_date: '2030-01-01'
|
creation_date: '2030-01-01'
|
||||||
tree_id: 1
|
tree_id: 1
|
||||||
level: 0
|
level: 0
|
||||||
@ -200,6 +206,7 @@
|
|||||||
category: 7
|
category: 7
|
||||||
creation_date: '2031-02-02'
|
creation_date: '2031-02-02'
|
||||||
trackable: true
|
trackable: true
|
||||||
|
testable: true
|
||||||
tree_id: 1
|
tree_id: 1
|
||||||
level: 0
|
level: 0
|
||||||
lft: 0
|
lft: 0
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.15 on 2024-08-29 03:24
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('part', '0129_auto_20240815_0214'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='parttesttemplate',
|
||||||
|
name='part',
|
||||||
|
field=models.ForeignKey(limit_choices_to={'testable': True}, on_delete=django.db.models.deletion.CASCADE, related_name='test_templates', to='part.part', verbose_name='Part'),
|
||||||
|
),
|
||||||
|
]
|
@ -3582,9 +3582,9 @@ class PartTestTemplate(InvenTree.models.InvenTreeMetadataModel):
|
|||||||
|
|
||||||
def validate_unique(self, exclude=None):
|
def validate_unique(self, exclude=None):
|
||||||
"""Test that this test template is 'unique' within this part tree."""
|
"""Test that this test template is 'unique' within this part tree."""
|
||||||
if not self.part.trackable:
|
if not self.part.testable:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'part': _('Test templates can only be created for trackable parts')
|
'part': _('Test templates can only be created for testable parts')
|
||||||
})
|
})
|
||||||
|
|
||||||
# Check that this test is unique within the part tree
|
# Check that this test is unique within the part tree
|
||||||
@ -3605,7 +3605,7 @@ class PartTestTemplate(InvenTree.models.InvenTreeMetadataModel):
|
|||||||
Part,
|
Part,
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
related_name='test_templates',
|
related_name='test_templates',
|
||||||
limit_choices_to={'trackable': True},
|
limit_choices_to={'testable': True},
|
||||||
verbose_name=_('Part'),
|
verbose_name=_('Part'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2996,7 +2996,7 @@ class PartTestTemplateTest(PartAPITestBase):
|
|||||||
expected_code=400,
|
expected_code=400,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Try to post a new test against a non-trackable part (should fail)
|
# Try to post a new test against a non-testable part (should fail)
|
||||||
response = self.post(
|
response = self.post(
|
||||||
url, data={'part': 1, 'test_name': 'A simple test'}, expected_code=400
|
url, data={'part': 1, 'test_name': 'A simple test'}, expected_code=400
|
||||||
)
|
)
|
||||||
|
@ -1784,9 +1784,9 @@ class StockTestResultTest(StockAPITestCase):
|
|||||||
|
|
||||||
stock_item = StockItem.objects.get(pk=1)
|
stock_item = StockItem.objects.get(pk=1)
|
||||||
|
|
||||||
# Ensure the part is marked as "trackable"
|
# Ensure the part is marked as "testable"
|
||||||
p = stock_item.part
|
p = stock_item.part
|
||||||
p.trackable = True
|
p.testable = True
|
||||||
p.save()
|
p.save()
|
||||||
|
|
||||||
# Create some objects (via the API)
|
# Create some objects (via the API)
|
||||||
@ -1799,7 +1799,6 @@ class StockTestResultTest(StockAPITestCase):
|
|||||||
'result': True,
|
'result': True,
|
||||||
'value': 'Test result value',
|
'value': 'Test result value',
|
||||||
},
|
},
|
||||||
# expected_code=201,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
tests.append(response.data['pk'])
|
tests.append(response.data['pk'])
|
||||||
|
Loading…
Reference in New Issue
Block a user