mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-01 04:56:45 +00:00
Raise error if no search term provided for search endpoint (#5441)
- Also adjust unit testing
This commit is contained in:
parent
93e4dadb49
commit
5731b88499
@ -287,6 +287,11 @@ class APISearchView(APIView):
|
|||||||
'offset': 0,
|
'offset': 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if 'search' not in data:
|
||||||
|
raise ValidationError({
|
||||||
|
'search': 'Search term must be provided',
|
||||||
|
})
|
||||||
|
|
||||||
for key, cls in self.get_result_types().items():
|
for key, cls in self.get_result_types().items():
|
||||||
# Only return results which are specifically requested
|
# Only return results which are specifically requested
|
||||||
if key in data:
|
if key in data:
|
||||||
|
@ -316,6 +316,19 @@ class SearchTests(InvenTreeAPITestCase):
|
|||||||
'sales_order',
|
'sales_order',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def test_empty(self):
|
||||||
|
"""Test empty request"""
|
||||||
|
|
||||||
|
data = [
|
||||||
|
'',
|
||||||
|
None,
|
||||||
|
{},
|
||||||
|
]
|
||||||
|
|
||||||
|
for d in data:
|
||||||
|
response = self.post(reverse('api-search'), d, expected_code=400)
|
||||||
|
self.assertIn('Search term must be provided', str(response.data))
|
||||||
|
|
||||||
def test_results(self):
|
def test_results(self):
|
||||||
"""Test individual result types"""
|
"""Test individual result types"""
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user