mirror of
https://github.com/inventree/InvenTree.git
synced 2026-04-04 10:31:03 +00:00
Initial unit tests for API
This commit is contained in:
@@ -798,7 +798,7 @@ class ParameterSerializer(
|
|||||||
mixin_class=InvenTreeParameterMixin,
|
mixin_class=InvenTreeParameterMixin,
|
||||||
label=_('Model Type'),
|
label=_('Model Type'),
|
||||||
default='',
|
default='',
|
||||||
required=False,
|
allow_null=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
updated_by_detail = enable_filter(
|
updated_by_detail = enable_filter(
|
||||||
|
|||||||
69
src/backend/InvenTree/common/test_api.py
Normal file
69
src/backend/InvenTree/common/test_api.py
Normal 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'])
|
||||||
Reference in New Issue
Block a user