diff --git a/refstack/api/controllers/products.py b/refstack/api/controllers/products.py index 08194733..9d054862 100644 --- a/refstack/api/controllers/products.py +++ b/refstack/api/controllers/products.py @@ -115,6 +115,15 @@ class VersionsController(validation.BaseRestControllerWithValidation): pecan.abort(403, 'Forbidden.') try: + version = db.get_product_version(version_id, + allowed_keys=['version']) + if not version['version']: + pecan.abort(400, 'Can not delete the empty version as it is ' + 'used for basic product/test association. ' + 'This version was implicitly created with ' + 'the product, and so it cannot be deleted ' + 'explicitly.') + db.delete_product_version(version_id) except DBReferenceError: pecan.abort(400, 'Unable to delete. There are still tests ' diff --git a/refstack/tests/api/test_products.py b/refstack/tests/api/test_products.py index 1ccca172..51906776 100644 --- a/refstack/tests/api/test_products.py +++ b/refstack/tests/api/test_products.py @@ -284,3 +284,9 @@ class TestProductVersionEndpoint(api.FunctionalTest): self.delete(self.URL + version_id) self.assertRaises(webtest.app.AppError, self.get_json, self.URL + 'version_id') + + # Get the null version and ensure it can't be deleted. + versions = self.get_json(self.URL) + version_id = versions[0]['id'] + response = self.delete(self.URL + version_id, expect_errors=True) + self.assertEqual(400, response.status_code)