def update(run_id, values): """ .. function:: RPC TestRun.update(run_id, values) Update the selected TestRun :param run_id: PK of TestRun to modify :type run_id: int :param values: Field values for :class:`tcms.testruns.models.TestRun` :type values: dict :return: Serialized :class:`tcms.testruns.models.TestRun` object :rtype: dict :raises PermissionDenied: if missing *testruns.change_testrun* permission :raises ValueError: if data validations fail """ test_run = TestRun.objects.get(pk=run_id) form = UpdateForm(values, instance=test_run) # In the rare case where this TR is reassigned to another TP # don't validate if TR.build has a FK relationship with TP.product_version. # Instead all Build IDs should be valid if "plan" not in values: form.populate(version_id=test_run.plan.product_version_id) if not form.is_valid(): raise ValueError(form_errors_to_list(form)) test_run = form.save() return test_run.serialize()
def create(values): """ .. function:: RPC Version.create(values) Add new version. :param values: Field values for :class:`tcms.management.models.Version` :type values: dict :return: Serialized :class:`tcms.management.models.Version` object :rtype: dict :raises ValueError: if input data validation fails :raises PermissionDenied: if missing *management.add_version* permission Example:: # Add version for specified product: >>> Version.create({'value': 'devel', 'product': 272}) {'id': '1106', 'value': 'devel', 'product': 272} """ form = VersionForm(values) if form.is_valid(): version = form.save() return model_to_dict(version) raise ValueError(form_errors_to_list(form))
def update(plan_id, values): """ .. function:: RPC TestPlan.update(plan_id, values) Update the fields of the selected test plan. :param plan_id: PK of TestPlan to modify :type plan_id: int :param values: Field values for :class:`tcms.testplans.models.TestPlan` :type values: dict :return: Serialized :class:`tcms.testplans.models.TestPlan` object :rtype: dict :raises TestPlan.DoesNotExist: if object specified by PK doesn't exist :raises PermissionDenied: if missing *testplans.change_testplan* permission :raises ValueError: if validations fail """ test_plan = TestPlan.objects.get(pk=plan_id) form = EditPlanForm(values, instance=test_plan) if form.is_valid(): test_plan = form.save() result = model_to_dict(test_plan, exclude=["tag"]) # b/c value is set in the DB directly and if None # model_to_dict() will not return it result["create_date"] = test_plan.create_date return result raise ValueError(form_errors_to_list(form))
def update(case_id, values, **kwargs): """ .. function:: XML-RPC TestCase.update(case_id, values) Update the fields of the selected test case. :param case_id: PK of TestCase to be modified :type case_id: int :param values: Field values for :class:`tcms.testcases.models.TestCase`. The special keys ``setup``, ``breakdown``, ``action`` and ``effect`` are recognized and will cause update of the underlying :class:`tcms.testcases.models.TestCaseText` object! :type values: dict :return: Serialized :class:`tcms.testcases.models.TestCase` object :rtype: dict :raises: TestCase.DoesNotExist if object specified by PK doesn't exist :raises: PermissionDenied if missing *testcases.change_testcase* permission """ 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(): tc = TestCase.objects.get(pk=case_id) for key in values.keys(): # only modify attributes that were passed via parameters # skip attributes which are Many-to-Many relations if key not in ['component', 'tag'] and hasattr(tc, key): setattr(tc, key, form.cleaned_data[key]) tc.save() # if we're updating the text if any one of these parameters was # specified if any(x in ['setup', 'action', 'effect', 'breakdown'] for x in values.keys()): action = form.cleaned_data.get('action', '').strip() effect = form.cleaned_data.get('effect', '').strip() setup = form.cleaned_data.get('setup', '').strip() breakdown = form.cleaned_data.get('breakdown', '').strip() author = kwargs.get(REQUEST_KEY).user tc.add_text( author=author, action=action, effect=effect, setup=setup, breakdown=breakdown, ) else: raise ValueError(form_errors_to_list(form)) return tc.serialize()
def create(values): """ .. function:: XML-RPC TestRun.create(values) Create new TestRun object and store it in the database. :param values: Field values for :class:`tcms.testruns.models.TestRun` :type values: dict :return: Serialized :class:`tcms.testruns.models.TestRun` object :raises: PermissionDenied if missing *testruns.add_testrun* permission :raises: ValueError if data validations fail Example:: values = {'build': 384, 'manager': 137, 'plan': 137, 'product': 61, 'product_version': 93, 'summary': 'Testing XML-RPC for TCMS', } TestRun.create(values) """ 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'] = parse_duration( values.get('estimated_time')) form = XMLRPCNewRunForm(values) form.populate(product_id=values['product']) if form.is_valid(): test_run = 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['tag']: tag_names = form.cleaned_data['tag'] if isinstance(tag_names, str): tag_names = [c.strip() for c in tag_names.split(',') if c] for tag_name in tag_names: tag, _ = Tag.objects.get_or_create(name=tag_name) test_run.add_tag(tag=tag) else: raise ValueError(form_errors_to_list(form)) return test_run.serialize()
def update(case_id, values): """ .. function:: XML-RPC TestCase.update(case_id, values) Update the fields of the selected test case. :param case_id: PK of TestCase to be modified :type case_id: int :param values: Field values for :class:`tcms.testcases.models.TestCase`. :type values: dict :return: Serialized :class:`tcms.testcases.models.TestCase` object :rtype: dict :raises: TestCase.DoesNotExist if object specified by PK doesn't exist :raises: PermissionDenied if missing *testcases.change_testcase* permission """ form = UpdateForm(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(): test_case = TestCase.objects.get(pk=case_id) for key in values.keys(): # only modify attributes that were passed via parameters # skip attributes which are Many-to-Many relations if key not in ['component', 'tag'] and hasattr(test_case, key): setattr(test_case, key, form.cleaned_data[key]) test_case.save() else: raise ValueError(form_errors_to_list(form)) return test_case.serialize()
def create(values): """ .. function:: XML-RPC Version.create(values) Add new version. :param values: Field values for :class:`tcms.management.models.Version` :type query: dict :return: Serialized :class:`tcms.management.models.Version` object :rtype: dict :raises: ValueError if input data validation fails :raises: PermissionDenied if missing *management.add_version* permission Example:: # Add version for specified product: >>> Version.create({'value': 'devel', 'product': 272}) {'product': 'QE Test Product', 'id': '1106', 'value': 'devel', 'product_id': 272} """ 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() raise ValueError(form_errors_to_list(form))
def create(values): """ .. function:: RPC TestRun.create(values) Create new TestRun object and store it in the database. :param values: Field values for :class:`tcms.testruns.models.TestRun` :type values: dict :return: Serialized :class:`tcms.testruns.models.TestRun` object :rtype: dict :raises PermissionDenied: if missing *testruns.add_testrun* permission :raises ValueError: if data validations fail Example:: >>> values = {'build': 384, 'manager': 137, 'plan': 137, 'summary': 'Testing XML-RPC for TCMS', } >>> TestRun.create(values) """ form = NewRunForm(values) form.populate(values.get("plan")) if form.is_valid(): test_run = form.save() result = model_to_dict(test_run, exclude=["cc", "tag"]) # b/c value is set in the DB directly and if None # model_to_dict() will not return it result["start_date"] = test_run.start_date return result raise ValueError(form_errors_to_list(form))
def update(run_id, values): """ .. function:: RPC TestRun.update(run_id, values) Update the selected TestRun :param run_id: PK of TestRun to modify :type run_id: int :param values: Field values for :class:`tcms.testruns.models.TestRun` :type values: dict :return: Serialized :class:`tcms.testruns.models.TestRun` object :rtype: dict :raises PermissionDenied: if missing *testruns.change_testrun* permission :raises ValueError: if data validations fail """ test_run = TestRun.objects.get(pk=run_id) form = UpdateForm(values, instance=test_run) if values.get('product'): form.populate(product_id=values['product']) if not form.is_valid(): raise ValueError(form_errors_to_list(form)) test_run = form.save() return test_run.serialize()
def create(values, **kwargs): """ .. function:: XML-RPC TestCase.create(values) Create a new TestCase object and store it in the database. :param values: Field values for :class:`tcms.testcases.models.TestCase` :type values: dict :return: Serialized :class:`tcms.testcases.models.TestCase` object :rtype: dict :raises: PermissionDenied if missing *testcases.add_testcase* permission Minimal test case parameters:: >>> values = { 'category': 135, 'product': 61, 'summary': 'Testing XML-RPC', 'priority': 1, } >>> TestCase.create(values) """ request = kwargs.get(REQUEST_KEY) if not (values.get('author') or values.get('author_id')): values['author'] = request.user.pk form = NewForm(values) if form.is_valid(): test_case = form.save() else: raise ValueError(form_errors_to_list(form)) return test_case.serialize()
def update(execution_id, values): """ .. function:: RPC TestExecution.update(execution_id, values) Update the selected TestExecution :param execution_id: PK of TestExecution to modify :type execution_id: int :param values: Field values for :class:`tcms.testruns.models.TestExecution` :type values: dict :return: Serialized :class:`tcms.testruns.models.TestExecution` object :rtype: dict :raises ValueError: if data validations fail :raises PermissionDenied: if missing *testruns.change_testexecution* permission """ test_execution = TestExecution.objects.get(pk=execution_id) if values.get('case_text_version') == 'latest': values['case_text_version'] = test_execution.case.history.latest( ).history_id form = UpdateExecutionForm(values, instance=test_execution) if form.is_valid(): test_execution = form.save() else: raise ValueError(form_errors_to_list(form)) return test_execution.serialize()
def update(run_id, values): """ .. function:: XML-RPC TestRun.update(run_id, values) Update the selected TestRun :param run_id: PK of TestRun to modify :type run_id: int :param values: Field values for :class:`tcms.testruns.models.TestRun` :type values: dict :return: Serialized :class:`tcms.testruns.models.TestRun` object :raises: PermissionDenied if missing *testruns.change_testrun* permission :raises: ValueError if data validations fail """ if (values.get('product_version') and not values.get('product')): raise ValueError('Field "product" is required by product_version') form = XMLRPCUpdateRunForm(values) if values.get('product_version'): form.populate(product_id=values['product']) if form.is_valid(): return _get_updated_test_run(run_id, values, form).serialize() raise ValueError(form_errors_to_list(form))
def get(request): """Get links of specific instance of content type - target: The model name of the instance being searched - target_id: The ID of the instance Only accept GET request from client. """ form = BasicValidationForm(request.GET) if form.is_valid(): model_class = form.cleaned_data['target'] target_id = form.cleaned_data['target_id'] try: model_instance = model_class.objects.get(pk=target_id) links = LinkReference.get_from(model_instance) except Exception as err: return JsonResponseBadRequest({'message': str(err)}) jd = [] for link in links: jd.append({'name': link.name, 'url': link.url}) return JsonResponse(jd, safe=False) else: return JsonResponseBadRequest({'message': form_errors_to_list(form)})
def create(values): """ .. function:: RPC TestRun.create(values) Create new TestRun object and store it in the database. :param values: Field values for :class:`tcms.testruns.models.TestRun` :type values: dict :return: Serialized :class:`tcms.testruns.models.TestRun` object :rtype: dict :raises PermissionDenied: if missing *testruns.add_testrun* permission :raises ValueError: if data validations fail Example:: >>> values = {'build': 384, 'manager': 137, 'plan': 137, 'summary': 'Testing XML-RPC for TCMS', } >>> TestRun.create(values) """ form = NewRunForm(values) form.populate(values.get('plan')) if form.is_valid(): test_run = form.save() return test_run.serialize() raise ValueError(form_errors_to_list(form))
def update(case_id, values): """ .. function:: RPC TestCase.update(case_id, values) Update the fields of the selected test case. :param case_id: PK of TestCase to be modified :type case_id: int :param values: Field values for :class:`tcms.testcases.models.TestCase`. :type values: dict :return: Serialized :class:`tcms.testcases.models.TestCase` object :rtype: dict :raises ValueError: if form is not valid :raises TestCase.DoesNotExist: if object specified by PK doesn't exist :raises PermissionDenied: if missing *testcases.change_testcase* permission """ test_case = TestCase.objects.get(pk=case_id) form = UpdateForm(values, instance=test_case) if form.is_valid(): test_case = form.save() else: raise ValueError(form_errors_to_list(form)) return test_case.serialize()
def add_version(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.']] """ 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(form_errors_to_list(form))
def create(values): """ .. function:: XML-RPC TestExecution.create(values) Create new TestExecution object and store it in the database. :param values: Field values for :class:`tcms.testruns.models.TestExecution` :type values: dict :return: Serialized :class:`tcms.testruns.models.TestExecution` object :rtype: dict :raises TypeError: if argument values is not in dict type :raises ValueError: if argument values is empty :raises ValueError: if data validations fail :raises PermissionDenied: if missing *testruns.add_testexecution* permission Minimal parameters:: >>> values = { 'run': 1990, 'case': 12345, 'build': 123, } >>> TestExecution.create(values) """ form = NewTestExecutionForm(values) if form.is_valid(): test_execution = form.save() else: raise ValueError(form_errors_to_list(form)) return test_execution.serialize()
def create(values, **kwargs): """ .. function:: XML-RPC TestCase.create(values) Create a new TestCase object and store it in the database. :param values: Field values for :class:`tcms.testcases.models.TestCase` :type values: dict :return: Serialized :class:`tcms.testcases.models.TestCase` object :rtype: dict :raises: PermissionDenied if missing *testcases.add_testcase* permission Minimal test case parameters:: >>> values = { 'category': 135, 'product': 61, 'summary': 'Testing XML-RPC', 'priority': 1, } >>> TestCase.create(values) """ request = kwargs.get(REQUEST_KEY) if not (values.get('category') or values.get('summary')): raise ValueError() if values.get('estimated_time'): values['estimated_time'] = parse_duration(values.get('estimated_time')) form = NewCaseForm(values) form.populate(values.get('product')) if form.is_valid(): # Create the case test_case = TestCase.create(author=request.user, values=form.cleaned_data) # Add case text to the case test_case.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 tag to the case for tag in string_to_list(values.get('tag', [])): tag, _ = Tag.objects.get_or_create(name=tag) test_case.add_tag(tag=tag) else: # Print the errors if the form is not passed validation. raise ValueError(form_errors_to_list(form)) result = test_case.serialize() result['text'] = test_case.latest_text().serialize() return result
def update(run_id, values): """ .. function:: XML-RPC TestRun.update(run_id, values) Update the selected TestRun :param run_id: PK of TestRun to modify :type run_id: int :param values: Field values for :class:`tcms.testruns.models.TestRun` :type values: dict :return: Serialized :class:`tcms.testruns.models.TestRun` object :raises: PermissionDenied if missing *testruns.change_testrun* permission :raises: ValueError if data validations fail """ if values.get('product_version') and not values.get('product'): raise ValueError('Field "product" is required by product_version') form = XMLRPCUpdateRunForm(values) if values.get('product_version'): form.populate(product_id=values['product']) if not form.is_valid(): raise ValueError(form_errors_to_list(form)) test_run = TestRun.objects.get(pk=run_id) if form.cleaned_data['plan']: test_run.plan = form.cleaned_data['plan'] if form.cleaned_data['build']: test_run.build = form.cleaned_data['build'] if form.cleaned_data['manager']: test_run.manager = form.cleaned_data['manager'] test_run.default_tester = None if form.cleaned_data['default_tester']: test_run.default_tester = form.cleaned_data['default_tester'] if form.cleaned_data['summary']: test_run.summary = form.cleaned_data['summary'] if form.cleaned_data['product_version']: test_run.product_version = form.cleaned_data['product_version'] if 'notes' in values: if values['notes'] in (None, ''): test_run.notes = values['notes'] if form.cleaned_data['notes']: test_run.notes = form.cleaned_data['notes'] if form.cleaned_data['stop_date']: test_run.stop_date = form.cleaned_data['stop_date'] test_run.save() return test_run.serialize()
def create(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.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(form_errors_to_list(form)) return tcr.serialize()
def update(execution_id, values, **kwargs): """ .. function:: RPC TestExecution.update(execution_id, values) Update the selected TestExecution :param execution_id: PK of TestExecution to modify :type execution_id: int :param values: Field values for :class:`tcms.testruns.models.TestExecution` :type values: dict :param kwargs: Dict providing access to the current request, protocol entry point name and handler instance from the rpc method :return: Serialized :class:`tcms.testruns.models.TestExecution` object :rtype: dict :raises ValueError: if data validations fail :raises PermissionDenied: if missing *testruns.change_testexecution* permission """ test_execution = TestExecution.objects.get(pk=execution_id) if values.get("case_text_version") == "latest": values["case_text_version"] = test_execution.case.history.latest( ).history_id if values.get("status") and not values.get("tested_by"): values["tested_by"] = kwargs.get(REQUEST_KEY).user.id if values.get("status") and not values.get("build"): values["build"] = test_execution.run.build.pk form = UpdateExecutionForm(values, instance=test_execution) if form.is_valid(): test_execution = form.save() else: raise ValueError(form_errors_to_list(form)) # if this call updated TE.status then adjust timestamps if values.get("status"): now = timezone.now() if test_execution.status.weight != 0: test_execution.close_date = now else: test_execution.close_date = None test_execution.save() all_executions = TestExecution.objects.filter(run=test_execution.run) if (test_execution.status.weight != 0 and not all_executions.filter(status__weight=0).exists()): test_execution.run.stop_date = now test_execution.run.save() elif test_execution.status.weight == 0 and test_execution.run.stop_date: test_execution.run.stop_date = None test_execution.run.save() return test_execution.serialize()
def create(values, **kwargs): """ .. function:: XML-RPC TestPlan.create(values) Create new Test Plan object and store it in the database. :param values: Field values for :class:`tcms.testplans.models.TestPlan` :type values: dict :return: Serialized :class:`tcms.testplans.models.TestPlan` object :rtype: dict :raises: PermissionDenied if missing *testplans.add_testplan* permission :raises: ValueError if data validation fails Minimal parameters:: >>> values = { 'product': 61, 'name': 'Testplan foobar', 'type': 1, 'parent_id': 150, 'default_product_version': 93, 'text':'Testing TCMS', } >>> TestPlan.create(values) """ 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(): request = kwargs.get(REQUEST_KEY) 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(form_errors_to_list(form))
def attach_bug(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_run_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: >>> TestCaseRun.attach_bug({ 'case_run_id': 12345, 'bug_id': 67890, 'bug_system_id': 1, 'summary': 'Testing TCMS', 'description': 'Just foo and bar', }) """ 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(form_errors_to_list(form)) return
def update(execution_id, values, **kwargs): """ .. function:: XML-RPC TestExecution.update(execution_id, values) Update the selected TestExecution :param execution_id: PK of TestExecution to modify :type execution_id: int :param values: Field values for :class:`tcms.testruns.models.TestExecution` :type values: dict :param kwargs: Dict providing access to the current request, protocol entry point name and handler instance from the rpc method :return: Serialized :class:`tcms.testruns.models.TestExecution` object :rtype: dict :raises ValueError: if data validations fail :raises PermissionDenied: if missing *testruns.change_testexecution* permission """ execution = TestExecution.objects.get(pk=execution_id) form = UpdateExecutionForm(values) if form.is_valid(): if form.cleaned_data['build']: execution.build = form.cleaned_data['build'] if form.cleaned_data['assignee']: execution.assignee = form.cleaned_data['assignee'] if form.cleaned_data['status']: execution.status = form.cleaned_data['status'] request = kwargs.get(REQUEST_KEY) execution.tested_by = request.user if form.cleaned_data['sortkey'] is not None: execution.sortkey = form.cleaned_data['sortkey'] if form.cleaned_data['tested_by']: execution.tested_by = form.cleaned_data['tested_by'] case_text_version = form.cleaned_data['case_text_version'] if case_text_version: _update_case_text_version(execution, case_text_version) execution.save() else: raise ValueError(form_errors_to_list(form)) return execution.serialize()
def add_link(values, update_tracker=False, **kwargs): """ .. function:: RPC TestExecution.add_link(values) Add new URL link to a TestExecution :param values: Field values for :class:`tcms.core.contrib.linkreference.models.LinkReference` :type values: dict :param update_tracker: Automatically update Issue Tracker by placing a comment linking back to the failed TestExecution. :type update_tracker: bool, default=False :param kwargs: Dict providing access to the current request, protocol entry point name and handler instance from the rpc method :return: Serialized :class:`tcms.core.contrib.linkreference.models.LinkReference` object :rtype: dict :raises RuntimeError: if operation not successfull :raises ValueError: if input validation fails .. note:: Always 'link' with IT instance if URL is from Kiwi TCMS own bug tracker! """ # for backwards compatibility if "execution_id" in values: values["execution"] = values["execution_id"] del values["execution_id"] form = LinkReferenceForm(values) if form.is_valid(): link = form.save() else: raise ValueError(form_errors_to_list(form)) request = kwargs.get(REQUEST_KEY) tracker = tracker_from_url(link.url, request) if ( link.is_defect and tracker is not None and update_tracker and not tracker.is_adding_testcase_to_issue_disabled() ) or isinstance(tracker, KiwiTCMS): tracker.add_testexecution_to_issue([link.execution], link.url) return model_to_dict(link)
def create(values, **kwargs): """ .. function:: RPC TestPlan.create(values) Create new Test Plan object and store it in the database. :param values: Field values for :class:`tcms.testplans.models.TestPlan` :type values: dict :param \\**kwargs: Dict providing access to the current request, protocol, entry point name and handler instance from the rpc method :return: Serialized :class:`tcms.testplans.models.TestPlan` object :rtype: dict :raises PermissionDenied: if missing *testplans.add_testplan* permission :raises ValueError: if data validation fails Minimal parameters:: >>> values = { 'product': 61, 'product_version': 93, 'name': 'Testplan foobar', 'type': 1, 'parent': 150, 'text':'Testing TCMS', } >>> TestPlan.create(values) """ request = kwargs.get(REQUEST_KEY) if not values.get("author"): values["author"] = request.user.pk if not values.get("is_active"): values["is_active"] = True form = NewPlanForm(values) form.populate(product_id=values["product"]) if form.is_valid(): test_plan = form.save() result = model_to_dict(test_plan, exclude=["tag"]) # b/c value is set in the DB directly and if None # model_to_dict() will not return it result["create_date"] = test_plan.create_date return result raise ValueError(form_errors_to_list(form))
def create(values): """ .. function:: XML-RPC TestCaseRun.create(values) Create new TestCaseRun object and store it in the database. :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.add_testcaserun* permission Minimal parameters:: >>> values = { 'run': 1990, 'case': 12345, 'build': 123, } >>> TestCaseRun.create(values) """ 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(form_errors_to_list(form)) return tcr.serialize()
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(case_id, values): """ .. function:: RPC TestCase.update(case_id, values) Update the fields of the selected test case. :param case_id: PK of TestCase to be modified :type case_id: int :param values: Field values for :class:`tcms.testcases.models.TestCase`. :type values: dict :return: Serialized :class:`tcms.testcases.models.TestCase` object :rtype: dict :raises ValueError: if form is not valid :raises TestCase.DoesNotExist: if object specified by PK doesn't exist :raises PermissionDenied: if missing *testcases.change_testcase* permission """ test_case = TestCase.objects.get(pk=case_id) form = UpdateForm(values, instance=test_case) if form.is_valid(): test_case = form.save() result = model_to_dict(test_case, exclude=["component", "plan", "tag"]) # b/c date may be None and model_to_dict() doesn't return it result["create_date"] = test_case.create_date # additional information result["case_status__name"] = test_case.case_status.name result["category__name"] = test_case.category.name result["priority__value"] = test_case.priority.value result["author__username"] = ( test_case.author.username if test_case.author else None ) result["default_tester__username"] = ( test_case.default_tester.username if test_case.default_tester else None ) result["reviewer__username"] = ( test_case.reviewer.username if test_case.reviewer else None ) result["setup_duration"] = str(result["setup_duration"]) result["testing_duration"] = str(result["testing_duration"]) return result raise ValueError(form_errors_to_list(form))
def create(values): """ .. function:: XML-RPC TestRun.create(values) Create new TestRun object and store it in the database. :param values: Field values for :class:`tcms.testruns.models.TestRun` :type values: dict :return: Serialized :class:`tcms.testruns.models.TestRun` object :raises: PermissionDenied if missing *testruns.add_testrun* permission :raises: ValueError if data validations fail Example:: >>> values = {'build': 384, 'manager': 137, 'plan': 137, 'summary': 'Testing XML-RPC for TCMS', } >>> TestRun.create(values) """ # TODO: XMLRPC only accept HH:MM:SS rather than DdHhMm if values.get('estimated_time'): values['estimated_time'] = parse_duration(values.get('estimated_time')) form = XMLRPCNewRunForm(values) form.assign_plan(values.get('plan')) if form.is_valid(): test_run = TestRun.objects.create( product_version=form.cleaned_data['plan'].product_version, 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'], ) else: raise ValueError(form_errors_to_list(form)) return test_run.serialize()