Allow build orders to be deleted via the API (#3155)

This commit is contained in:
Oliver
2022-06-08 07:45:42 +10:00
committed by GitHub
parent 403655e3d2
commit a816c14b95
6 changed files with 56 additions and 27 deletions

View File

@ -90,7 +90,7 @@ class BuildAPITest(InvenTreeAPITestCase):
# Required roles to access Build API endpoints
roles = [
'build.change',
'build.add'
'build.add',
]
@ -268,6 +268,39 @@ class BuildTest(BuildAPITest):
self.assertEqual(bo.status, BuildStatus.CANCELLED)
def test_delete(self):
"""Test that we can delete a BuildOrder via the API"""
bo = Build.objects.get(pk=1)
url = reverse('api-build-detail', kwargs={'pk': bo.pk})
# At first we do not have the required permissions
self.delete(
url,
expected_code=403,
)
self.assignRole('build.delete')
# As build is currently not 'cancelled', it cannot be deleted
self.delete(
url,
expected_code=400,
)
bo.status = BuildStatus.CANCELLED
bo.save()
# Now, we should be able to delete
self.delete(
url,
expected_code=204,
)
with self.assertRaises(Build.DoesNotExist):
Build.objects.get(pk=1)
def test_create_delete_output(self):
"""Test that we can create and delete build outputs via the API."""
bo = Build.objects.get(pk=1)