mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Fixes
This commit is contained in:
parent
2bb86ff22b
commit
4d1eb51bc4
@ -74,8 +74,11 @@ class CategoryList(generics.ListCreateAPIView):
|
||||
|
||||
cascade = str2bool(params.get('cascade', False))
|
||||
|
||||
# Do not filter by category
|
||||
if cat_id is None:
|
||||
pass
|
||||
# Look for top-level categories
|
||||
if isNull(cat_id):
|
||||
elif isNull(cat_id):
|
||||
|
||||
if not cascade:
|
||||
queryset = queryset.filter(parent=None)
|
||||
|
@ -37,12 +37,54 @@ class PartAPITest(InvenTreeAPITestCase):
|
||||
super().setUp()
|
||||
|
||||
def test_get_categories(self):
|
||||
""" Test that we can retrieve list of part categories """
|
||||
"""
|
||||
Test that we can retrieve list of part categories,
|
||||
with various filtering options.
|
||||
"""
|
||||
|
||||
url = reverse('api-part-category-list')
|
||||
|
||||
# Request *all* part categories
|
||||
response = self.client.get(url, format='json')
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(len(response.data), 8)
|
||||
|
||||
# Request top-level part categories only
|
||||
response = self.client.get(
|
||||
url,
|
||||
{
|
||||
'parent': 'null',
|
||||
},
|
||||
format='json'
|
||||
)
|
||||
|
||||
self.assertEqual(len(response.data), 2)
|
||||
|
||||
# Children of PartCategory<1>, cascade
|
||||
response = self.client.get(
|
||||
url,
|
||||
{
|
||||
'parent': 1,
|
||||
'cascade': 'true',
|
||||
},
|
||||
format='json',
|
||||
)
|
||||
|
||||
self.assertEqual(len(response.data), 5)
|
||||
|
||||
# Children of PartCategory<1>, do not cascade
|
||||
response = self.client.get(
|
||||
url,
|
||||
{
|
||||
'parent': 1,
|
||||
'cascade': 'false',
|
||||
},
|
||||
format='json',
|
||||
)
|
||||
|
||||
self.assertEqual(len(response.data), 3)
|
||||
|
||||
def test_add_categories(self):
|
||||
""" Check that we can add categories """
|
||||
data = {
|
||||
|
@ -295,8 +295,11 @@ class StockLocationList(generics.ListCreateAPIView):
|
||||
|
||||
cascade = str2bool(params.get('cascade', False))
|
||||
|
||||
# Do not filter by location
|
||||
if loc_id is None:
|
||||
pass
|
||||
# Look for top-level locations
|
||||
if isNull(loc_id):
|
||||
elif isNull(loc_id):
|
||||
|
||||
# If we allow "cascade" at the top-level, this essentially means *all* locations
|
||||
if not cascade:
|
||||
|
Loading…
Reference in New Issue
Block a user