summaryrefslogtreecommitdiffstats
path: root/testapi/testapi-client/testapiclient/cli
diff options
context:
space:
mode:
authorthuva4 <tharma.thuva@gmail.com>2018-03-16 10:51:29 +0530
committerSerenaFeng <feng.xiaowei@zte.com.cn>2018-03-21 16:55:06 +0800
commitb8176c7026e9b7f50905cdad140bd16990eaba29 (patch)
treefec9610a8774fb48e9b4d8151092c7b34e450068 /testapi/testapi-client/testapiclient/cli
parent57c40c1797db312c609a99bfd4777ace22ad8b89 (diff)
Add testcases CRUD in testapiclient
implement interface to do CRUD operations for testcases in testapiclient + tests Change-Id: I59a810b6ba496d672fdf04be465ca5581dc58a3f Signed-off-by: thuva4 <tharma.thuva@gmail.com>
Diffstat (limited to 'testapi/testapi-client/testapiclient/cli')
-rw-r--r--testapi/testapi-client/testapiclient/cli/testcases.py119
1 files changed, 119 insertions, 0 deletions
diff --git a/testapi/testapi-client/testapiclient/cli/testcases.py b/testapi/testapi-client/testapiclient/cli/testcases.py
new file mode 100644
index 0000000..6c97edb
--- /dev/null
+++ b/testapi/testapi-client/testapiclient/cli/testcases.py
@@ -0,0 +1,119 @@
+import json
+
+from testapiclient.utils import command
+from testapiclient.utils import urlparse
+
+
+def testcases_url(name):
+ return urlparse.resource_join('projects', name, 'cases')
+
+
+def testcase_url(parsed_args):
+ return urlparse.path_join(
+ testcases_url(parsed_args.project_name), parsed_args.name)
+
+
+class TestcaseGet(command.Lister):
+
+ def get_parser(self, prog_name):
+ parser = super(TestcaseGet, self).get_parser(prog_name)
+ parser.add_argument('--project-name',
+ required=True,
+ help='Search testcases by project name')
+ return parser
+
+ def take_action(self, parsed_args):
+ columns = (
+ 'name',
+ '_id',
+ 'creator',
+ 'creation_date'
+ )
+ data = self.app.client_manager.get(
+ testcases_url(parsed_args.project_name))
+ return self.format_output(columns, data.get('testcases', []))
+
+
+class TestcaseGetOne(command.ShowOne):
+
+ def get_parser(self, prog_name):
+ parser = super(TestcaseGetOne, self).get_parser(prog_name)
+ parser.add_argument('--project-name',
+ required=True,
+ help='Search testcase by project name')
+ parser.add_argument('name',
+ help='Search testcase by name')
+ return parser
+
+ def take_action(self, parsed_args):
+ return self.format_output(
+ self.app.client_manager.get(testcase_url(parsed_args)))
+
+
+class TestcaseCreate(command.ShowOne):
+
+ def get_parser(self, prog_name):
+ parser = super(TestcaseCreate, self).get_parser(prog_name)
+ parser.add_argument('--project-name',
+ required=True,
+ help='Create testcase under project name')
+ parser.add_argument('testcase',
+ type=json.loads,
+ help='Testcase create request format:\n'
+ '\'{"run": "", "name": "", "ci_loop": "",'
+ '"tags": "",\n "url": "", "blocking": "",'
+ '"domains": "", "dependencies": "",\n '
+ '"version": "", "criteria": "", "tier": "",'
+ '"trust": "",\n "catalog_description": "",'
+ '"description": ""}\'')
+ return parser
+
+ def take_action(self, parsed_args):
+ return self.format_output(
+ self.app.client_manager.post(
+ testcases_url(parsed_args.project_name), parsed_args.testcase))
+
+
+class TestcaseDelete(command.Command):
+
+ def get_parser(self, prog_name):
+ parser = super(TestcaseDelete, self).get_parser(prog_name)
+ parser.add_argument('--project-name',
+ required=True,
+ type=str,
+ help='Delete testcase by project name')
+ parser.add_argument('name',
+ type=str,
+ help='Delete testcase by name')
+ return parser
+
+ def take_action(self, parsed_args):
+ return self.app.client_manager.delete(testcase_url(parsed_args))
+
+
+class TestcasePut(command.ShowOne):
+
+ def get_parser(self, prog_name):
+ parser = super(TestcasePut, self).get_parser(prog_name)
+ parser.add_argument('--project-name',
+ type=str,
+ required=True,
+ help='Update testcase by project name')
+ parser.add_argument('name',
+ type=str,
+ help='Update testcase by name')
+ parser.add_argument('testcase',
+ type=json.loads,
+ help='Testcase Update request format:\n'
+ '\'{"run": "", "name": "", "ci_loop": "",'
+ '"tags": "",\n "url": "", "blocking": "",'
+ '"domains": "", "dependencies": "",\n '
+ '"version": "", "criteria": "", "tier": "",'
+ '"trust": "",\n "catalog_description": "",'
+ '"description": ""}\'')
+ return parser
+
+ def take_action(self, parsed_args):
+ return self.format_output(
+ self.app.client_manager.put(
+ testcase_url(parsed_args), parsed_args.testcase))