def update(case_run_id, values, **kwargs): """ .. function:: XML-RPC TestCaseRun.update(case_run_id, values) Update the selected TestCaseRun :param case_run_id: PK of TestCaseRun to modify :type case_run_id: int :param values: Field values for :class:`tcms.testruns.models.TestCaseRun` :type values: dict :return: Serialized :class:`tcms.testruns.models.TestCaseRun` object :raises: PermissionDenied if missing *testruns.change_testcaserun* permission """ from tcms.testruns.forms import XMLRPCUpdateCaseRunForm tcr = TestCaseRun.objects.get(pk=case_run_id) form = XMLRPCUpdateCaseRunForm(values) if form.is_valid(): if form.cleaned_data['build']: tcr.build = form.cleaned_data['build'] if form.cleaned_data['assignee']: tcr.assignee = form.cleaned_data['assignee'] if form.cleaned_data['case_run_status']: tcr.case_run_status = form.cleaned_data['case_run_status'] request = kwargs.get(REQUEST_KEY) tcr.tested_by = request.user if 'notes' in values: if values['notes'] in (None, ''): tcr.notes = values['notes'] if form.cleaned_data['notes']: tcr.notes = form.cleaned_data['notes'] if form.cleaned_data['sortkey'] is not None: tcr.sortkey = form.cleaned_data['sortkey'] tcr.save() else: raise ValueError(form_errors_to_list(form)) return tcr.serialize()
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 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)