From 4c085dbd532dcfbbb0270e05d32e303da2cf247a Mon Sep 17 00:00:00 2001 From: Lingxian Kong Date: Mon, 30 Apr 2018 18:14:42 +1200 Subject: [PATCH] Functional test for deleting function version Change-Id: I045c9ac2e3bd9d41950bb47ec471048cb22c85dd Story: 2001829 Task: 14456 --- .../api/controllers/v1/function_version.py | 4 ++- qinling/db/api.py | 4 +-- .../tests/api/test_function_versions.py | 33 +++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/qinling/api/controllers/v1/function_version.py b/qinling/api/controllers/v1/function_version.py index cab53557..baf3efb2 100644 --- a/qinling/api/controllers/v1/function_version.py +++ b/qinling/api/controllers/v1/function_version.py @@ -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( diff --git a/qinling/db/api.py b/qinling/db/api.py index a1021ae1..39f5b55a 100644 --- a/qinling/db/api.py +++ b/qinling/db/api.py @@ -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. diff --git a/qinling_tempest_plugin/tests/api/test_function_versions.py b/qinling_tempest_plugin/tests/api/test_function_versions.py index 161a62ec..7c84862b 100644 --- a/qinling_tempest_plugin/tests/api/test_function_versions.py +++ b/qinling_tempest_plugin/tests/api/test_function_versions.py @@ -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."""