Browse Source

Functional test for deleting function version

Change-Id: I045c9ac2e3bd9d41950bb47ec471048cb22c85dd
Story: 2001829
Task: 14456
changes/55/565155/2
Lingxian Kong 3 years ago
parent
commit
4c085dbd53
3 changed files with 38 additions and 3 deletions
  1. +3
    -1
      qinling/api/controllers/v1/function_version.py
  2. +2
    -2
      qinling/db/api.py
  3. +33
    -0
      qinling_tempest_plugin/tests/api/test_function_versions.py

+ 3
- 1
qinling/api/controllers/v1/function_version.py 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(


+ 2
- 2
qinling/db/api.py 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.


+ 33
- 0
qinling_tempest_plugin/tests/api/test_function_versions.py 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."""


Loading…
Cancel
Save