2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-02 19:50:59 +00:00

Adds API mixin for "bulk delete" (#3146)

* Introduces a BulkDelete API mixin class

- Allows deletion of multiple items against a single API request

* Bump API version

* Adds BulkDelete mixin to StockItemTestResult API class

* refactor "multi BOM Item delete" to use new approach

* Refactor various attachment API endpoints

* Refactor multi delete for StockItem

* Convert remaining enndpoints over

* Fix for API test code
This commit is contained in:
Oliver
2022-06-07 07:25:12 +10:00
committed by GitHub
parent ea83d4b290
commit 00b75d792e
16 changed files with 218 additions and 156 deletions

View File

@ -15,7 +15,7 @@ import part.models
from common.models import InvenTreeSetting
from InvenTree.api_tester import InvenTreeAPITestCase
from InvenTree.status_codes import StockStatus
from stock.models import StockItem, StockLocation
from stock.models import StockItem, StockItemTestResult, StockLocation
class StockAPITestCase(InvenTreeAPITestCase):
@ -934,6 +934,50 @@ class StockTestResultTest(StockAPITestCase):
# Check that an attachment has been uploaded
self.assertIsNotNone(response.data['attachment'])
def test_bulk_delete(self):
"""Test that the BulkDelete endpoint works for this model"""
n = StockItemTestResult.objects.count()
tests = []
url = reverse('api-stock-test-result-list')
# Create some objects (via the API)
for _ii in range(50):
response = self.post(
url,
{
'stock_item': 1,
'test': f"Some test {_ii}",
'result': True,
'value': 'Test result value'
},
expected_code=201
)
tests.append(response.data['pk'])
self.assertEqual(StockItemTestResult.objects.count(), n + 50)
# Attempt a delete without providing items
self.delete(
url,
{},
expected_code=400,
)
# Now, let's delete all the newly created items with a single API request
response = self.delete(
url,
{
'items': tests,
},
expected_code=204
)
self.assertEqual(StockItemTestResult.objects.count(), n)
class StockAssignTest(StockAPITestCase):
"""Unit tests for the stock assignment API endpoint, where stock items are manually assigned to a customer."""