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) test_plan = 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'], text=form.cleaned_data['text'], ) return test_plan.serialize() raise ValueError(form_errors_to_list(form))
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, **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") or values.get("author_id")): values["author"] = request.user.pk form = NewPlanForm(values) form.populate(product_id=values["product"]) if form.is_valid(): test_plan = form.save() else: raise ValueError(form_errors_to_list(form)) return test_plan.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, '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') or values.get('author_id')): values['author'] = request.user.pk form = NewPlanForm(values) form.populate(product_id=values['product']) if form.is_valid(): test_plan = form.save() else: raise ValueError(form_errors_to_list(form)) return test_plan.serialize()