init: Add functionality to clone templates
PATCH 1/2 init: Add functionality to clone templates
From: Jose Perez Carranza <[email protected]>
Add “clone_template” function that allow cloning in the same branch or for X to Y branch, also add “get_test_run_list” to do a query of test runs with specific summary and specific test plan.
Signed-off-by Jose Perez Carranza <[email protected]>
--- testopia_update/product/__init__.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
testopia_update/product/__init__.py +26 -0
@@ -150,6 +150,26 @@ class Product(object): return new_test_run + def clone_template(self, test_run, old_project_version, new_project_version, + **kwargs): + if 'new_branch' in kwargs: + plan_id = self.get_test_plan(kwargs['new_branch'])['plan_id'] + else: + plan_id = test_run['plan_id'] + + test_case_ids = self._get_test_case_ids(test_run) + summary = test_run['summary'].replace(old_project_version, + new_project_version) + + summary = summary.replace('TEMPLATE','TRTEMP') + + new_test_run = self.testopia.testrun_create(test_run['build_id'], + test_run['environment_id'], plan_id, summary, + self.testopia.userId, product_version=new_project_version) + self.testopia.testrun_add_cases(test_case_ids, new_test_run['run_id']) + + return new_test_run + def parse_results_log(self, log_file): regex = "^.*RESULTS.* (?P<case_id>\d+): (?P<status>PASSED|FAILED)$" if hasattr(self, 'results_regex'):
@@ -195,6 +215,12 @@ class Product(object): return tr_id + def get_test_run_list(self, test_plan, temp_summary): + list_test_runs = self.testopia.testrun_list(plan_id=test_plan['plan_id'], + summary=temp_summary) + + return list_test_runs + class DummyProduct(Product): #Dummy product to use when specific product is not required name = 'Dummy'
Signature · 1 line
2.11.0
PATCH 2/2 testopia_update.py: Add functionality for setup clone-templates
From: Jose Perez Carranza <[email protected]>
Add action “setup” to do a different actions on the exiting Testopia DB, also add validation for the specific option used on this new action, sub-option “-clone-templates” implemented to help on the setup for new release and cloning form the same bran or form one branch to another.
Signed-off-by Jose Perez Carranza <[email protected]>
--- testopia_update.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 8 deletions(-)
testopia_update.py +57 -8
@@ -5,7 +5,6 @@ import sys import argparse import logging import ConfigParser -import types from external.testopia import Testopia from testopia_update.product import get_products, get_product_class
@@ -13,8 +12,9 @@ from testopia_update.product import get_products, get_product_class DEFAULT_CONFIG_FILE = "testopia_update.config" DEFAULT_STORE_LOCATION = "/tmp/testopia_update" -ACTIONS = ('create', 'update') -BRANCHES = ('master', 'jethro', 'dizzy', 'daisy', 'noexists', 'morty', "pyro") +ACTIONS = ('create', 'update', 'setup') +BRANCHES = ('master', 'jethro', 'dizzy', 'daisy', 'noexists', 'morty', "krogoth", + "pyro") CATEGORIES = ('AUTO', 'MANUAL')
@@ -41,16 +41,28 @@ def load_results(results_log): def load_opts(args, opts_list, opts): + + invalid_opts = ['old_project_version', 'clone_templates', 'new_branch'] + + if args.action == "create" or args.action == "update": + for invarg in invalid_opts: + if getattr(args, invarg): + logger.error("option %s not availabe for %s action " + % (invarg, args.action)) + sys.exit(1) + for to in opts_list: if to in vars(args): arg = getattr(args, to) if arg: setattr(opts, to, arg) + if not hasattr(opts, to): logger.error("%s: Requires testopia %s in arguments or config." % \ (sys.argv[0], to)) + if args.action == "update": - logger.warn('for action create you can use only --testrun-id ' + + logger.warn('for action update you can use only --testrun-id ' + 'and --results-log if test run was already created') sys.exit(1)
@@ -59,7 +71,8 @@ def connect_to_testopia(): config = None opts = Options() - testopia_config = ['url', 'username', 'password', 'store_location'] + #testopia_config = ['url', 'username', 'password', 'store_location'] + testopia_config = ['url', 'username', 'password'] if not args.config and os.path.exists(DEFAULT_CONFIG_FILE): args.config = DEFAULT_CONFIG_FILE
@@ -73,8 +86,8 @@ def connect_to_testopia(): load_opts(args, testopia_config, opts) - if not os.path.exists(opts.store_location): - os.makedirs(opts.store_location) + if not os.path.exists(DEFAULT_STORE_LOCATION): + os.makedirs(DEFAULT_STORE_LOCATION) return opts, config
@@ -99,7 +112,7 @@ def get_args(): parser.add_argument('-a', '--action', required=False, dest='action', choices=ACTIONS, - help='Action to execute can be create or update.') + help='Action to execute can be create, update or setup') parser.add_argument('-p', '--product', required=False, dest="product_name", help='Product to create or update.') parser.add_argument('-c', '--category', required=False,
@@ -131,6 +144,16 @@ def get_args(): parser.add_argument('--results-log', required=False, dest="results_log", help='Results log.') + parser.add_argument('--old-project-version', required=False, + dest="old_project_version", help='Version of the project to clone from') + + parser.add_argument('--clone-templates', required=False, + dest="clone_templates", help='clone templates from one brnach to \ + another or same branch (only avaibale) \ + with setup action', const='Y', nargs='?') + parser.add_argument('--new-branch', required=False, + dest="new_branch", help='New branch to clone the Templates') + parser.add_argument('--verbose', required=False, action="store_true", dest="verbose", default=False, help='Enable verbose mode.') parser.add_argument('--debug', required=False, action="store_true",
@@ -172,6 +195,32 @@ if __name__ == '__main__': print("%s\n" % p.name) sys.exit(0) + if args.action == 'setup': + setup_opts = ['clone_templates', 'project_version','branch_name', + 'old_project_version', 'product_name'] + + load_opts(args, setup_opts, opts) + + product = get_product_class(args.product_name, products) + test_plan = product.get_test_plan(args.branch_name) + temp_summary = 'TRTEMP_' + args.old_project_version + temp_list = product.get_test_run_list(test_plan,temp_summary) + if not temp_list: + logger.error("%s: No templates found with %s string on %s" + % (sys.argv[0], temp_summary, args.branch_name)) + + for tr in temp_list: + if args.new_branch and args.new_branch != args.branch_name: + kwargs['new_branch'] = args.new_branch + + new_template = product.clone_template(tr, args.old_project_version, + args.project_version, **kwargs) + logger.info("%s: Template was created with (%d), Summary (%s)" + % (sys.argv[0], new_template['run_id'], + new_template['summary'])) + sys.exit(0) + + if args.action == 'update' and args.trun_id: args.product_name = 'Dummy' product = get_product_class(args.product_name, products)
Signature · 1 line
2.11.0