mirror of
https://github.com/inventree/InvenTree.git
synced 2025-10-23 17:37:38 +00:00
[API] Bug fix for FilterableSerializerMixin (#10632)
- Handle case where data is being exported
This commit is contained in:
@@ -6,6 +6,7 @@ from rest_framework import generics, mixins, status
|
|||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
import data_exporter.mixins
|
import data_exporter.mixins
|
||||||
|
import data_exporter.serializers
|
||||||
import importer.mixins
|
import importer.mixins
|
||||||
from InvenTree.fields import InvenTreeNotesField, OutputConfiguration
|
from InvenTree.fields import InvenTreeNotesField, OutputConfiguration
|
||||||
from InvenTree.helpers import (
|
from InvenTree.helpers import (
|
||||||
@@ -231,7 +232,12 @@ class OutputOptionsMixin:
|
|||||||
serializer = super().get_serializer(*args, **kwargs)
|
serializer = super().get_serializer(*args, **kwargs)
|
||||||
|
|
||||||
# Check if the serializer actually can be filtered - makes not much sense to use this mixin without that prerequisite
|
# Check if the serializer actually can be filtered - makes not much sense to use this mixin without that prerequisite
|
||||||
if not isinstance(serializer, FilterableSerializerMixin):
|
if isinstance(
|
||||||
|
serializer, data_exporter.serializers.DataExportOptionsSerializer
|
||||||
|
):
|
||||||
|
# Skip in this instance, special case for determining export options
|
||||||
|
pass
|
||||||
|
elif not isinstance(serializer, FilterableSerializerMixin):
|
||||||
raise Exception(
|
raise Exception(
|
||||||
'INVE-I2: `OutputOptionsMixin` can only be used with serializers that contain the `FilterableSerializerMixin` mixin'
|
'INVE-I2: `OutputOptionsMixin` can only be used with serializers that contain the `FilterableSerializerMixin` mixin'
|
||||||
)
|
)
|
||||||
|
@@ -3339,3 +3339,27 @@ class PartTestTemplateTest(PartAPITestBase):
|
|||||||
response = self.patch(url, {'choices': 'a,b,c,d,e,f,f'}, expected_code=400)
|
response = self.patch(url, {'choices': 'a,b,c,d,e,f,f'}, expected_code=400)
|
||||||
|
|
||||||
self.assertIn('Choices must be unique', str(response.data['choices']))
|
self.assertIn('Choices must be unique', str(response.data['choices']))
|
||||||
|
|
||||||
|
|
||||||
|
class PartParameterTests(PartAPITestBase):
|
||||||
|
"""Unit test for PartParameter API endpoints."""
|
||||||
|
|
||||||
|
def test_export_data(self):
|
||||||
|
"""Test data export functionality for PartParameter objects."""
|
||||||
|
url = reverse('api-part-parameter-list')
|
||||||
|
|
||||||
|
response = self.options(
|
||||||
|
url,
|
||||||
|
data={
|
||||||
|
'export': True,
|
||||||
|
'export_plugin': 'inventree-exporter',
|
||||||
|
'part_detail': True,
|
||||||
|
'template_detail': True,
|
||||||
|
},
|
||||||
|
expected_code=200,
|
||||||
|
)
|
||||||
|
|
||||||
|
fields = response.data['actions']['GET'].keys()
|
||||||
|
|
||||||
|
self.assertIn('export_format', fields)
|
||||||
|
self.assertIn('export_plugin', fields)
|
||||||
|
Reference in New Issue
Block a user