def add_version(request, values): """Add version to specified product. :param dict values: a mapping containing these data * product: (int or str) product ID or name. * value: (str) the version value. :return: a mapping representing newly added :class:`Version`. :raise ValueError: if fail to add version. Example:: # Add version for specified product: >>> Product.add_version({'value': 'devel', 'product': 1}) {'product': 'Test Product', 'id': '1', 'value': 'devel', 'product_id': 1} # Run it again: >>> Product.add_version({'value': 'devel', 'product': 1}) [['__all__', 'Version with this Product and Value already exists.']] """ from tcms.management.forms import VersionForm from tcms.core import forms product = pre_check_product(values) form_values = values.copy() form_values['product'] = product.pk form = VersionForm(form_values) if form.is_valid(): version = form.save() return version.serialize() else: raise ValueError(forms.errors_to_list(form))
def create(request, values): """ Description: Creates a new Test Plan object and stores it in the database. Params: $values - Hash: A reference to a hash with keys and values matching the fields of the test plan to be created. +-------------------------+----------------+-----------+------------------------------------+ | Field | Type | Null | Description | +-------------------------+----------------+-----------+------------------------------------+ | product | Integer | Required | ID of product | | name | String | Required | | | type | Integer | Required | ID of plan type | | default_product_version | Integer | Required | | | text | String | Required | Plan documents, HTML acceptable. | | parent | Integer | Optional | Parent plan ID | | is_active | Boolean | Optional | 0: Archived 1: Active (Default 0) | +-------------------------+----------------+-----------+------------------------------------+ Returns: The newly created object hash. Example: # Minimal test case parameters >>> values = { 'product': 61, 'name': 'Testplan foobar', 'type': 1, 'parent_id': 150, 'default_product_version': 93, 'text':'Testing TCMS', } >>> TestPlan.create(values) """ from tcms.core import forms from tcms.apps.testplans.forms import XMLRPCNewPlanForm if not values.get('product'): raise ValueError('Value of product is required') form = XMLRPCNewPlanForm(values) form.populate(product_id = values['product']) if form.is_valid(): tp = TestPlan.objects.create( product = form.cleaned_data['product'], name = form.cleaned_data['name'], type = form.cleaned_data['type'], author = request.user, default_product_version = form.cleaned_data['default_product_version'], parent = form.cleaned_data['parent'], is_active = form.cleaned_data['is_active'] ) tp.add_text( author = request.user, plan_text = values['text'], ) return tp.serialize() else: return forms.errors_to_list(form)
def add_version(request, values): """ Description: Add version to specified product. Params: $product - Integer/String Integer: product_id of the product in the Database String: Product name $value - String The name of the version string. Returns: Array: Returns the newly added version object, error info if failed. Example: # Add version for specified product: >>> Product.add_version({'value': 'devel', 'product': 272}) {'product': 'QE Test Product', 'id': '1106', 'value': 'devel', 'product_id': 272} # Run it again: >>> Product.add_version({'value': 'devel', 'product': 272}) [['__all__', 'Version with this Product and Value already exists.']] """ from tcms.apps.management.forms import VersionForm from tcms.core import forms form = VersionForm(values) if form.is_valid(): version = form.save() return version.serialize() else: raise ValueError(forms.errors_to_list(form))
def update(request, case_ids, values): """Updates the fields of the selected case or cases. $values - Hash of keys matching TestCase fields and the new values to set each field to. :param case_ids: give one or more case IDs. It could be an integer, a string containing comma separated IDs, or a list of int each of them is a case ID. :type case_ids: int, str or list :param dict values: a mapping containing these case data to update. * case_status: (ini) optional * product: (ini) optional (Required if changes category) * category: (ini) optional * priority: (ini) optional * default_tester: (str or int) optional (str - user_name, int - user_id) * estimated_time: (str) optional (2h30m30s(recommend) or HH:MM:SS * is_automated: (ini) optional (0 - Manual, 1 - Auto, 2 - Both) * is_automated_proposed: (bool) optional * script: (str) optional * arguments: (str) optional * summary: (str) optional * requirement: (str) optional * alias: (str) optional * notes: (str) optional * extra_link: (str) optional (reference link) :return: a list of mappings of updated :class:`TestCase`. :rtype: list(dict) Example:: # Update alias to 'tcms' for case 1 and 2 >>> TestCase.update([1, 2], {'alias': 'tcms'}) """ from tcms.core import forms from tcms.xmlrpc.forms import UpdateCaseForm if values.get('estimated_time'): values['estimated_time'] = pre_process_estimated_time(values.get('estimated_time')) form = UpdateCaseForm(values) if values.get('category') and not values.get('product'): raise ValueError('Product ID is required for category') if values.get('product'): form.populate(product_id=values['product']) if form.is_valid(): tcs = TestCase.update( case_ids=pre_process_ids(value=case_ids), values=form.cleaned_data, ) else: raise ValueError(forms.errors_to_list(form)) query = {'pk__in': tcs.values_list('pk', flat=True)} return TestCase.to_xmlrpc(query)
def add_version(request, values): """ Description: Add version to specified product. Params: $product - Integer/String Integer: product_id of the product in the Database String: Product name $value - String The name of the version string. Returns: Array: Returns the newly added version object, error info if failed. Example: # Add version for specified product: >>> Product.add_version({'value': 'devel', 'product': 272}) {'product': 'QE Test Product', 'id': '1106', 'value': 'devel', 'product_id': 272} # Run it again: >>> Product.add_version({'value': 'devel', 'product': 272}) [['__all__', 'Version with this Product and Value already exists.']] """ from tcms.apps.management.forms import VersionForm from tcms.core import forms form = VersionForm(values) if form.is_valid(): version = form.save() return version.serialize() else: return forms.errors_to_list(form)
def attach_bug(request, values): """ Description: Add one or more bugs to the selected test cases. Params: $values - Array/Hash: A reference to a hash or array of hashes with keys and values matching the fields of the test case bug to be created. +-------------------+----------------+-----------+-------------------------------+ | Field | Type | Null | Description | +-------------------+----------------+-----------+-------------------------------+ | case_id | Integer | Required | ID of Case | | bug_id | Integer | Required | ID of Bug | | bug_system_id | Integer | Required | 1: BZ(Default), 2: JIRA | | summary | String | Optional | Bug summary | | description | String | Optional | Bug description | +-------------------+----------------+-----------+-------------------------------+ Returns: Array: empty on success or an array of hashes with failure codes if a failure occured. Example: >>> TestCase.attach_bug({ 'case_id': 12345, 'bug_id': 67890, 'bug_system_id': 1, 'summary': 'Testing TCMS', 'description': 'Just foo and bar', }) """ from tcms.core import forms from tcms.testcases.models import TestCaseBugSystem from tcms.xmlrpc.forms import AttachCaseBugForm DEFAULT_BUG_SYSTEM_ID = settings.DEFAULT_BUG_SYSTEM_ID if isinstance(values, dict): values = [values, ] for value in values: form = AttachCaseBugForm(value) if form.is_valid(): if form.cleaned_data['bug_system_id']: bug_system_id = form.cleaned_data['bug_system_id'] bug_system_id = bug_system_id if \ TestCaseBugSystem.objects.filter( pk=bug_system_id).exists() else DEFAULT_BUG_SYSTEM_ID else: bug_system_id = DEFAULT_BUG_SYSTEM_ID tc = TestCase.objects.only('pk').get(case_id=form.cleaned_data[ 'case_id']) tc.add_bug( bug_id=form.cleaned_data['bug_id'], bug_system_id=bug_system_id, summary=form.cleaned_data['summary'], description=form.cleaned_data['description'] ) else: raise ValueError(forms.errors_to_list(form)) return
def update(request, case_ids, values): """Updates the fields of the selected case or cases. $values - Hash of keys matching TestCase fields and the new values to set each field to. :param case_ids: give one or more case IDs. It could be an integer, a string containing comma separated IDs, or a list of int each of them is a case ID. :type case_ids: int, str or list :param dict values: a mapping containing these case data to update. * case_status: (ini) optional * product: (ini) optional (Required if changes category) * category: (ini) optional * priority: (ini) optional * default_tester: (str or int) optional (str - user_name, int - user_id) * estimated_time: (str) optional (2h30m30s(recommend) or HH:MM:SS * is_automated: (ini) optional (0 - Manual, 1 - Auto, 2 - Both) * is_automated_proposed: (bool) optional * script: (str) optional * arguments: (str) optional * summary: (str) optional * requirement: (str) optional * alias: (str) optional * notes: (str) optional * extra_link: (str) optional (reference link) :return: a list of mappings of updated :class:`TestCase`. :rtype: list(dict) Example:: # Update alias to 'tcms' for case 1 and 2 TestCase.update([1, 2], {'alias': 'tcms'}) """ from tcms.core import forms from tcms.xmlrpc.forms import UpdateCaseForm if values.get('estimated_time'): values['estimated_time'] = pre_process_estimated_time(values.get('estimated_time')) form = UpdateCaseForm(values) if values.get('category') and not values.get('product'): raise ValueError('Product ID is required for category') if values.get('product'): form.populate(product_id=values['product']) if form.is_valid(): tcs = TestCase.update( case_ids=pre_process_ids(value=case_ids), values=form.cleaned_data, ) else: raise ValueError(forms.errors_to_list(form)) query = {'pk__in': tcs.values_list('pk', flat=True)} return TestCase.to_xmlrpc(query)
def create(request, values): """ Description: Creates a new Test Plan object and stores it in the database. Params: $values - Hash: A reference to a hash with keys and values matching the fields of the test plan to be created. +-------------------------+----------------+-----------+------------------------------------+ | Field | Type | Null | Description | +-------------------------+----------------+-----------+------------------------------------+ | product | Integer | Required | ID of product | | name | String | Required | | | type | Integer | Required | ID of plan type | | default_product_version | Integer | Required | | | text | String | Required | Plan documents, HTML acceptable. | | parent | Integer | Optional | Parent plan ID | | is_active | Boolean | Optional | 0: Archived 1: Active (Default 0) | +-------------------------+----------------+-----------+------------------------------------+ Returns: The newly created object hash. Example: # Minimal test case parameters >>> values = { 'product': 61, 'name': 'Testplan foobar', 'type': 1, 'parent_id': 150, 'default_product_version': 93, 'text':'Testing TCMS', } >>> TestPlan.create(values) """ from tcms.core import forms from tcms.apps.testplans.forms import XMLRPCNewPlanForm if not values.get('product'): raise ValueError('Value of product is required') form = XMLRPCNewPlanForm(values) form.populate(product_id=values['product']) if form.is_valid(): tp = TestPlan.objects.create(product=form.cleaned_data['product'], name=form.cleaned_data['name'], type=form.cleaned_data['type'], author=request.user, default_product_version=form. cleaned_data['default_product_version'], parent=form.cleaned_data['parent'], is_active=form.cleaned_data['is_active']) tp.add_text( author=request.user, plan_text=values['text'], ) return tp.serialize() else: raise ValueError(forms.errors_to_list(form))
def attach_bug(request, values): """Add one or more bugs to the selected test cases. :param values: mapping or list of mappings containing these bug information. * case_id: (int) **Required**. Case ID. * bug_id: (int) **Required**. Bug ID. * bug_system_id: (int) **Required**. It could be ``1`` representing BZ(Default) and ``2`` representing JIRA. * summary: (str) optional Bug summary. * description: (str) optional bug description. :return: a list which is empty on success or a list of mappings with failure codes if a failure occured. Example:: # Bug data to add >>> values = { 'case_id': 1, 'bug_id': 1000, 'bug_system_id': 1, 'summary': 'Testing TCMS', 'description': 'Just foo and bar', } >>> TestCase.attach_bug(values) """ from tcms.core import forms from tcms.testcases.models import TestCaseBugSystem from tcms.xmlrpc.forms import AttachCaseBugForm DEFAULT_BUG_SYSTEM_ID = settings.DEFAULT_BUG_SYSTEM_ID if isinstance(values, dict): values = [ values, ] for value in values: form = AttachCaseBugForm(value) if form.is_valid(): if form.cleaned_data['bug_system_id']: bug_system_id = form.cleaned_data['bug_system_id'] bug_system_id = bug_system_id if \ TestCaseBugSystem.objects.filter( pk=bug_system_id).exists() else DEFAULT_BUG_SYSTEM_ID else: bug_system_id = DEFAULT_BUG_SYSTEM_ID tc = TestCase.objects.only('pk').get( case_id=form.cleaned_data['case_id']) tc.add_bug(bug_id=form.cleaned_data['bug_id'], bug_system_id=bug_system_id, summary=form.cleaned_data['summary'], description=form.cleaned_data['description']) else: raise ValueError(forms.errors_to_list(form)) return
def create(request, values): """ *** It always report - ValueError: invalid literal for int() with base 10: '' *** Description: Creates a new Test Case Run object and stores it in the database. Params: $values - Hash: A reference to a hash with keys and values matching the fields of the test case to be created. +--------------------+----------------+-----------+------------------------------------------------+ | Field | Type | Null | Description | +--------------------+----------------+-----------+------------------------------------------------+ | run | Integer | Required | ID of Test Run | | case | Integer | Required | ID of test case | | build | Integer | Required | ID of a Build in plan's product | | assignee | Integer | Optional | ID of assignee | | case_run_status | Integer | Optional | Defaults to "IDLE" | | case_text_version | Integer | Optional | Default to latest case text version | | notes | String | Optional | | | sortkey | Integer | Optional | a.k.a. Index, Default to 0 | +--------------------+----------------+-----------+------------------------------------------------+ Returns: The newly created object hash. Example: # Minimal test case parameters >>> values = { 'run': 1990, 'case': 12345, 'build': 123, } >>> TestCaseRun.create(values) """ from tcms.core import forms from tcms.testruns.forms import XMLRPCNewCaseRunForm form = XMLRPCNewCaseRunForm(values) if not isinstance(values, dict): raise TypeError('Argument values must be in dict type.') if not values: raise ValueError('Argument values is empty.') if form.is_valid(): tr = form.cleaned_data['run'] tcr = tr.add_case_run( case=form.cleaned_data['case'], build=form.cleaned_data['build'], assignee=form.cleaned_data['assignee'], case_run_status=form.cleaned_data['case_run_status'], case_text_version=form.cleaned_data['case_text_version'], notes=form.cleaned_data['notes'], sortkey=form.cleaned_data['sortkey']) else: raise ValueError(forms.errors_to_list(form)) return tcr.serialize()
def attach_bug(request, values): """Add one or more bugs to the selected test cases. :param values: mapping or list of mappings containing these bug information. * case_id: (int) **Required**. Case ID. * bug_id: (int) **Required**. Bug ID. * bug_system_id: (int) **Required**. It could be ``1`` representing BZ(Default) and ``2`` representing JIRA. * summary: (str) optional Bug summary. * description: (str) optional bug description. :return: a list which is empty on success or a list of mappings with failure codes if a failure occured. Example:: # Bug data to add >>> values = { 'case_id': 1, 'bug_id': 1000, 'bug_system_id': 1, 'summary': 'Testing TCMS', 'description': 'Just foo and bar', } >>> TestCase.attach_bug(values) """ from tcms.core import forms from tcms.testcases.models import TestCaseBugSystem from tcms.xmlrpc.forms import AttachCaseBugForm DEFAULT_BUG_SYSTEM_ID = settings.DEFAULT_BUG_SYSTEM_ID if isinstance(values, dict): values = [values, ] for value in values: form = AttachCaseBugForm(value) if form.is_valid(): if form.cleaned_data['bug_system_id']: bug_system_id = form.cleaned_data['bug_system_id'] bug_system_id = bug_system_id if \ TestCaseBugSystem.objects.filter( pk=bug_system_id).exists() else DEFAULT_BUG_SYSTEM_ID else: bug_system_id = DEFAULT_BUG_SYSTEM_ID tc = TestCase.objects.only('pk').get(case_id=form.cleaned_data[ 'case_id']) tc.add_bug( bug_id=form.cleaned_data['bug_id'], bug_system_id=bug_system_id, summary=form.cleaned_data['summary'], description=form.cleaned_data['description'] ) else: raise ValueError(forms.errors_to_list(form)) return
def create(request, values): """ *** It always report - ValueError: invalid literal for int() with base 10: '' *** Description: Creates a new Test Case Run object and stores it in the database. Params: $values - Hash: A reference to a hash with keys and values matching the fields of the test case to be created. +--------------------+----------------+-----------+------------------------------------------------+ | Field | Type | Null | Description | +--------------------+----------------+-----------+------------------------------------------------+ | run | Integer | Required | ID of Test Run | | case | Integer | Required | ID of test case | | build | Integer | Required | ID of a Build in plan's product | | assignee | Integer | Optional | ID of assignee | | case_run_status | Integer | Optional | Defaults to "IDLE" | | case_text_version | Integer | Optional | Default to latest case text version | | notes | String | Optional | | | sortkey | Integer | Optional | a.k.a. Index, Default to 0 | +--------------------+----------------+-----------+------------------------------------------------+ Returns: The newly created object hash. Example: # Minimal test case parameters >>> values = { 'run': 1990, 'case': 12345, 'build': 123, } >>> TestCaseRun.create(values) """ from tcms.core import forms from tcms.apps.testcases.models import TestCase from tcms.apps.testruns.models import TestRun from tcms.apps.testruns.forms import XMLRPCNewCaseRunForm form = XMLRPCNewCaseRunForm(values) if form.is_valid(): tr = form.cleaned_data['run'] tcr = tr.add_case_run( case = form.cleaned_data['case'], build = form.cleaned_data['build'], assignee = form.cleaned_data['assignee'], case_run_status = form.cleaned_data['case_run_status'], case_text_version = form.cleaned_data['case_text_version'], notes = form.cleaned_data['notes'], sortkey = form.cleaned_data['sortkey'] ) else: return forms.errors_to_list(form) return tcr.serialize()
def create(request, values): """Creates a new Test Case Run object and stores it in the database. :param dict values: a mapping containing these data to create a case run. * run: (int) **Required** ID of Test Run * case: (int) **Required** ID of test case * build: (int) **Required** ID of a Build in plan's product * assignee: (int) optional ID of assignee * case_run_status: (int) optional Defaults to "IDLE" * case_text_version: (int) optional Default to latest case text version * notes: (str) optional * sortkey: (int) optional a.k.a. Index, Default to 0 :return: a mapping representing a newly created case run. :rtype: dict Example:: # Minimal test case parameters >>> values = { 'run': 1990, 'case': 12345, 'build': 123, } >>> TestCaseRun.create(values) """ from tcms.core import forms from tcms.testruns.forms import XMLRPCNewCaseRunForm form = XMLRPCNewCaseRunForm(values) if not isinstance(values, dict): raise TypeError('Argument values must be in dict type.') if not values: raise ValueError('Argument values is empty.') if form.is_valid(): tr = form.cleaned_data['run'] tcr = tr.add_case_run( case=form.cleaned_data['case'], build=form.cleaned_data['build'], assignee=form.cleaned_data['assignee'], case_run_status=form.cleaned_data['case_run_status'], case_text_version=form.cleaned_data['case_text_version'], notes=form.cleaned_data['notes'], sortkey=form.cleaned_data['sortkey'] ) else: raise ValueError(forms.errors_to_list(form)) return tcr.serialize()
def create(request, values): """Creates a new Test Case Run object and stores it in the database. :param dict values: a mapping containing these data to create a case run. * run: (int) **Required** ID of Test Run * case: (int) **Required** ID of test case * build: (int) **Required** ID of a Build in plan's product * assignee: (int) optional ID of assignee * case_run_status: (int) optional Defaults to "IDLE" * case_text_version: (int) optional Default to latest case text version * notes: (str) optional * sortkey: (int) optional a.k.a. Index, Default to 0 :return: a mapping representing a newly created case run. :rtype: dict Example:: # Minimal test case parameters values = { 'run': 1990, 'case': 12345, 'build': 123, } TestCaseRun.create(values) """ from tcms.core import forms from tcms.testruns.forms import XMLRPCNewCaseRunForm form = XMLRPCNewCaseRunForm(values) if not isinstance(values, dict): raise TypeError('Argument values must be in dict type.') if not values: raise ValueError('Argument values is empty.') if form.is_valid(): tr = form.cleaned_data['run'] tcr = tr.add_case_run( case=form.cleaned_data['case'], build=form.cleaned_data['build'], assignee=form.cleaned_data['assignee'], case_run_status=form.cleaned_data['case_run_status'], case_text_version=form.cleaned_data['case_text_version'], notes=form.cleaned_data['notes'], sortkey=form.cleaned_data['sortkey'] ) else: raise ValueError(forms.errors_to_list(form)) return tcr.serialize()
def attach_bug(request, values): """Add one or more bugs to the selected test cases. :param dict values: a mapping containing these data to create a test run. * case_run_id: (int) **Required** ID of Case * bug_id: (int) **Required** ID of Bug * bug_system_id: (int) **Required** 1: BZ(Default), 2: JIRA * summary: (str) optional Bug summary * description: (str) optional Bug description :return: a list which is empty on success or a list of mappings with failure codes if a failure occured. :rtype: list Example:: # Attach a bug 67890 to case run 12345 >>> TestCaseRun.attach_bug({ 'case_run_id': 12345, 'bug_id': 67890, 'bug_system_id': 1, 'summary': 'Testing TCMS', 'description': 'Just foo and bar', }) """ from tcms.core import forms from tcms.testcases.models import TestCaseBugSystem from tcms.xmlrpc.forms import AttachCaseRunBugForm if isinstance(values, dict): values = [ values, ] for value in values: form = AttachCaseRunBugForm(value) if form.is_valid(): bug_system = TestCaseBugSystem.objects.get( id=form.cleaned_data['bug_system_id']) tcr = TestCaseRun.objects.only( 'pk', 'case').get(case_run_id=form.cleaned_data['case_run_id']) tcr.add_bug(bug_id=form.cleaned_data['bug_id'], bug_system_id=bug_system.pk, summary=form.cleaned_data['summary'], description=form.cleaned_data['description']) else: raise ValueError(forms.errors_to_list(form)) return
def attach_bug(request, values): """Add one or more bugs to the selected test cases. :param dict values: a mapping containing these data to create a test run. * case_run_id: (int) **Required** ID of Case * bug_id: (int) **Required** ID of Bug * bug_system_id: (int) **Required** 1: BZ(Default), 2: JIRA * summary: (str) optional Bug summary * description: (str) optional Bug description :return: a list which is empty on success or a list of mappings with failure codes if a failure occured. :rtype: list Example:: # Attach a bug 67890 to case run 12345 >>> TestCaseRun.attach_bug({ 'case_run_id': 12345, 'bug_id': 67890, 'bug_system_id': 1, 'summary': 'Testing TCMS', 'description': 'Just foo and bar', }) """ from tcms.core import forms from tcms.testcases.models import TestCaseBugSystem from tcms.xmlrpc.forms import AttachCaseRunBugForm if isinstance(values, dict): values = [values, ] for value in values: form = AttachCaseRunBugForm(value) if form.is_valid(): bug_system = TestCaseBugSystem.objects.get( id=form.cleaned_data['bug_system_id']) tcr = TestCaseRun.objects.only('pk', 'case').get( case_run_id=form.cleaned_data['case_run_id']) tcr.add_bug( bug_id=form.cleaned_data['bug_id'], bug_system_id=bug_system.pk, summary=form.cleaned_data['summary'], description=form.cleaned_data['description'] ) else: raise ValueError(forms.errors_to_list(form)) return
def update(request, plan_ids, values): """ Description: Updates the fields of the selected test plan. Params: $plan_ids - Integer: A single (or list of) TestPlan ID. $values - Hash of keys matching TestPlan fields and the new values to set each field to. +-------------------------------------------+----------------+--------------------------------------------+ | Field | Type | Description | +-------------------------------------------+----------------+--------------------------------------------+ | product | Integer | ID of product | | name | String | | | type | Integer | ID of plan type | | product_version(default_product_version) | Integer | ID of version, product_version(recommend), | | | | default_product_version will be deprecated | | | | in future release. | | owner | String/Integer | user_name/user_id | | parent | Integer | Parent plan ID | | is_active | Boolean | True/False | | env_group | Integer | New environment group ID | +-------------------------+----------------+--------------------------------------------------------------+ Returns: Hash: The updated test plan object. Example: # Update product to 61 for plan 207 and 208 >>> TestPlan.update([207, 208], {'product': 61}) """ from tcms.core import forms from tcms.xmlrpc.forms import EditPlanForm if values.get('default_product_version'): values['product_version'] = values.pop('default_product_version') form = EditPlanForm(values) if values.get('product_version') and not values.get('product'): raise ValueError('Field "product" is required by product_version') if values.get('product') and not values.get('product_version'): raise ValueError('Field "product_version" is required by product') if values.get('product_version') and values.get('product'): form.populate(product_id=values['product']) plan_ids = pre_process_ids(value=plan_ids) tps = TestPlan.objects.filter(pk__in=plan_ids) if form.is_valid(): _values = dict() if form.cleaned_data['name']: _values['name'] = form.cleaned_data['name'] if form.cleaned_data['type']: _values['type'] = form.cleaned_data['type'] if form.cleaned_data['product']: _values['product'] = form.cleaned_data['product'] if form.cleaned_data['product_version']: _values['product_version'] = form.cleaned_data[ 'product_version'] if form.cleaned_data['owner']: _values['owner'] = form.cleaned_data['owner'] if form.cleaned_data['parent']: _values['parent'] = form.cleaned_data['parent'] if not (values.get('is_active') is None): _values['is_active'] = form.cleaned_data['is_active'] tps.update(**_values) # requested to update environment group for selected test plans if form.cleaned_data['env_group']: # prepare the list of new objects to be inserted into DB new_objects = [ TCMSEnvPlanMap( plan_id=plan_pk, group_id=form.cleaned_data['env_group'].pk ) for plan_pk in plan_ids ] # first delete the old values (b/c many-to-many I presume ?) TCMSEnvPlanMap.objects.filter(plan__in=plan_ids).delete() # then create all objects with 1 INSERT TCMSEnvPlanMap.objects.bulk_create(new_objects) else: raise ValueError(forms.errors_to_list(form)) query = {'pk__in': tps.values_list('pk', flat=True)} return TestPlan.to_xmlrpc(query)
def __check_form_validation(self): form = self.__get_form() if not form.is_valid(): return 0, self.render_ajax(forms.errors_to_list(form)) return 1, form
def update(request, run_ids, values): """ Description: Updates the fields of the selected test run. Params: $run_ids - Integer/Array/String: An integer or alias representing the ID in the database, an array of run_ids, or a string of comma separated run_ids. $values - Hash of keys matching TestRun fields and the new values to set each field to. See params of TestRun.create for description +-------------------+----------------+--------------------------------+ | Field | Type | Description | +-------------------+----------------+--------------------------------+ | plan | Integer | TestPlan.plan_id | | product | Integer | Product.id | | build | Integer | Build.id | | manager | Integer | Auth.User.id | | default_tester | Intege | Auth.User.id | | summary | String | | | estimated_time | TimeDelta | 2h30m30s(recommend) or HH:MM:SS| | product_version | Integer | | | plan_text_version | Integer | | | notes | String | | | status | Integer | 0:RUNNING 1:FINISHED | +-------------------+----------------+ -------------------------------+ Returns: Hash: The updated test run object. Example: # Update status to finished for run 1193 and 1194 >>> TestRun.update([1193, 1194], {'status': 1}) """ from datetime import datetime from tcms.core import forms from tcms.testruns.forms import XMLRPCUpdateRunForm if (values.get('product_version') and not values.get('product')): raise ValueError('Field "product" is required by product_version') if values.get('estimated_time'): values['estimated_time'] = pre_process_estimated_time( values.get('estimated_time')) form = XMLRPCUpdateRunForm(values) if values.get('product_version'): form.populate(product_id=values['product']) if form.is_valid(): trs = TestRun.objects.filter(pk__in=pre_process_ids(value=run_ids)) _values = dict() if form.cleaned_data['plan']: _values['plan'] = form.cleaned_data['plan'] if form.cleaned_data['build']: _values['build'] = form.cleaned_data['build'] if form.cleaned_data['manager']: _values['manager'] = form.cleaned_data['manager'] if 'default_tester' in values: if values.get('default_tester') and \ form.cleaned_data['default_tester']: _values['default_tester'] = form.cleaned_data['default_tester'] else: _values['default_tester'] = None if form.cleaned_data['summary']: _values['summary'] = form.cleaned_data['summary'] if values.get('estimated_time') is not None: _values['estimated_time'] = form.cleaned_data['estimated_time'] if form.cleaned_data['product_version']: _values['product_version'] = form.cleaned_data['product_version'] if 'notes' in values: if values['notes'] in (None, ''): _values['notes'] = values['notes'] if form.cleaned_data['notes']: _values['notes'] = form.cleaned_data['notes'] if form.cleaned_data['plan_text_version']: _values['plan_text_version'] = form.cleaned_data[ 'plan_text_version'] if isinstance(form.cleaned_data['status'], int): if form.cleaned_data['status']: _values['stop_date'] = datetime.now() else: _values['stop_date'] = None trs.update(**_values) else: raise ValueError(forms.errors_to_list(form)) query = {'pk__in': trs.values_list('pk', flat=True)} return TestRun.to_xmlrpc(query)
def update(request, plan_ids, values): """ Description: Updates the fields of the selected test plan. Params: $plan_ids - Integer: A single TestPlan ID. $values - Hash of keys matching TestPlan fields and the new values to set each field to. +------------------------+----------------+------------------------------------+ | Field | Type | Description | +-------------------------+----------------+------------------------------------+ | product | Integer | ID of product | | name | String | | | type | Integer | ID of plan type | | default_product_version | Integer | | | parent | Integer | Parent plan ID | | is_active | Boolean | True/False | | env_group | Integer | | +-------------------------+----------------+------------------------------------+ Returns: Hash: The updated test plan object. Example: # Update product to 61 for plan 207 and 208 >>> TestPlan.update([207, 208], {'product': 61}) """ from tcms.core import forms from tcms.apps.testplans.forms import XMLRPCEditPlanForm if values.get('is_active') in (False, True): if values.get('is_active') == False: values['is_active'] = 0 else: values['is_active'] = 1 form = XMLRPCEditPlanForm(values) if values.get('default_product_version') and not values.get('product'): raise ValueError( 'Product value is required by default product version') if values.get('default_product_version') and values.get('product'): form.populate(product_id=values['product']) tps = TestPlan.objects.filter(pk__in=pre_process_ids(value=plan_ids)) if form.is_valid(): _values = dict() if form.cleaned_data['name']: _values['name'] = form.cleaned_data['name'] if form.cleaned_data['type']: _values['type'] = form.cleaned_data['type'] if form.cleaned_data['product']: _values['product'] = form.cleaned_data['product'] if form.cleaned_data['default_product_version']: _values['default_product_version'] = form.cleaned_data[ 'default_product_version'] if form.cleaned_data['parent']: _values['parent'] = form.cleaned_data['parent'] if isinstance(form.cleaned_data['is_active'], int): _values['is_active'] = form.cleaned_data['is_active'] tps.update(**_values) if form.cleaned_data['env_group']: for tp in tps.iterator(): tp.clear_env_groups() tp.add_env_group(form.cleaned_data['env_group']) else: raise ValueError(forms.errors_to_list(form)) query = {'pk__in': tps.values_list('pk', flat=True)} return TestPlan.to_xmlrpc(query)
def create(request, values): """ Description: Creates a new Test Run object and stores it in the database. Params: $values - Hash: A reference to a hash with keys and values matching the fields of the test run to be created. +-------------------+----------------+-----------+---------------------------------------+ | Field | Type | Null | Description | +-------------------+----------------+-----------+---------------------------------------+ | plan | Integer | Required | ID of test plan | | build | Integer/String | Required | ID of Build | | manager | Integer | Required | ID of run manager | | summary | String | Required | | | product | Integer | Required | ID of product | | product_version | Integer | Required | ID of product version | | default_tester | Integer | Optional | ID of run default tester | | plan_text_version | Integer | Optional | | | estimated_time | String | Optional | 2h30m30s(recommend) or HH:MM:SS Format| | notes | String | Optional | | | status | Integer | Optional | 0:RUNNING 1:STOPPED (default 0) | | case | Array/String | Optional | list of case ids to add to the run | | tag | Array/String | Optional | list of tag to add to the run | +-------------------+----------------+-----------+---------------------------------------+ Returns: The newly created object hash. Example: >>> values = {'build': 384, 'manager': 137, 'plan': 137, 'product': 61, 'product_version': 93, 'summary': 'Testing XML-RPC for TCMS', } >>> TestRun.create(values) """ from datetime import datetime from tcms.core import forms from tcms.testruns.forms import XMLRPCNewRunForm if not values.get('product'): raise ValueError('Value of product is required') # TODO: XMLRPC only accept HH:MM:SS rather than DdHhMm if values.get('estimated_time'): values['estimated_time'] = pre_process_estimated_time( values.get('estimated_time')) if values.get('case'): values['case'] = pre_process_ids(value=values['case']) form = XMLRPCNewRunForm(values) form.populate(product_id=values['product']) if form.is_valid(): tr = TestRun.objects.create( product_version=form.cleaned_data['product_version'], plan_text_version=form.cleaned_data['plan_text_version'], stop_date=form.cleaned_data['status'] and datetime.now() or None, summary=form.cleaned_data['summary'], notes=form.cleaned_data['notes'], estimated_time=form.cleaned_data['estimated_time'], plan=form.cleaned_data['plan'], build=form.cleaned_data['build'], manager=form.cleaned_data['manager'], default_tester=form.cleaned_data['default_tester'], ) if form.cleaned_data['case']: for c in form.cleaned_data['case']: tr.add_case_run(case=c) del c if form.cleaned_data['tag']: tags = form.cleaned_data['tag'] if isinstance(tags, str): tags = [c.strip() for c in tags.split(',') if c] for tag in tags: t, c = TestTag.objects.get_or_create(name=tag) tr.add_tag(tag=t) del tag, t, c else: raise ValueError(forms.errors_to_list(form)) return tr.serialize()
def update(request, plan_ids, values): """Updates the fields of the selected test plan. :param plan_ids: give one or more plan IDs. It could be an integer, a string containing comma separated IDs, or a list of int each of them is a plan ID. :type plan_ids: int, str or list :param dict values: a mapping containing these plan data to update * product: (int) ID of product * name: (str) * type: (int) ID of plan type * product_version: (int) ID of version * default_product_version: (int) alternative version ID. * owner: (str)/(int) user_name/user_id * parent: (int) Parent plan ID * is_active: bool True/False * env_group: (int) New environment group ID :return: a mapping of updated :class:`TestPlan`. :rtype: dict Example:: # Update product to 7 for plan 1 and 2 TestPlan.update([1, 2], {'product': 7}) .. deprecated:: x.y ``default_product_version`` is deprecated and will be removed. """ from tcms.core import forms from tcms.xmlrpc.forms import EditPlanForm if values.get('default_product_version'): values['product_version'] = values.pop('default_product_version') form = EditPlanForm(values) if values.get('product_version') and not values.get('product'): raise ValueError('Field "product" is required by product_version') if values.get('product') and not values.get('product_version'): raise ValueError('Field "product_version" is required by product') if values.get('product_version') and values.get('product'): form.populate(product_id=values['product']) plan_ids = pre_process_ids(value=plan_ids) tps = TestPlan.objects.filter(pk__in=plan_ids) if form.is_valid(): _values = dict() if form.cleaned_data['name']: _values['name'] = form.cleaned_data['name'] if form.cleaned_data['type']: _values['type'] = form.cleaned_data['type'] if form.cleaned_data['product']: _values['product'] = form.cleaned_data['product'] if form.cleaned_data['product_version']: _values['product_version'] = form.cleaned_data['product_version'] if form.cleaned_data['owner']: _values['owner'] = form.cleaned_data['owner'] if form.cleaned_data['parent']: _values['parent'] = form.cleaned_data['parent'] if not (values.get('is_active') is None): _values['is_active'] = form.cleaned_data['is_active'] tps.update(**_values) # requested to update environment group for selected test plans if form.cleaned_data['env_group']: # prepare the list of new objects to be inserted into DB new_objects = [ TCMSEnvPlanMap(plan_id=plan_pk, group_id=form.cleaned_data['env_group'].pk) for plan_pk in plan_ids ] # first delete the old values (b/c many-to-many I presume ?) TCMSEnvPlanMap.objects.filter(plan__in=plan_ids).delete() # then create all objects with 1 INSERT TCMSEnvPlanMap.objects.bulk_create(new_objects) else: raise ValueError(forms.errors_to_list(form)) query = {'pk__in': tps.values_list('pk', flat=True)} return TestPlan.to_xmlrpc(query)
def update(request, case_run_ids, values): """Updates the fields of the selected case-runs. :param case_run_ids: give one or more case run IDs. It could be an integer, a string containing comma separated IDs, or a list of int each of them is a case run ID. :type run_ids: int, str or list :param dict values: a mapping containing these data to update specified case runs. * build: (int) * assignee: (int) * case_run_status: (int) * notes: (str) * sortkey: (int) :return: In the case of a single object, it is returned. If a list was passed, it returns an array of object hashes. If the update on any particular object failed, the hash will contain a ERROR key and the message as to why it failed. Example:: # Update alias to 'tcms' for case 12345 and 23456 >>> TestCaseRun.update([12345, 23456], {'assignee': 2206}) """ from datetime import datetime from tcms.core import forms from tcms.testruns.forms import XMLRPCUpdateCaseRunForm pks_to_update = pre_process_ids(case_run_ids) tcrs = TestCaseRun.objects.filter(pk__in=pks_to_update) form = XMLRPCUpdateCaseRunForm(values) if form.is_valid(): data = {} if form.cleaned_data['build']: data['build'] = form.cleaned_data['build'] if form.cleaned_data['assignee']: data['assignee'] = form.cleaned_data['assignee'] if form.cleaned_data['case_run_status']: data['case_run_status'] = form.cleaned_data['case_run_status'] data['tested_by'] = request.user data['close_date'] = datetime.now() if 'notes' in values: if values['notes'] in (None, ''): data['notes'] = values['notes'] if form.cleaned_data['notes']: data['notes'] = form.cleaned_data['notes'] if form.cleaned_data['sortkey'] is not None: data['sortkey'] = form.cleaned_data['sortkey'] tcrs.update(**data) else: raise ValueError(forms.errors_to_list(form)) query = {'pk__in': pks_to_update} return TestCaseRun.to_xmlrpc(query)
def create(request, values): """Creates a new Test Run object and stores it in the database. :param dict values: a mapping containing these data to create a test run. * plan: (int) **Required** ID of test plan * build: (int)/(str) **Required** ID of Build * manager: (int) **Required** ID of run manager * summary: (str) **Required** * product: (int) **Required** ID of product * product_version: (int) **Required** ID of product version * default_tester: (int) optional ID of run default tester * plan_text_version: (int) optional * estimated_time: (str) optional, could be in format ``2h30m30s``, which is recommended or ``HH:MM:SS``. * notes: (str) optional * status: (int) optional 0:RUNNING 1:STOPPED (default 0) * case: list or (str) optional list of case ids to add to the run * tag: list or (str) optional list of tag to add to the run :return: a mapping representing newly created :class:`TestRun`. :rtype: dict .. versionchanged:: 4.5 Argument ``errata_id`` is removed. Example:: values = { 'build': 2, 'manager': 1, 'plan': 1, 'product': 1, 'product_version': 2, 'summary': 'Testing XML-RPC for TCMS', } TestRun.create(values) """ from datetime import datetime from tcms.core import forms from tcms.testruns.forms import XMLRPCNewRunForm if not values.get('product'): raise ValueError('Value of product is required') # TODO: XMLRPC only accept HH:MM:SS rather than DdHhMm if values.get('estimated_time'): values['estimated_time'] = pre_process_estimated_time( values.get('estimated_time')) if values.get('case'): values['case'] = pre_process_ids(value=values['case']) form = XMLRPCNewRunForm(values) form.populate(product_id=values['product']) if form.is_valid(): tr = TestRun.objects.create( product_version=form.cleaned_data['product_version'], plan_text_version=form.cleaned_data['plan_text_version'], stop_date=form.cleaned_data['status'] and datetime.now() or None, summary=form.cleaned_data['summary'], notes=form.cleaned_data['notes'], estimated_time=form.cleaned_data['estimated_time'], plan=form.cleaned_data['plan'], build=form.cleaned_data['build'], manager=form.cleaned_data['manager'], default_tester=form.cleaned_data['default_tester'], ) if form.cleaned_data['case']: for c in form.cleaned_data['case']: tr.add_case_run(case=c) del c if form.cleaned_data['tag']: tags = form.cleaned_data['tag'] if isinstance(tags, str): tags = [c.strip() for c in tags.split(',') if c] for tag in tags: t, c = TestTag.objects.get_or_create(name=tag) tr.add_tag(tag=t) del tag, t, c else: raise ValueError(forms.errors_to_list(form)) return tr.serialize()
def update(request, run_ids, values): """Updates the fields of the selected test run. :param run_ids: give one or more run IDs. It could be an integer, a string containing comma separated IDs, or a list of int each of them is a run ID. :type run_ids: int, str or list :param dict values: a mapping containing these data to update specified runs. * plan: (int) TestPlan.plan_id * product: (int) Product.id * build: (int) Build.id * manager: (int) Auth.User.id * default_tester: Intege Auth.User.id * summary: (str) * estimated_time: (TimeDelta) in format ``2h30m30s`` which is recommended or ``HH:MM:SS``. * product_version: (int) * plan_text_version: (int) * notes: (str) * status: (int) 0:RUNNING 1:FINISHED :return: list of mappings of the updated test runs. :rtype: list[dict] .. versionchanged:: 4.5 Argument ``errata_id`` is removed. Example:: # Update status to finished for run 1 and 2 TestRun.update([1, 2], {'status': 1}) """ from datetime import datetime from tcms.core import forms from tcms.testruns.forms import XMLRPCUpdateRunForm if (values.get('product_version') and not values.get('product')): raise ValueError('Field "product" is required by product_version') if values.get('estimated_time'): values['estimated_time'] = pre_process_estimated_time( values.get('estimated_time')) form = XMLRPCUpdateRunForm(values) if values.get('product_version'): form.populate(product_id=values['product']) if form.is_valid(): trs = TestRun.objects.filter(pk__in=pre_process_ids(value=run_ids)) _values = dict() if form.cleaned_data['plan']: _values['plan'] = form.cleaned_data['plan'] if form.cleaned_data['build']: _values['build'] = form.cleaned_data['build'] if form.cleaned_data['manager']: _values['manager'] = form.cleaned_data['manager'] if 'default_tester' in values: default_tester = form.cleaned_data['default_tester'] if values.get('default_tester') and default_tester: _values['default_tester'] = default_tester else: _values['default_tester'] = None if form.cleaned_data['summary']: _values['summary'] = form.cleaned_data['summary'] if values.get('estimated_time') is not None: _values['estimated_time'] = form.cleaned_data['estimated_time'] if form.cleaned_data['product_version']: _values['product_version'] = form.cleaned_data['product_version'] if 'notes' in values: if values['notes'] in (None, ''): _values['notes'] = values['notes'] if form.cleaned_data['notes']: _values['notes'] = form.cleaned_data['notes'] if form.cleaned_data['plan_text_version']: _values['plan_text_version'] = form.cleaned_data[ 'plan_text_version'] if isinstance(form.cleaned_data['status'], int): if form.cleaned_data['status']: _values['stop_date'] = datetime.now() else: _values['stop_date'] = None trs.update(**_values) else: raise ValueError(forms.errors_to_list(form)) query = {'pk__in': trs.values_list('pk', flat=True)} return TestRun.to_xmlrpc(query)
def update(request, case_ids, values): """ Description: Updates the fields of the selected case or cases. Params: $case_ids - Integer/String/Array Integer: A single TestCase ID. String: A comma separates string of TestCase IDs for batch processing. Array: An array of case IDs for batch mode processing $values - Hash of keys matching TestCase fields and the new values to set each field to. Returns: Array: an array of case hashes. If the update on any particular case failed, the has will contain a ERROR key and the message as to why it failed. +-----------------------+----------------+-----------------------------------------+ | Field | Type | Null | +-----------------------+----------------+-----------------------------------------+ | case_status | Integer | Optional | | product | Integer | Optional(Required if changes category) | | category | Integer | Optional | | priority | Integer | Optional | | default_tester | String/Integer | Optional(str - user_name, int - user_id)| | estimated_time | String | Optional | | is_automated | Integer | Optional(0 - Manual, 1 - Auto, 2 - Both)| | is_automated_proposed | Boolean | Optional | | script | String | Optional | | arguments | String | Optional | | summary | String | Optional | | requirement | String | Optional | | alias | String | Optional | | notes | String | Optional | | extra_link | String | Optional(reference link) +-----------------------+----------------+-----------------------------------------+ Example: # Update alias to 'tcms' for case 12345 and 23456 >>> TestCase.update([12345, 23456], {'alias': 'tcms'}) """ from tcms.core import forms from tcms.apps.testcases.forms import XMLRPCUpdateCaseForm form = XMLRPCUpdateCaseForm(values) if values.get('category') and not values.get('product'): raise ValueError('Product ID is required for category') if values.get('product'): form.populate(product_id = values['product']) if form.is_valid(): tcs = TestCase.update( case_ids = pre_process_ids(value = case_ids), values = form.cleaned_data, ) else: return forms.errors_to_list(form) query = {'pk__in': tcs.values_list('pk', flat = True)} return TestCase.to_xmlrpc(query)
def create(request, values): """ Description: Creates a new Test Run object and stores it in the database. Params: $values - Hash: A reference to a hash with keys and values matching the fields of the test run to be created. +-------------------+----------------+-----------+---------------------------------------+ | Field | Type | Null | Description | +-------------------+----------------+-----------+---------------------------------------+ | plan | Integer | Required | ID of test plan | | build | Integer/String | Required | ID of Build | | errata_id | Integer | Optional | ID of Errata | | manager | Integer | Required | ID of run manager | | summary | String | Required | | | product | Integer | Required | ID of product | | product_version | Integer | Required | ID of product version | | default_tester | Integer | Optional | ID of run default tester | | plan_text_version | Integer | Optional | | | estimated_time | String | Optional | 2h30m30s(recommend) or HH:MM:SS Format| | notes | String | Optional | | | status | Integer | Optional | 0:RUNNING 1:STOPPED (default 0) | | case | Array/String | Optional | list of case ids to add to the run | | tag | Array/String | Optional | list of tag to add to the run | +-------------------+----------------+-----------+---------------------------------------+ Returns: The newly created object hash. Example: >>> values = {'build': 384, 'manager': 137, 'plan': 137, 'errata_id': 124, 'product': 61, 'product_version': 93, 'summary': 'Testing XML-RPC for TCMS', } >>> TestRun.create(values) """ from datetime import datetime from tcms.core import forms from tcms.testruns.forms import XMLRPCNewRunForm if not values.get('product'): raise ValueError('Value of product is required') # TODO: XMLRPC only accept HH:MM:SS rather than DdHhMm if values.get('estimated_time'): values['estimated_time'] = pre_process_estimated_time( values.get('estimated_time')) if values.get('case'): values['case'] = pre_process_ids(value=values['case']) form = XMLRPCNewRunForm(values) form.populate(product_id=values['product']) if form.is_valid(): tr = TestRun.objects.create( product_version=form.cleaned_data['product_version'], plan_text_version=form.cleaned_data['plan_text_version'], stop_date=form.cleaned_data['status'] and datetime.now() or None, summary=form.cleaned_data['summary'], notes=form.cleaned_data['notes'], estimated_time=form.cleaned_data['estimated_time'], plan=form.cleaned_data['plan'], build=form.cleaned_data['build'], errata_id=form.cleaned_data['errata_id'], manager=form.cleaned_data['manager'], default_tester=form.cleaned_data['default_tester'], ) if form.cleaned_data['case']: for c in form.cleaned_data['case']: tr.add_case_run(case=c) del c if form.cleaned_data['tag']: tags = form.cleaned_data['tag'] if isinstance(tags, str): tags = [c.strip() for c in tags.split(',') if c] for tag in tags: t, c = TestTag.objects.get_or_create(name=tag) tr.add_tag(tag=t) del tag, t, c else: raise ValueError(forms.errors_to_list(form)) return tr.serialize()
def update(request, plan_ids, values): """Updates the fields of the selected test plan. :param plan_ids: give one or more plan IDs. It could be an integer, a string containing comma separated IDs, or a list of int each of them is a plan ID. :type plan_ids: int, str or list :param dict values: a mapping containing these plan data to update * product: (int) ID of product * name: (str) * type: (int) ID of plan type * product_version: (int) ID of version * default_product_version: (int) alternative version ID. * owner: (str)/(int) user_name/user_id * parent: (int) Parent plan ID * is_active: bool True/False * env_group: (int) New environment group ID :return: a mapping of updated :class:`TestPlan`. :rtype: dict Example:: # Update product to 7 for plan 1 and 2 >>> TestPlan.update([1, 2], {'product': 7}) .. deprecated:: x.y ``default_product_version`` is deprecated and will be removed. """ from tcms.core import forms from tcms.xmlrpc.forms import EditPlanForm if values.get('default_product_version'): values['product_version'] = values.pop('default_product_version') form = EditPlanForm(values) if values.get('product_version') and not values.get('product'): raise ValueError('Field "product" is required by product_version') if values.get('product') and not values.get('product_version'): raise ValueError('Field "product_version" is required by product') if values.get('product_version') and values.get('product'): form.populate(product_id=values['product']) plan_ids = pre_process_ids(value=plan_ids) tps = TestPlan.objects.filter(pk__in=plan_ids) if form.is_valid(): _values = dict() if form.cleaned_data['name']: _values['name'] = form.cleaned_data['name'] if form.cleaned_data['type']: _values['type'] = form.cleaned_data['type'] if form.cleaned_data['product']: _values['product'] = form.cleaned_data['product'] if form.cleaned_data['product_version']: _values['product_version'] = form.cleaned_data[ 'product_version'] if form.cleaned_data['owner']: _values['owner'] = form.cleaned_data['owner'] if form.cleaned_data['parent']: _values['parent'] = form.cleaned_data['parent'] if not (values.get('is_active') is None): _values['is_active'] = form.cleaned_data['is_active'] tps.update(**_values) # requested to update environment group for selected test plans if form.cleaned_data['env_group']: # prepare the list of new objects to be inserted into DB new_objects = [ TCMSEnvPlanMap( plan_id=plan_pk, group_id=form.cleaned_data['env_group'].pk ) for plan_pk in plan_ids ] # first delete the old values (b/c many-to-many I presume ?) TCMSEnvPlanMap.objects.filter(plan__in=plan_ids).delete() # then create all objects with 1 INSERT TCMSEnvPlanMap.objects.bulk_create(new_objects) else: raise ValueError(forms.errors_to_list(form)) query = {'pk__in': tps.values_list('pk', flat=True)} return TestPlan.to_xmlrpc(query)
def create(request, values): """Creates a new Test Plan object and stores it in the database. :param dict values: a mapping containing these plan data: * product: (int) **Required** ID of product * name: (str) **Required** * type: (int) **Required** ID of plan type * product_version: (int) **Required** version ID. * default_product_version: (int) optional version ID. * text: (str) **Required** Plan documents, HTML acceptable. * parent: (int) optional Parent plan ID * is_active: bool optional 0: Archived 1: Active (Default 0) :return: a mapping of newly created :class:`TestPlan`. :rtype: dict Example:: # Minimal test case parameters >>> values = { 'product': 1, 'name': 'Testplan foobar', 'type': 1, 'parent_id': 2, 'default_product_version': 1, 'text':'Testing TCMS', } >>> TestPlan.create(values) .. deprecated: x.y ``default_product_version`` is deprecated and will be removed. """ from tcms.core import forms from tcms.xmlrpc.forms import NewPlanForm if values.get('default_product_version'): values['product_version'] = values.pop('default_product_version') if not values.get('product'): raise ValueError('Value of product is required') form = NewPlanForm(values) form.populate(product_id=values['product']) if form.is_valid(): tp = TestPlan.objects.create( product=form.cleaned_data['product'], name=form.cleaned_data['name'], type=form.cleaned_data['type'], author=request.user, product_version=form.cleaned_data['product_version'], parent=form.cleaned_data['parent'], is_active=form.cleaned_data['is_active'] ) tp.add_text( author=request.user, plan_text=values['text'], ) return tp.serialize() else: raise ValueError(forms.errors_to_list(form))
def update(request, run_ids, values): """ Description: Updates the fields of the selected test run. Params: $run_ids - Integer/Array/String: An integer or alias representing the ID in the database, an array of run_ids, or a string of comma separated run_ids. $values - Hash of keys matching TestRun fields and the new values to set each field to. See params of TestRun.create for description +-------------------+----------------+--------------------------------+ | Field | Type | Description | +-------------------+----------------+--------------------------------+ | plan | Integer | TestPlan.plan_id | | product | Integer | Product.id | | build | Integer | Build.id | | errata_id | Integer | Errata.id | | manager | Integer | Auth.User.id | | default_tester | Intege | Auth.User.id | | summary | String | | | estimated_time | TimeDelta | 2h30m30s(recommend) or HH:MM:SS| | product_version | Integer | | | plan_text_version | Integer | | | notes | String | | | status | Integer | 0:RUNNING 1:FINISHED | +-------------------+----------------+ -------------------------------+ Returns: Hash: The updated test run object. Example: # Update status to finished for run 1193 and 1194 >>> TestRun.update([1193, 1194], {'status': 1}) """ from datetime import datetime from tcms.core import forms from tcms.testruns.forms import XMLRPCUpdateRunForm if (values.get('product_version') and not values.get('product')): raise ValueError('Field "product" is required by product_version') if values.get('estimated_time'): values['estimated_time'] = pre_process_estimated_time( values.get('estimated_time')) form = XMLRPCUpdateRunForm(values) if values.get('product_version'): form.populate(product_id=values['product']) if form.is_valid(): trs = TestRun.objects.filter(pk__in=pre_process_ids(value=run_ids)) _values = dict() if form.cleaned_data['plan']: _values['plan'] = form.cleaned_data['plan'] if form.cleaned_data['build']: _values['build'] = form.cleaned_data['build'] if form.cleaned_data['errata_id']: _values['errata_id'] = form.cleaned_data['errata_id'] if form.cleaned_data['manager']: _values['manager'] = form.cleaned_data['manager'] if 'default_tester' in values: if values.get('default_tester') and \ form.cleaned_data['default_tester']: _values['default_tester'] = form.cleaned_data['default_tester'] else: _values['default_tester'] = None if form.cleaned_data['summary']: _values['summary'] = form.cleaned_data['summary'] if values.get('estimated_time') is not None: _values['estimated_time'] = form.cleaned_data['estimated_time'] if form.cleaned_data['product_version']: _values['product_version'] = form.cleaned_data['product_version'] if 'notes' in values: if values['notes'] in (None, ''): _values['notes'] = values['notes'] if form.cleaned_data['notes']: _values['notes'] = form.cleaned_data['notes'] if form.cleaned_data['plan_text_version']: _values['plan_text_version'] = form.cleaned_data[ 'plan_text_version'] if isinstance(form.cleaned_data['status'], int): if form.cleaned_data['status']: _values['stop_date'] = datetime.now() else: _values['stop_date'] = None trs.update(**_values) else: raise ValueError(forms.errors_to_list(form)) query = {'pk__in': trs.values_list('pk', flat=True)} return TestRun.to_xmlrpc(query)
def create(request, values): """Creates a new Test Case object and stores it in the database. :param values: a mapping or list of mappings containing these case information for creation. * product: (int) **Required** ID of Product * category: (int) **Required** ID of Category * priority: (int) **Required** ID of Priority * summary: (str) **Required** * case_status: (int) optional ID of case status * plan Array/Str/Int optional ID or List of plan_ids * component: (int)/str optional ID of Priority * default_tester: (str) optional Login of tester * estimated_time: (str) optional 2h30m30s(recommend) or HH:MM:SS Format| * is_automated: (int) optional 0: Manual, 1: Auto, 2: Both * is_automated_proposed: (bool) optional Default 0 * script: (str) optional * arguments: (str) optional * requirement: (str) optional * alias: (str) optional Must be unique * action: (str) optional * effect: (str) optional Expected Result * setup: (str) optional * breakdown: (str) optional * tag Array/str optional String Comma separated * bug Array/str optional String Comma separated * extra_link: (str) optional reference link :return: a mapping of newly created test case if a single case was created, or a list of mappings of created cases if more than one are created. :rtype: dict of list[dict] Example:: # Minimal test case parameters >>> values = { 'category': 1, 'product': 1, 'summary': 'Testing XML-RPC', 'priority': 1, } >>> TestCase.create(values) """ from tcms.core import forms from tcms.xmlrpc.forms import NewCaseForm if not (values.get('category') or values.get('summary')): raise ValueError() values['component'] = pre_process_ids(values.get('component', [])) values['plan'] = pre_process_ids(values.get('plan', [])) values['bug'] = pre_process_ids(values.get('bug', [])) if values.get('estimated_time'): values['estimated_time'] = pre_process_estimated_time(values.get('estimated_time')) form = NewCaseForm(values) form.populate(values.get('product')) if form.is_valid(): # Create the case tc = TestCase.create(author=request.user, values=form.cleaned_data) # Add case text to the case tc.add_text( action=form.cleaned_data['action'] or '', effect=form.cleaned_data['effect'] or '', setup=form.cleaned_data['setup'] or '', breakdown=form.cleaned_data['breakdown'] or '', ) # Add the case to specific plans for p in form.cleaned_data['plan']: tc.add_to_plan(plan=p) del p # Add components to the case for c in form.cleaned_data['component']: tc.add_component(component=c) del c # Add tag to the case for tag in TestTag.string_to_list(values.get('tag', [])): t, c = TestTag.objects.get_or_create(name=tag) tc.add_tag(tag=t) else: # Print the errors if the form is not passed validation. raise ValueError(forms.errors_to_list(form)) return get(request, tc.case_id)
def update(request, plan_ids, values): """ Description: Updates the fields of the selected test plan. Params: $plan_ids - Integer: A single TestPlan ID. $values - Hash of keys matching TestPlan fields and the new values to set each field to. +-------------------------------------------+----------------+--------------------------------------------+ | Field | Type | Description | +-------------------------------------------+----------------+--------------------------------------------+ | product | Integer | ID of product | | name | String | | | type | Integer | ID of plan type | | product_version(default_product_version) | Integer | ID of version, product_version(recommend), | | | | default_product_version will be deprecated | | | | in future release. | | owner | String/Integer | user_name/user_id | | parent | Integer | Parent plan ID | | is_active | Boolean | True/False | | env_group | Integer | | +-------------------------+----------------+--------------------------------------------------------------+ Returns: Hash: The updated test plan object. Example: # Update product to 61 for plan 207 and 208 >>> TestPlan.update([207, 208], {'product': 61}) """ from tcms.core import forms from tcms.xmlrpc.forms import EditPlanForm if values.get('default_product_version'): values['product_version'] = values.pop('default_product_version') form = EditPlanForm(values) if values.get('product_version') and not values.get('product'): raise ValueError('Field "product" is required by product_version') if values.get('product') and not values.get('product_version'): raise ValueError('Field "product_version" is required by product') if values.get('product_version') and values.get('product'): form.populate(product_id=values['product']) plan_ids = pre_process_ids(value=plan_ids) tps = TestPlan.objects.filter(pk__in=plan_ids) if form.is_valid(): _values = dict() if form.cleaned_data['name']: _values['name'] = form.cleaned_data['name'] if form.cleaned_data['type']: _values['type'] = form.cleaned_data['type'] if form.cleaned_data['product']: _values['product'] = form.cleaned_data['product'] if form.cleaned_data['product_version']: _values['product_version'] = form.cleaned_data['product_version'] if form.cleaned_data['owner']: _values['owner'] = form.cleaned_data['owner'] if form.cleaned_data['parent']: _values['parent'] = form.cleaned_data['parent'] if not (values.get('is_active') is None): _values['is_active'] = form.cleaned_data['is_active'] tps.update(**_values) if form.cleaned_data['env_group']: # NOTE: MyISAM does not support transaction, so no need to use # transaction.commit_on_success to control the commit. cursor = connection.writer_cursor in_condition = ','.join(itertools.repeat('%s', len(plan_ids))) del_env_group_sql = TP_CLEAR_ENV_GROUP % in_condition cursor.execute(del_env_group_sql, plan_ids) insert_values = ','.join( itertools.repeat('(%s, %s)', len(plan_ids))) insert_env_group_sql = TP_ADD_ENV_GROUP % insert_values args = list() for arg in itertools.izip( plan_ids, itertools.repeat(form.cleaned_data['env_group'].pk, len(plan_ids))): args.extend(arg) cursor.execute(insert_env_group_sql, args) transaction.commit_unless_managed() else: raise ValueError(forms.errors_to_list(form)) query = {'pk__in': tps.values_list('pk', flat=True)} return TestPlan.to_xmlrpc(query)
def create(request, values): """Creates a new Test Plan object and stores it in the database. :param dict values: a mapping containing these plan data: * product: (int) **Required** ID of product * name: (str) **Required** * type: (int) **Required** ID of plan type * product_version: (int) **Required** version ID. * default_product_version: (int) optional version ID. * text: (str) **Required** Plan documents, HTML acceptable. * parent: (int) optional Parent plan ID * is_active: bool optional 0: Archived 1: Active (Default 0) :return: a mapping of newly created :class:`TestPlan`. :rtype: dict Example:: # Minimal test case parameters values = { 'product': 1, 'name': 'Testplan foobar', 'type': 1, 'parent_id': 2, 'default_product_version': 1, 'text':'Testing TCMS', } TestPlan.create(values) .. deprecated: x.y ``default_product_version`` is deprecated and will be removed. """ from tcms.core import forms from tcms.xmlrpc.forms import NewPlanForm if values.get('default_product_version'): values['product_version'] = values.pop('default_product_version') if not values.get('product'): raise ValueError('Value of product is required') form = NewPlanForm(values) form.populate(product_id=values['product']) if form.is_valid(): tp = TestPlan.objects.create( product=form.cleaned_data['product'], name=form.cleaned_data['name'], type=form.cleaned_data['type'], author=request.user, product_version=form.cleaned_data['product_version'], parent=form.cleaned_data['parent'], is_active=form.cleaned_data['is_active']) tp.add_text( author=request.user, plan_text=values['text'], ) return tp.serialize() else: raise ValueError(forms.errors_to_list(form))
def update(request, run_ids, values): """Updates the fields of the selected test run. :param run_ids: give one or more run IDs. It could be an integer, a string containing comma separated IDs, or a list of int each of them is a run ID. :type run_ids: int, str or list :param dict values: a mapping containing these data to update specified runs. * plan: (int) TestPlan.plan_id * product: (int) Product.id * build: (int) Build.id * errata_id: (int) Errata.id * manager: (int) Auth.User.id * default_tester: Intege Auth.User.id * summary: (str) * estimated_time: (TimeDelta) in format ``2h30m30s`` which is recommended or ``HH:MM:SS``. * product_version: (int) * plan_text_version: (int) * notes: (str) * status: (int) 0:RUNNING 1:FINISHED :return: list of mappings of the updated test runs. :rtype: list[dict] Example:: # Update status to finished for run 1 and 2 >>> TestRun.update([1, 2], {'status': 1}) """ from datetime import datetime from tcms.core import forms from tcms.testruns.forms import XMLRPCUpdateRunForm if (values.get('product_version') and not values.get('product')): raise ValueError('Field "product" is required by product_version') if values.get('estimated_time'): values['estimated_time'] = pre_process_estimated_time( values.get('estimated_time')) form = XMLRPCUpdateRunForm(values) if values.get('product_version'): form.populate(product_id=values['product']) if form.is_valid(): trs = TestRun.objects.filter(pk__in=pre_process_ids(value=run_ids)) _values = dict() if form.cleaned_data['plan']: _values['plan'] = form.cleaned_data['plan'] if form.cleaned_data['build']: _values['build'] = form.cleaned_data['build'] if form.cleaned_data['errata_id']: _values['errata_id'] = form.cleaned_data['errata_id'] if form.cleaned_data['manager']: _values['manager'] = form.cleaned_data['manager'] if 'default_tester' in values: if values.get('default_tester') and \ form.cleaned_data['default_tester']: _values['default_tester'] = form.cleaned_data['default_tester'] else: _values['default_tester'] = None if form.cleaned_data['summary']: _values['summary'] = form.cleaned_data['summary'] if values.get('estimated_time') is not None: _values['estimated_time'] = form.cleaned_data['estimated_time'] if form.cleaned_data['product_version']: _values['product_version'] = form.cleaned_data['product_version'] if 'notes' in values: if values['notes'] in (None, ''): _values['notes'] = values['notes'] if form.cleaned_data['notes']: _values['notes'] = form.cleaned_data['notes'] if form.cleaned_data['plan_text_version']: _values['plan_text_version'] = form.cleaned_data[ 'plan_text_version'] if isinstance(form.cleaned_data['status'], int): if form.cleaned_data['status']: _values['stop_date'] = datetime.now() else: _values['stop_date'] = None trs.update(**_values) else: raise ValueError(forms.errors_to_list(form)) query = {'pk__in': trs.values_list('pk', flat=True)} return TestRun.to_xmlrpc(query)
def create(request, values): """Creates a new Test Run object and stores it in the database. :param dict values: a mapping containing these data to create a test run. * plan: (int) **Required** ID of test plan * build: (int)/(str) **Required** ID of Build * errata_id: (int) optional ID of Errata * manager: (int) **Required** ID of run manager * summary: (str) **Required** * product: (int) **Required** ID of product * product_version: (int) **Required** ID of product version * default_tester: (int) optional ID of run default tester * plan_text_version: (int) optional * estimated_time: (str) optional, could be in format ``2h30m30s``, which is recommended or ``HH:MM:SS``. * notes: (str) optional * status: (int) optional 0:RUNNING 1:STOPPED (default 0) * case: list or (str) optional list of case ids to add to the run * tag: list or (str) optional list of tag to add to the run :return: a mapping representing newly created :class:`TestRun`. :rtype: dict Example:: >>> values = { 'build': 2, 'manager': 1, 'plan': 1, 'errata_id': 2, 'product': 1, 'product_version': 2, 'summary': 'Testing XML-RPC for TCMS', } >>> TestRun.create(values) """ from datetime import datetime from tcms.core import forms from tcms.testruns.forms import XMLRPCNewRunForm if not values.get('product'): raise ValueError('Value of product is required') # TODO: XMLRPC only accept HH:MM:SS rather than DdHhMm if values.get('estimated_time'): values['estimated_time'] = pre_process_estimated_time( values.get('estimated_time')) if values.get('case'): values['case'] = pre_process_ids(value=values['case']) form = XMLRPCNewRunForm(values) form.populate(product_id=values['product']) if form.is_valid(): tr = TestRun.objects.create( product_version=form.cleaned_data['product_version'], plan_text_version=form.cleaned_data['plan_text_version'], stop_date=form.cleaned_data['status'] and datetime.now() or None, summary=form.cleaned_data['summary'], notes=form.cleaned_data['notes'], estimated_time=form.cleaned_data['estimated_time'], plan=form.cleaned_data['plan'], build=form.cleaned_data['build'], errata_id=form.cleaned_data['errata_id'], manager=form.cleaned_data['manager'], default_tester=form.cleaned_data['default_tester'], ) if form.cleaned_data['case']: for c in form.cleaned_data['case']: tr.add_case_run(case=c) del c if form.cleaned_data['tag']: tags = form.cleaned_data['tag'] if isinstance(tags, str): tags = [c.strip() for c in tags.split(',') if c] for tag in tags: t, c = TestTag.objects.get_or_create(name=tag) tr.add_tag(tag=t) del tag, t, c else: raise ValueError(forms.errors_to_list(form)) return tr.serialize()
def update(request, case_run_ids, values): """ Description: Updates the fields of the selected case-runs. Params: $caserun_ids - Integer/String/Array Integer: A single TestCaseRun ID. String: A comma separates string of TestCaseRun IDs for batch processing. Array: An array of TestCaseRun IDs for batch mode processing $values - Hash of keys matching TestCaseRun fields and the new values to set each field to. +--------------------+----------------+ | Field | Type | +--------------------+----------------+ | build | Integer | | assignee | Integer | | case_run_status | Integer | | notes | String | | sortkey | Integer | +--------------------+----------------+ Returns: Hash/Array: In the case of a single object, it is returned. If a list was passed, it returns an array of object hashes. If the update on any particular object failed, the hash will contain a ERROR key and the message as to why it failed. Example: # Update alias to 'tcms' for case 12345 and 23456 >>> TestCaseRun.update([12345, 23456], {'assignee': 2206}) """ from datetime import datetime from tcms.core import forms from tcms.testruns.forms import XMLRPCUpdateCaseRunForm pks_to_update = pre_process_ids(case_run_ids) tcrs = TestCaseRun.objects.filter(pk__in=pks_to_update) form = XMLRPCUpdateCaseRunForm(values) if form.is_valid(): data = {} if form.cleaned_data['build']: data['build'] = form.cleaned_data['build'] if form.cleaned_data['assignee']: data['assignee'] = form.cleaned_data['assignee'] if form.cleaned_data['case_run_status']: data['case_run_status'] = form.cleaned_data['case_run_status'] data['tested_by'] = request.user data['close_date'] = datetime.now() if 'notes' in values: if values['notes'] in (None, ''): data['notes'] = values['notes'] if form.cleaned_data['notes']: data['notes'] = form.cleaned_data['notes'] if form.cleaned_data['sortkey'] is not None: data['sortkey'] = form.cleaned_data['sortkey'] tcrs.update(**data) else: raise ValueError(forms.errors_to_list(form)) query = {'pk__in': pks_to_update} return TestCaseRun.to_xmlrpc(query)
def update(request, plan_ids, values): """ Description: Updates the fields of the selected test plan. Params: $plan_ids - Integer: A single TestPlan ID. $values - Hash of keys matching TestPlan fields and the new values to set each field to. +-------------------------------------------+----------------+--------------------------------------------+ | Field | Type | Description | +-------------------------------------------+----------------+--------------------------------------------+ | product | Integer | ID of product | | name | String | | | type | Integer | ID of plan type | | product_version(default_product_version) | Integer | ID of version, product_version(recommend), | | | | default_product_version will be deprecated | | | | in future release. | | owner | String/Integer | user_name/user_id | | parent | Integer | Parent plan ID | | is_active | Boolean | True/False | | env_group | Integer | | +-------------------------+----------------+--------------------------------------------------------------+ Returns: Hash: The updated test plan object. Example: # Update product to 61 for plan 207 and 208 >>> TestPlan.update([207, 208], {'product': 61}) """ from tcms.core import forms from tcms.xmlrpc.forms import EditPlanForm if values.get('default_product_version'): values['product_version'] = values.pop('default_product_version') form = EditPlanForm(values) if values.get('product_version') and not values.get('product'): raise ValueError('Field "product" is required by product_version') if values.get('product') and not values.get('product_version'): raise ValueError('Field "product_version" is required by product') if values.get('product_version') and values.get('product'): form.populate(product_id=values['product']) plan_ids = pre_process_ids(value=plan_ids) tps = TestPlan.objects.filter(pk__in=plan_ids) if form.is_valid(): _values = dict() if form.cleaned_data['name']: _values['name'] = form.cleaned_data['name'] if form.cleaned_data['type']: _values['type'] = form.cleaned_data['type'] if form.cleaned_data['product']: _values['product'] = form.cleaned_data['product'] if form.cleaned_data['product_version']: _values['product_version'] = form.cleaned_data[ 'product_version'] if form.cleaned_data['owner']: _values['owner'] = form.cleaned_data['owner'] if form.cleaned_data['parent']: _values['parent'] = form.cleaned_data['parent'] if not (values.get('is_active') is None): _values['is_active'] = form.cleaned_data['is_active'] tps.update(**_values) if form.cleaned_data['env_group']: # NOTE: MyISAM does not support transaction, so no need to use # transaction.commit_on_success to control the commit. cursor = connection.writer_cursor in_condition = ','.join(itertools.repeat('%s', len(plan_ids))) del_env_group_sql = TP_CLEAR_ENV_GROUP % in_condition cursor.execute(del_env_group_sql, plan_ids) insert_values = ','.join(itertools.repeat('(%s, %s)', len(plan_ids))) insert_env_group_sql = TP_ADD_ENV_GROUP % insert_values args = list() for arg in itertools.izip(plan_ids, itertools.repeat(form.cleaned_data['env_group'].pk, len(plan_ids))): args.extend(arg) cursor.execute(insert_env_group_sql, args) transaction.commit_unless_managed() else: raise ValueError(forms.errors_to_list(form)) query = {'pk__in': tps.values_list('pk', flat=True)} return TestPlan.to_xmlrpc(query)
def update(request, case_ids, values): """ Description: Updates the fields of the selected case or cases. Params: $case_ids - Integer/String/Array Integer: A single TestCase ID. String: A comma separates string of TestCase IDs for batch processing. Array: An array of case IDs for batch mode processing $values - Hash of keys matching TestCase fields and the new values to set each field to. Returns: Array: an array of case hashes. If the update on any particular case failed, the has will contain a ERROR key and the message as to why it failed. +-----------------------+----------------+-----------------------------------------+ | Field | Type | Null | +-----------------------+----------------+-----------------------------------------+ | case_status | Integer | Optional | | product | Integer | Optional(Required if changes category) | | category | Integer | Optional | | priority | Integer | Optional | | default_tester | String/Integer | Optional(str - user_name, int - user_id)| | estimated_time | String | Optional(2h30m30s(recommend) or HH:MM:SS| | is_automated | Integer | Optional(0 - Manual, 1 - Auto, 2 - Both)| | is_automated_proposed | Boolean | Optional | | script | String | Optional | | arguments | String | Optional | | summary | String | Optional | | requirement | String | Optional | | alias | String | Optional | | notes | String | Optional | | extra_link | String | Optional(reference link) +-----------------------+----------------+-----------------------------------------+ Example: # Update alias to 'tcms' for case 12345 and 23456 >>> TestCase.update([12345, 23456], {'alias': 'tcms'}) """ from tcms.core import forms from tcms.xmlrpc.forms import UpdateCaseForm if values.get('estimated_time'): values['estimated_time'] = pre_process_estimated_time(values.get('estimated_time')) form = UpdateCaseForm(values) if values.get('category') and not values.get('product'): raise ValueError('Product ID is required for category') if values.get('product'): form.populate(product_id=values['product']) if form.is_valid(): tcs = TestCase.update( case_ids=pre_process_ids(value=case_ids), values=form.cleaned_data, ) else: raise ValueError(forms.errors_to_list(form)) query = {'pk__in': tcs.values_list('pk', flat=True)} return TestCase.to_xmlrpc(query)
def update(request, plan_ids, values): """ Description: Updates the fields of the selected test plan. Params: $plan_ids - Integer: A single TestPlan ID. $values - Hash of keys matching TestPlan fields and the new values to set each field to. +------------------------+----------------+------------------------------------+ | Field | Type | Description | +-------------------------+----------------+------------------------------------+ | product | Integer | ID of product | | name | String | | | type | Integer | ID of plan type | | default_product_version | Integer | | | parent | Integer | Parent plan ID | | is_active | Boolean | True/False | | env_group | Integer | | +-------------------------+----------------+------------------------------------+ Returns: Hash: The updated test plan object. Example: # Update product to 61 for plan 207 and 208 >>> TestPlan.update([207, 208], {'product': 61}) """ from tcms.core import forms from tcms.apps.testplans.forms import XMLRPCEditPlanForm if values.get('is_active') in (False, True): if values.get('is_active') == False: values['is_active'] = 0 else: values['is_active'] = 1 form = XMLRPCEditPlanForm(values) if values.get('default_product_version') and not values.get('product'): raise ValueError('Product value is required by default product version') if values.get('default_product_version') and values.get('product'): form.populate(product_id = values['product']) tps = TestPlan.objects.filter(pk__in = pre_process_ids(value = plan_ids)) if form.is_valid(): if form.cleaned_data['name']: tps.update(name = form.cleaned_data['name']) if form.cleaned_data['type']: tps.update(type = form.cleaned_data['type']) if form.cleaned_data['product']: tps.update(product = form.cleaned_data['product']) if form.cleaned_data['default_product_version']: tps.update(default_product_version = form.cleaned_data['default_product_version']) if form.cleaned_data['parent']: tps.update(parent = form.cleaned_data['parent']) if isinstance(form.cleaned_data['is_active'], int): tps.update(is_active = form.cleaned_data['is_active']) if form.cleaned_data['env_group']: for tp in tps: tp.clear_env_groups() tp.add_env_group(form.cleaned_data['env_group']) else: return forms.errors_to_list(form) query = {'pk__in': tps.values_list('pk', flat = True)} return TestPlan.to_xmlrpc(query)
def create(request, values): """ Description: Creates a new Test Case object and stores it in the database. Params: $values - Array/Hash: A reference to a hash or array of hashes with keys and values matching the fields of the test case to be created. +----------------------------+----------------+-----------+---------------------------------------+ | Field | Type | Null | Description | +----------------------------+----------------+-----------+---------------------------------------+ | product | Integer | Required | ID of Product | | category | Integer | Required | ID of Category | | priority | Integer | Required | ID of Priority | | summary | String | Required | | | case_status | Integer | Optional | ID of case status | | plan | Array/Str/Int | Optional | ID or List of plan_ids | | component | Integer/String | Optional | ID of Priority | | default_tester | String | Optional | Login of tester | | estimated_time | String | Optional | 2h30m30s(recommend) or HH:MM:SS Format| | is_automated | Integer | Optional | 0: Manual, 1: Auto, 2: Both | | is_automated_proposed | Boolean | Optional | Default 0 | | script | String | Optional | | | arguments | String | Optional | | | requirement | String | Optional | | | alias | String | Optional | Must be unique | | action | String | Optional | | | effect | String | Optional | Expected Result | | setup | String | Optional | | | breakdown | String | Optional | | | tag | Array/String | Optional | String Comma separated | | bug | Array/String | Optional | String Comma separated | | extra_link | String | Optional | reference link | +----------------------------+----------------+-----------+---------------------------------------+ Returns: Array/Hash: The newly created object hash if a single case was created, or an array of objects if more than one was created. If any single case threw an error during creation, a hash with an ERROR key will be set in its place. Example: # Minimal test case parameters >>> values = { 'category': 135, 'product': 61, 'summary': 'Testing XML-RPC', 'priority': 1, } >>> TestCase.create(values) """ from tcms.core import forms from tcms.xmlrpc.forms import NewCaseForm if not (values.get('category') or values.get('summary')): raise ValueError() values['component'] = pre_process_ids(values.get('component', [])) values['plan'] = pre_process_ids(values.get('plan', [])) values['bug'] = pre_process_ids(values.get('bug', [])) if values.get('estimated_time'): values['estimated_time'] = pre_process_estimated_time(values.get('estimated_time')) form = NewCaseForm(values) form.populate(values.get('product')) if form.is_valid(): # Create the case tc = TestCase.create(author=request.user, values=form.cleaned_data) # Add case text to the case tc.add_text( action=form.cleaned_data['action'] or '', effect=form.cleaned_data['effect'] or '', setup=form.cleaned_data['setup'] or '', breakdown=form.cleaned_data['breakdown'] or '', ) # Add the case to specific plans for p in form.cleaned_data['plan']: tc.add_to_plan(plan=p) del p # Add components to the case for c in form.cleaned_data['component']: tc.add_component(component=c) del c # Add tag to the case for tag in TestTag.string_to_list(values.get('tag', [])): t, c = TestTag.objects.get_or_create(name=tag) tc.add_tag(tag=t) else: # Print the errors if the form is not passed validation. raise ValueError(forms.errors_to_list(form)) return get(request, tc.case_id)
def create(request, values): """ Description: Creates a new Test Case object and stores it in the database. Params: $values - Array/Hash: A reference to a hash or array of hashes with keys and values matching the fields of the test case to be created. +----------------------------+----------------+-----------+-----------------------------+ | Field | Type | Null | Description | +----------------------------+----------------+-----------+-----------------------------+ | product | Integer | Required | ID of Product | | category | Integer | Required | ID of Category | | priority | Integer | Required | ID of Priority | | summary | String | Required | | | case_status | Integer | Optional | ID of case status | | plan | Array/Str/Int | Optional | ID or List of plan_ids | | component | Integer/String | Optional | ID of Priority | | default_tester | String | Optional | Login of tester | | estimated_time | String | Optional | HH:MM:SS Format | | is_automated | Integer | Optional | 0: Manual, 1: Auto, 2: Both | | is_automated_proposed | Boolean | Optional | Default 0 | | script | String | Optional | | | arguments | String | Optional | | | requirement | String | Optional | | | alias | String | Optional | Must be unique | | action | String | Optional | | | effect | String | Optional | Expected Result | | setup | String | Optional | | | breakdown | String | Optional | | | tag | Array/String | Optional | String Comma separated | | bug | Array/String | Optional | String Comma separated | | extra_link | String | Optional | reference link | +----------------------------+----------------+-----------+-----------------------------+ Returns: Array/Hash: The newly created object hash if a single case was created, or an array of objects if more than one was created. If any single case threw an error during creation, a hash with an ERROR key will be set in its place. Example: # Minimal test case parameters >>> values = { 'category': 135, 'product': 61, 'summary': 'Testing XML-RPC', 'priority': 1, } >>> TestCase.create(values) """ from tcms.core import forms from tcms.apps.testcases.forms import XMLRPCNewCaseForm if not (values.get('category') or values.get('summary')): raise ValueError() values['component'] = pre_process_ids(values.get('component', [])) values['plan'] = pre_process_ids(values.get('plan', [])) values['bug'] = pre_process_ids(values.get('bug', [])) form = XMLRPCNewCaseForm(values) form.populate(values.get('product')) if form.is_valid(): # Create the case tc = TestCase.create(author = request.user, values = form.cleaned_data) # Add case text to the case tc.add_text( action = form.cleaned_data['action'] or '', effect = form.cleaned_data['effect'] or '', setup = form.cleaned_data['setup'] or '', breakdown = form.cleaned_data['breakdown'] or '', ) # Add the case to specific plans for p in form.cleaned_data['plan']: tc.add_to_plan(plan = p) del p # Add components to the case for c in form.cleaned_data['component']: tc.add_component(component = c) del c # Add tag to the case for tag in TestTag.string_to_list(values.get('tag', [])): t, c = TestTag.objects.get_or_create(name = tag) tc.add_tag(tag = t) else: # Print the errors if the form is not passed validation. return forms.errors_to_list(form) return get(request, tc.case_id)
def create(request, values): """Creates a new Test Case object and stores it in the database. :param values: a mapping or list of mappings containing these case information for creation. * product: (int) **Required** ID of Product * category: (int) **Required** ID of Category * priority: (int) **Required** ID of Priority * summary: (str) **Required** * case_status: (int) optional ID of case status * plan Array/Str/Int optional ID or List of plan_ids * component: (int)/str optional ID of Priority * default_tester: (str) optional Login of tester * estimated_time: (str) optional 2h30m30s(recommend) or HH:MM:SS Format| * is_automated: (int) optional 0: Manual, 1: Auto, 2: Both * is_automated_proposed: (bool) optional Default 0 * script: (str) optional * arguments: (str) optional * requirement: (str) optional * alias: (str) optional Must be unique * action: (str) optional * effect: (str) optional Expected Result * setup: (str) optional * breakdown: (str) optional * tag Array/str optional String Comma separated * bug Array/str optional String Comma separated * extra_link: (str) optional reference link :return: a mapping of newly created test case if a single case was created, or a list of mappings of created cases if more than one are created. :rtype: dict of list[dict] Example:: # Minimal test case parameters values = { 'category': 1, 'product': 1, 'summary': 'Testing XML-RPC', 'priority': 1, } TestCase.create(values) """ from tcms.core import forms from tcms.xmlrpc.forms import NewCaseForm if not (values.get('category') or values.get('summary')): raise ValueError() values['component'] = pre_process_ids(values.get('component', [])) values['plan'] = pre_process_ids(values.get('plan', [])) values['bug'] = pre_process_ids(values.get('bug', [])) if values.get('estimated_time'): values['estimated_time'] = pre_process_estimated_time(values.get('estimated_time')) form = NewCaseForm(values) form.populate(values.get('product')) if form.is_valid(): # Create the case tc = TestCase.create(author=request.user, values=form.cleaned_data) # Add case text to the case tc.add_text( action=form.cleaned_data['action'] or '', effect=form.cleaned_data['effect'] or '', setup=form.cleaned_data['setup'] or '', breakdown=form.cleaned_data['breakdown'] or '', ) # Add the case to specific plans for p in form.cleaned_data['plan']: tc.add_to_plan(plan=p) del p # Add components to the case for c in form.cleaned_data['component']: tc.add_component(component=c) del c # Add tag to the case for tag in TestTag.string_to_list(values.get('tag', [])): t, c = TestTag.objects.get_or_create(name=tag) tc.add_tag(tag=t) else: # Print the errors if the form is not passed validation. raise ValueError(forms.errors_to_list(form)) return get(request, tc.case_id)