Browse Source

Merge "Function versioning API: list"

changes/31/562431/2
Zuul 3 years ago
committed by Gerrit Code Review
parent
commit
edf0b7824d
3 changed files with 36 additions and 1 deletions
  1. +16
    -0
      qinling/api/controllers/v1/function_version.py
  2. +3
    -1
      qinling/api/controllers/v1/resources.py
  3. +17
    -0
      qinling/tests/unit/api/controllers/v1/test_function_version.py

+ 16
- 0
qinling/api/controllers/v1/function_version.py View File

@ -121,3 +121,19 @@ class FunctionVersionsController(rest.RestController):
**values)
return resources.FunctionVersion.from_dict(version.to_dict())
@rest_utils.wrap_wsme_controller_exception
@wsme_pecan.wsexpose(resources.FunctionVersions, types.uuid)
def get_all(self, function_id):
acl.enforce('function_version:get_all', context.get_ctx())
LOG.info("Getting function versions for function %s.", function_id)
# Getting function and versions needs to happen in a db transaction
with db_api.transaction():
func_db = db_api.get_function(function_id)
db_versions = func_db.versions
versions = [resources.FunctionVersion.from_dict(v.to_dict())
for v in db_versions]
return resources.FunctionVersions(function_versions=versions)

+ 3
- 1
qinling/api/controllers/v1/resources.py View File

@ -170,6 +170,7 @@ class Function(Resource):
code = types.jsontype
entry = wtypes.text
count = wsme.wsattr(int, readonly=True)
latest_version = wsme.wsattr(int, readonly=True)
project_id = wsme.wsattr(wtypes.text, readonly=True)
created_at = wtypes.text
updated_at = wtypes.text
@ -186,6 +187,7 @@ class Function(Resource):
code={'zip': True},
entry='main',
count=10,
latest_version=0,
project_id='default',
created_at='1970-01-01T00:00:00.000000',
updated_at='1970-01-01T00:00:00.000000'
@ -417,7 +419,7 @@ class Webhooks(ResourceList):
class FunctionVersion(Resource):
id = types.uuid
description = wtypes.text
function_version = wsme.wsattr(int, readonly=True)
version_number = wsme.wsattr(int, readonly=True)
project_id = wsme.wsattr(wtypes.text, readonly=True)
created_at = wsme.wsattr(wtypes.text, readonly=True)
updated_at = wsme.wsattr(wtypes.text, readonly=True)


+ 17
- 0
qinling/tests/unit/api/controllers/v1/test_function_version.py View File

@ -62,6 +62,12 @@ class TestFunctionVersionController(base.APITest):
func_db = db_api.get_function(self.func_id)
self.assertEqual(1, len(func_db.versions))
# Verify the latest function version by calling API
resp = self.app.get('/v1/functions/%s' % self.func_id)
self.assertEqual(200, resp.status_int)
self.assertEqual(1, resp.json.get('latest_version'))
@mock.patch('qinling.storage.file_system.FileSystemStorage.changed_since')
@mock.patch('qinling.utils.etcd_util.get_function_version_lock')
def test_post_not_change(self, mock_etcd_lock, mock_changed):
@ -91,3 +97,14 @@ class TestFunctionVersionController(base.APITest):
expect_errors=True)
self.assertEqual(403, resp.status_int)
def test_get_all(self):
db_api.increase_function_version(self.func_id, 0,
description="version 1")
resp = self.app.get('/v1/functions/%s/versions' % self.func_id)
self.assertEqual(200, resp.status_int)
actual = self._assert_single_item(resp.json['function_versions'],
version_number=1)
self.assertEqual("version 1", actual.get('description'))

Loading…
Cancel
Save