mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +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,
|
||||
}
|
||||
|
||||
if 'search' not in data:
|
||||
raise ValidationError({
|
||||
'search': 'Search term must be provided',
|
||||
})
|
||||
|
||||
for key, cls in self.get_result_types().items():
|
||||
# Only return results which are specifically requested
|
||||
if key in data:
|
||||
|
@ -316,6 +316,19 @@ class SearchTests(InvenTreeAPITestCase):
|
||||
'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):
|
||||
"""Test individual result types"""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user