summaryrefslogtreecommitdiffstats
path: root/testapi/testapi-client/testapiclient/cli
diff options
context:
space:
mode:
authorthuva4 <tharma.thuva@gmail.com>2018-03-19 23:50:47 +0530
committerthuva4 <tharma.thuva@gmail.com>2018-03-19 23:50:47 +0530
commit797f5b340dd4e468ed35e260e502d6cfe48b3d20 (patch)
tree6b4345f2f1af3915d2446bcbfd78814ea9913f72 /testapi/testapi-client/testapiclient/cli
parent3f179ccef8a3d49993ecdec58a008054288b622b (diff)
Add scenarios CRUD in testapiclient
implement interface to do CRUD operations for scenarios in testapiclient + tests Change-Id: Ia952bd29e88d867a2873af79c3424953142676d3 Signed-off-by: thuva4 <tharma.thuva@gmail.com>
Diffstat (limited to 'testapi/testapi-client/testapiclient/cli')
-rw-r--r--testapi/testapi-client/testapiclient/cli/scenarios.py131
1 files changed, 131 insertions, 0 deletions
diff --git a/testapi/testapi-client/testapiclient/cli/scenarios.py b/testapi/testapi-client/testapiclient/cli/scenarios.py
new file mode 100644
index 0000000..fc6a2db
--- /dev/null
+++ b/testapi/testapi-client/testapiclient/cli/scenarios.py
@@ -0,0 +1,131 @@
+import json
+
+from testapiclient.utils import command
+from testapiclient.utils import urlparse
+
+
+def scenarios_url():
+ return urlparse.resource_join('scenarios')
+
+
+def scenario_url(parsed_args):
+ return urlparse.path_join(scenarios_url(), parsed_args.name)
+
+
+class ScenarioGet(command.Lister):
+
+ def get_parser(self, prog_name):
+ parser = super(ScenarioGet, self).get_parser(prog_name)
+ parser.add_argument('-name',
+ help='Search scenarios using name')
+ parser.add_argument('-installer',
+ help='Search scenarios using installer')
+ parser.add_argument('---version',
+ help='Search scenarios using version')
+ parser.add_argument('-project',
+ help='Search scenarios using project')
+ return parser
+
+ def take_action(self, parsed_args):
+ columns = (
+ 'name',
+ '_id',
+ 'creator',
+ 'creation_date'
+ )
+ data = self.app.client_manager.get(
+ urlparse.query_by(scenarios_url(),
+ ['name', 'installer', 'version', 'project'],
+ parsed_args))
+ return self.format_output(columns, data.get('scenarios', []))
+
+
+class ScenarioGetOne(command.ShowOne):
+
+ def get_parser(self, prog_name):
+ parser = super(ScenarioGetOne, self).get_parser(prog_name)
+ parser.add_argument('name',
+ help='Search scenario by name')
+ return parser
+
+ def take_action(self, parsed_args):
+ return self.format_output(
+ self.app.client_manager.get(scenario_url(parsed_args)))
+
+
+class ScenarioCreate(command.ShowOne):
+
+ def get_parser(self, prog_name):
+ parser = super(ScenarioCreate, self).get_parser(prog_name)
+ parser.add_argument('scenario',
+ type=json.loads,
+ help='Scenario create request format :\n'
+ '\'{ "installers": [], "name": ""}\',\n'
+ 'Intaller create request format :\n'
+ '\'{"installer": "","versions": []}\',\n'
+ 'Version create request format :\n'
+ '\'{"owner": "","version": "",'
+ '"projects": []}\',\n'
+ 'Project create request format :\n'
+ '\'{"project": "","customs": [],'
+ '"scores": [],'
+ '"trust_indicators": []}\',\n'
+ 'Custom create request format :\n'
+ '\'["asf","saf"]\',\n'
+ 'Score create request format :\n'
+ '\'{"date": "", "score": ""}\',\n'
+ 'Trust Indicators create request format :\n'
+ '\'{"date": "", "status": ""}\'')
+ return parser
+
+ def take_action(self, parsed_args):
+ return self.format_output(
+ self.app.client_manager.post(
+ scenarios_url(), parsed_args.scenario))
+
+
+class ScenarioDelete(command.Command):
+
+ def get_parser(self, prog_name):
+ parser = super(ScenarioDelete, self).get_parser(prog_name)
+ parser.add_argument('name',
+ type=str,
+ help='Delete scenario by name')
+ return parser
+
+ def take_action(self, parsed_args):
+ return self.app.client_manager.delete(scenario_url(parsed_args))
+
+
+class ScenarioPut(command.ShowOne):
+
+ def get_parser(self, prog_name):
+ parser = super(ScenarioPut, self).get_parser(prog_name)
+ parser.add_argument('name',
+ type=str,
+ help='Update scenario by name')
+ parser.add_argument('scenario',
+ type=json.loads,
+ help='Scenario create request format :\n'
+ '\'{ "installers": [], "name": ""}\',\n'
+ 'Intaller create request format :\n'
+ '\'{"installer": "","versions": []}\',\n'
+ 'Version create request format :\n'
+ '\'{"owner": "","version": "",'
+ '"projects": []}\',\n'
+ 'Project create request format :\n'
+ '\'{"project": "","customs": [],'
+ '"scores": [],'
+ '"trust_indicators": []}\',\n'
+ 'Custom create request format :\n'
+ '\'["asf","saf"]\',\n'
+ 'Score create request format :\n'
+ '\'{"date": "", "score": ""}\',\n'
+ 'Trust Indicators create request format :\n'
+ '\'{"date": "", "status": ""}\'')
+ return parser
+
+ def take_action(self, parsed_args):
+ return self.format_output(
+ self.app.client_manager.put(
+ scenario_url(parsed_args), parsed_args.scenario))