This commit is contained in:
Oliver Walters 2021-04-20 20:42:55 +10:00
parent 2bb86ff22b
commit 4d1eb51bc4
3 changed files with 51 additions and 3 deletions

View File

@ -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)

View File

@ -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 = {

View File

@ -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: