Ejemplo n.º 1
0
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                           |
      | product_version(default_product_version)  | Integer        | Required  | ID of version, product_version(recommend),|
      |                                           |                |           | default_product_version will be deprecated|
      |                                           |                |           | in future release.                        |
      | 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.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))
Ejemplo n.º 2
0
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))