Functional test for deleting function version

Change-Id: I045c9ac2e3bd9d41950bb47ec471048cb22c85dd
Story: 2001829
Task: 14456
This commit is contained in:
Lingxian Kong 2018-04-30 18:14:42 +12:00
parent 19cd85e818
commit 4c085dbd53
3 changed files with 38 additions and 3 deletions

View File

@ -204,13 +204,15 @@ class FunctionVersionsController(rest.RestController):
- The version should not being used by any job
- The version should not being used by any webhook
- Admin user can not delete normal user's version
"""
ctx = context.get_ctx()
acl.enforce('function_version:delete', ctx)
LOG.info("Deleting version %s of function %s.", version, function_id)
with db_api.transaction():
version_db = db_api.get_function_version(function_id, version)
version_db = db_api.get_function_version(function_id, version,
insecure=False)
latest_version = version_db.function.latest_version
version_jobs = db_api.get_jobs(

View File

@ -208,8 +208,8 @@ def increase_function_version(function_id, old_version, **kwargs):
return IMPL.increase_function_version(function_id, old_version, **kwargs)
def get_function_version(function_id, version):
return IMPL.get_function_version(function_id, version)
def get_function_version(function_id, version, **kwargs):
return IMPL.get_function_version(function_id, version, **kwargs)
# This function is only used in unit test.

View File

@ -113,6 +113,39 @@ class FunctionVersionsTest(base.BaseQinlingTest):
[v['version_number'] for v in body['function_versions']]
)
@decorators.idempotent_id('0e70ef18-687c-4ce4-ae29-aee2f88b4b9c')
def test_delete(self):
function_id = self.create_function()
version = self.create_function_version(function_id)
resp = self.client.delete_function_version(function_id, version)
self.assertEqual(204, resp.status)
resp, body = self.client.get_function_versions(function_id)
self.assertEqual(200, resp.status)
self.assertNotIn(
version,
[v['version_number'] for v in body['function_versions']]
)
@decorators.idempotent_id('c6717e2e-e80a-43d9-a25b-84f4b7453c76')
def test_delete_by_admin(self):
"""test_delete_by_admin
Admin user can not delete normal user's function version.
"""
function_id = self.create_function()
version = self.create_function_version(function_id)
self.assertRaises(
exceptions.NotFound,
self.admin_client.delete_function_version,
function_id,
version
)
@decorators.idempotent_id('7898f89f-a490-42a3-8cf7-63cbd9543a06')
def test_detach(self):
"""Admin only operation."""