From 368428217fd182ab7a939b69c5abd7adc6bc30eb Mon Sep 17 00:00:00 2001 From: thuva4 Date: Thu, 23 Nov 2017 12:44:38 +0530 Subject: Add filter option in projects page Implemented the filter option for the projects by following params. name - Check the project's name. Edit the Error message view. Change-Id: Ib2f0e0ccd9726353dbbedbc44d98747ec8e2d4f9 Signed-off-by: thuva4 --- .../static/testapi-ui/assets/css/style.css | 6 +++ testapi/opnfv_testapi/handlers/project_handlers.py | 28 ++++++++++--- .../tests/unit/handlers/test_project.py | 28 +++++++++++++ .../ui/components/projects/projects.html | 28 ++++++++++++- .../ui/components/projects/projectsController.js | 49 ++++++++++++++-------- 5 files changed, 114 insertions(+), 25 deletions(-) diff --git a/testapi/3rd_party/static/testapi-ui/assets/css/style.css b/testapi/3rd_party/static/testapi-ui/assets/css/style.css index f348092..91e8ba2 100644 --- a/testapi/3rd_party/static/testapi-ui/assets/css/style.css +++ b/testapi/3rd_party/static/testapi-ui/assets/css/style.css @@ -226,3 +226,9 @@ a.glyphicon { .modal-body .row { margin-bottom: 10px; } + +.alert{ + background-color: white; + border-color: white; + margin-top: 5px; +} \ No newline at end of file diff --git a/testapi/opnfv_testapi/handlers/project_handlers.py b/testapi/opnfv_testapi/handlers/project_handlers.py index 30d9ab3..3ba1a80 100644 --- a/testapi/opnfv_testapi/handlers/project_handlers.py +++ b/testapi/opnfv_testapi/handlers/project_handlers.py @@ -6,6 +6,7 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +import re from opnfv_testapi.handlers import base_handlers from opnfv_testapi.models import project_models @@ -20,16 +21,33 @@ class GenericProjectHandler(base_handlers.GenericApiHandler): self.table = 'projects' self.table_cls = project_models.Project + def set_query(self): + query = dict() + for k in self.request.query_arguments.keys(): + v = self.get_query_argument(k) + if k == 'name': + query['name'] = re.compile(v, re.IGNORECASE) + return query + class ProjectCLHandler(GenericProjectHandler): - @swagger.operation(nickname="listAllProjects") + @swagger.operation(nickname="listProjects") def get(self): """ - @description: list all projects - @return 200: return all projects, empty list is no project exist - @rtype: L{Projects} + @description: Retrieve project(s) on a specific details. + @notes: Retrieve project(s) on a specific details. + Available filters for this request are : + - name : project name + + GET /projects?name=functest + @return 200: all projects consist with query, + empty list if no result is found + @param name: project name + @type name: L{string} + @in name: query + @required name: False """ - self._list() + self._list(query=self.set_query()) @swagger.operation(nickname="createProject") def post(self): diff --git a/testapi/opnfv_testapi/tests/unit/handlers/test_project.py b/testapi/opnfv_testapi/tests/unit/handlers/test_project.py index 9bc0e86..cbd1a4e 100644 --- a/testapi/opnfv_testapi/tests/unit/handlers/test_project.py +++ b/testapi/opnfv_testapi/tests/unit/handlers/test_project.py @@ -8,6 +8,7 @@ ############################################################################## import httplib import unittest +import urllib from opnfv_testapi.common import message from opnfv_testapi.models import project_models @@ -25,6 +26,7 @@ class TestProjectBase(base.TestBase): self.get_res = project_models.Project self.list_res = project_models.Projects self.update_res = project_models.Project + self.name = 'functest' self.basePath = '/api/v1/projects' def assert_body(self, project, req=None): @@ -89,6 +91,10 @@ class TestProjectGet(TestProjectBase): def test_list(self): return None + @executor.query(httplib.OK, '_query_success', 1) + def test_queryName(self): + return self._set_query('name') + def _assert_list(self, body): for project in body.projects: if self.req_d.name == project.name: @@ -96,6 +102,19 @@ class TestProjectGet(TestProjectBase): else: self.assert_body(project, self.req_e) + def _set_query(self, *args, **kwargs): + def get_value(arg): + return self.__getattribute__(arg) + query = [] + for arg in args: + query.append((arg, get_value(arg))) + for k, v in kwargs.iteritems(): + query.append((k, v)) + return urllib.urlencode(query) + + def _query_success(self, body, number): + self.assertEqual(number, len(body.projects)) + class TestProjectUpdate(TestProjectBase): @executor.mock_valid_lfid() @@ -106,6 +125,11 @@ class TestProjectUpdate(TestProjectBase): self.index_d = get_res._id self.create_e() + @executor.update(httplib.BAD_REQUEST, message.not_login()) + def test_notlogin(self): + req = project_models.ProjectUpdateRequest('apex', 'apex test') + return req, self.req_d.name + @executor.update(httplib.BAD_REQUEST, message.no_body()) def test_withoutBody(self): return None, 'noBody' @@ -145,6 +169,10 @@ class TestProjectDelete(TestProjectBase): super(TestProjectDelete, self).setUp() self.create_d() + @executor.delete(httplib.BAD_REQUEST, message.not_login()) + def test_notlogin(self): + return self.req_d.name + @executor.delete(httplib.NOT_FOUND, message.not_found_base) def test_notFound(self): return 'notFound' diff --git a/testapi/opnfv_testapi/ui/components/projects/projects.html b/testapi/opnfv_testapi/ui/components/projects/projects.html index 55f8683..28c08b1 100644 --- a/testapi/opnfv_testapi/ui/components/projects/projects.html +++ b/testapi/opnfv_testapi/ui/components/projects/projects.html @@ -23,12 +23,12 @@
-