From 95c61074fbfe94570b9f8eac888f74a5cec1776f Mon Sep 17 00:00:00 2001 From: Thomas Maddox Date: Fri, 17 Feb 2017 21:22:15 +0000 Subject: [PATCH] Use String for Project ID in schema This patch sets the schema to accept a string for Project ID since it's actually a UUID Change-Id: Iad8733594ca83c3bc061017fd9eae6861f31ee5d Closes-Bug: 1665780 --- craton/api/v1/resources/projects.py | 6 ----- craton/api/v1/schemas.py | 9 ++----- craton/tests/functional/test_project_calls.py | 26 ++++++++++++++----- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/craton/api/v1/resources/projects.py b/craton/api/v1/resources/projects.py index 5be4201..c991eb5 100644 --- a/craton/api/v1/resources/projects.py +++ b/craton/api/v1/resources/projects.py @@ -15,14 +15,8 @@ class Projects(base.Resource): @base.pagination_context def get(self, context, request_args, pagination_params): """Get all projects. Requires super admin privileges.""" - project_id = request_args["id"] project_name = request_args["name"] - if project_id: - project_obj = dbapi.projects_get_by_id(context, project_id) - projects_obj = [project_obj] - link_params = {} - if project_name: projects_obj, link_params = dbapi.projects_get_by_name( context, project_name, request_args, pagination_params, diff --git a/craton/api/v1/schemas.py b/craton/api/v1/schemas.py index bf67a50..a2ed1ce 100644 --- a/craton/api/v1/schemas.py +++ b/craton/api/v1/schemas.py @@ -381,7 +381,7 @@ DefinitionProject = { "type": "string", }, "id": { - "type": "integer", + "type": "string", }, "name": { "type": "string", @@ -1032,11 +1032,6 @@ validators = { "args": { "additionalProperties": False, "properties": { - "id": { - "default": None, - "type": "integer", - "description": "id of the project to get", - }, "name": { "default": None, "type": "string", @@ -1050,7 +1045,7 @@ validators = { "description": "Number of projects to return in a page", }, "marker": { - "type": "integer", + "type": "string", "description": "Last project ID of the previous page", }, "vars": { diff --git a/craton/tests/functional/test_project_calls.py b/craton/tests/functional/test_project_calls.py index a983a59..373cd2e 100644 --- a/craton/tests/functional/test_project_calls.py +++ b/craton/tests/functional/test_project_calls.py @@ -1,5 +1,7 @@ import copy +from oslo_utils import uuidutils + from craton.tests import functional from craton.tests.functional.test_variable_calls import \ APIV1ResourceWithVariablesTestCase @@ -23,15 +25,17 @@ class ProjectTests(functional.TestCase): payload = {'name': name} if variables: payload['variables'] = variables - project = self.post(url, headers=self.root_headers, data=payload) - self.assertEqual(201, project.status_code) - self.assertIn('Location', project.headers) + response = self.post(url, headers=self.root_headers, data=payload) + self.assertEqual(201, response.status_code) + self.assertIn('Location', response.headers) + project = response.json() + self.assertTrue(uuidutils.is_uuid_like(project['id'])) self.assertEqual( - project.headers['Location'], - "{}/{}".format(url, project.json()['id']) + response.headers['Location'], + "{}/{}".format(url, project['id']) ) - return project.json() + return project class TestPaginationOfProjects(ProjectTests): @@ -51,6 +55,16 @@ class TestPaginationOfProjects(ProjectTests): projects = json['projects'] self.assertEqual(30, len(projects)) + def test_lists_projects_with_the_same_name(self): + self.create_project('project-0') + + response = self.get(self.url + '/v1/projects', + name='project-0', + headers=self.root_headers) + self.assertSuccessOk(response) + projects = response.json()['projects'] + self.assertEqual(2, len(projects)) + class APIV1ProjectTest(ProjectTests, APIV1ResourceWithVariablesTestCase):