mirror of
https://github.com/inventree/InvenTree.git
synced 2026-03-21 11:44:42 +00:00
[API] Bug fix for PartCategory cascade filter (#11562)
* Bug fix for PartCategory cascade filter * Additional unit test
This commit is contained in:
@@ -161,7 +161,7 @@ class CategoryFilter(FilterSet):
|
||||
|
||||
Note: If the "parent" filter is provided, we offload the logic to that method.
|
||||
"""
|
||||
parent = str2bool(self.data.get('parent', None))
|
||||
parent = self.data.get('parent', None)
|
||||
top_level = str2bool(self.data.get('top_level', None))
|
||||
|
||||
# If the parent is *not* provided, update the results based on the "cascade" value
|
||||
|
||||
@@ -111,7 +111,7 @@ class PartCategoryAPITest(InvenTreeAPITestCase):
|
||||
url = reverse('api-part-category-list')
|
||||
|
||||
# star categories manually for tests as it is not possible with fixures
|
||||
# because the current user is not fixured itself and throws an invalid
|
||||
# because the current user is not fixtured itself and throws an invalid
|
||||
# foreign key constraint
|
||||
for pk in [3, 4]:
|
||||
PartCategory.objects.get(pk=pk).set_starred(self.user, True)
|
||||
@@ -812,9 +812,14 @@ class PartAPITest(PartAPITestBase):
|
||||
|
||||
# Children of PartCategory<1>, do not cascade
|
||||
response = self.get(url, {'parent': 1, 'cascade': 'false'})
|
||||
|
||||
self.assertEqual(len(response.data), 3)
|
||||
|
||||
# Children of PartCategory<7>, with or without cascade
|
||||
# Only 1 child in either case
|
||||
for cascade in ['true', 'false']:
|
||||
response = self.get(url, {'parent': 7, 'cascade': cascade})
|
||||
self.assertEqual(len(response.data), 1)
|
||||
|
||||
def test_add_categories(self):
|
||||
"""Check that we can add categories."""
|
||||
data = {'name': 'Animals', 'description': 'All animals go here'}
|
||||
@@ -1644,7 +1649,7 @@ class PartCreationTests(PartAPITestBase):
|
||||
|
||||
self.assertEqual(cat.parameter_templates.count(), 3)
|
||||
|
||||
# Creat a new Part, without copying category parameters
|
||||
# Create a new Part, without copying category parameters
|
||||
data = self.post(
|
||||
reverse('api-part-list'),
|
||||
{
|
||||
@@ -2314,7 +2319,7 @@ class PartAPIAggregationTest(InvenTreeAPITestCase):
|
||||
self.assertEqual(data['allocated_to_build_orders'], 0)
|
||||
self.assertEqual(data['allocated_to_sales_orders'], 0)
|
||||
|
||||
# The unallocated stock count should equal the 'in stock' coutn
|
||||
# The unallocated stock count should equal the 'in stock' count
|
||||
in_stock = data['in_stock']
|
||||
self.assertEqual(in_stock, 126)
|
||||
self.assertEqual(data['unallocated_stock'], in_stock)
|
||||
|
||||
Reference in New Issue
Block a user