2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-03-16 00:50:56 +00:00

Initial unit tests for API

This commit is contained in:
Oliver Walters
2025-11-30 01:01:20 +00:00
parent 6f0379e861
commit ce7f6d218c
2 changed files with 70 additions and 1 deletions

View File

@@ -798,7 +798,7 @@ class ParameterSerializer(
mixin_class=InvenTreeParameterMixin,
label=_('Model Type'),
default='',
required=False,
allow_null=False,
)
updated_by_detail = enable_filter(

View File

@@ -0,0 +1,69 @@
"""API unit tests for InvenTree common functionality."""
from django.urls import reverse
from InvenTree.unit_test import InvenTreeAPITestCase
class ParameterAPITests(InvenTreeAPITestCase):
"""Tests for the Parameter API."""
roles = 'all'
def test_template_options(self):
"""Test OPTIONS information for the ParameterTemplate API endpoint."""
url = reverse('api-parameter-template-list')
options = self.options(url)
actions = options.data['actions']['GET']
for field in [
'pk',
'name',
'units',
'description',
'model_type',
'selectionlist',
'enabled',
]:
self.assertIn(
field,
actions.keys(),
f'Field "{field}" missing from ParameterTemplate API!',
)
model_types = [act['value'] for act in actions['model_type']['choices']]
for mdl in [
'part.part',
'build.build',
'company.company',
'order.purchaseorder',
]:
self.assertIn(
mdl,
model_types,
f'Model type "{mdl}" missing from ParameterTemplate API!',
)
def test_parameter_options(self):
"""Test OPTIONS information for the Parameter API endpoint."""
url = reverse('api-parameter-list')
options = self.options(url)
actions = options.data['actions']['GET']
for field in [
'pk',
'template',
'model_type',
'model_id',
'data',
'data_numeric',
]:
self.assertIn(
field, actions.keys(), f'Field "{field}" missing from Parameter API!'
)
self.assertFalse(actions['data']['read_only'])
self.assertFalse(actions['model_type']['read_only'])