mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 12:35:46 +00:00
Path detail API (#5569)
* Add "path_detail" to stock location serializer - Requires ?path_detail=1 in URL query parameters - Only avaialable on the StockLocation detail URL endpoint (not list, too expensive) * Implement path_detail option for PartCategory detail API endpoint * Add "path_detail" option to PartSerializer * Add optional path_detail to StockItem serializer * Cleanup * Increment API version * Add unit test for Part and PartCategory * Remove debug statement
This commit is contained in:
@ -441,6 +441,41 @@ class PartCategoryAPITest(InvenTreeAPITestCase):
|
||||
part.refresh_from_db()
|
||||
self.assertEqual(part.category.pk, non_structural_category.pk)
|
||||
|
||||
def test_path_detail(self):
|
||||
"""Test path_detail information"""
|
||||
|
||||
url = reverse('api-part-category-detail', kwargs={'pk': 5})
|
||||
|
||||
# First, request without path detail
|
||||
response = self.get(
|
||||
url,
|
||||
{
|
||||
'path_detail': False,
|
||||
},
|
||||
expected_code=200
|
||||
)
|
||||
|
||||
# Check that the path detail information is not included
|
||||
self.assertFalse('path' in response.data.keys())
|
||||
|
||||
# Now, request *with* path detail
|
||||
response = self.get(
|
||||
url,
|
||||
{
|
||||
'path_detail': True,
|
||||
},
|
||||
expected_code=200
|
||||
)
|
||||
|
||||
self.assertTrue('path' in response.data.keys())
|
||||
|
||||
path = response.data['path']
|
||||
|
||||
self.assertEqual(len(path), 3)
|
||||
self.assertEqual(path[0]['name'], 'Electronics')
|
||||
self.assertEqual(path[1]['name'], 'IC')
|
||||
self.assertEqual(path[2]['name'], 'MCU')
|
||||
|
||||
|
||||
class PartOptionsAPITest(InvenTreeAPITestCase):
|
||||
"""Tests for the various OPTIONS endpoints in the /part/ API.
|
||||
@ -1647,6 +1682,20 @@ class PartDetailTests(PartAPITestBase):
|
||||
self.assertEqual(data['in_stock'], 9000)
|
||||
self.assertEqual(data['unallocated_stock'], 9000)
|
||||
|
||||
def test_path_detail(self):
|
||||
"""Check that path_detail can be requested against the serializer"""
|
||||
|
||||
response = self.get(
|
||||
reverse('api-part-detail', kwargs={'pk': 1}),
|
||||
{
|
||||
'path_detail': True,
|
||||
},
|
||||
expected_code=200,
|
||||
)
|
||||
|
||||
self.assertIn('category_path', response.data)
|
||||
self.assertEqual(len(response.data['category_path']), 2)
|
||||
|
||||
|
||||
class PartListTests(PartAPITestBase):
|
||||
"""Unit tests for the Part List API endpoint"""
|
||||
|
Reference in New Issue
Block a user