Example #1
0
def unlink_plan(requst, case_id, plan_id):
    """
    Description: Unlink a test case from the given plan. If only one plan is linked, this will delete
                 the test case.

    Params:      $case_ids - Integer/String: An integer or alias representing the ID in the database.
                 $plan_id  - Integer: An integer representing the ID in the database.

    Returns:     Array: Array of plans hash still linked if any, empty if not.

    Example:
    >>> TestCase.unlink_plan(12345, 137)
    """
    from nitrate.apps.testplans.models import TestPlan
    try:
        tc = TestCase.objects.get(case_id = case_id)
        tp = tc.plan.get(plan_id = plan_id)
    except:
        raise

    tc.remove_plan(plan = tp)

    plan_ids = tc.plan.values_list('plan_id', flat = True)
    query = {'plan_id__in': plan_ids}
    return TestPlan.to_xmlrpc(query)
Example #2
0
def get_plans(request, case_id):
    """
    Description: Get the list of plans that this case is linked to.

    Params:      $case_id - Integer/String: An integer representing the ID in the database

    Returns:     Array: An array of test plan object hashes.

    Example:
    >>> TestCase.get_plans(12345)
    """
    from nitrate.apps.testplans.models import TestPlan
    try:
        tc = TestCase.objects.get(case_id = case_id)
    except:
        raise

    plan_ids = tc.plan.values_list('plan_id', flat = True)
    query = {'plan_id__in': plan_ids}
    return TestPlan.to_xmlrpc(query)
Example #3
0
def get_plans(request, product):
    """
    Description: Get the list of plans associated with this product.

    Params:      $product - Integer/String
                            Integer: product_id of the product in the Database
                            String: Product name

    Returns:     Array: Returns an array of Test Plan objects.

    Example:
    # Get with product id
    >>> Product.get_plans(61)
    # Get with product name
    >>> Product.get_plans('Red Hat Enterprise Linux 5')
    """
    from nitrate.apps.testplans.models import TestPlan
    p = pre_check_product(values = product)
    query = {'product': p}
    return TestPlan.to_xmlrpc(query)
Example #4
0
def filter(request, values = {}):
    """
    Description: Performs a search and returns the resulting list of test plans.

    Params:      $values - Hash: keys must match valid search fields.

        +------------------------------------------------------------+
        |                   Plan Search Parameters                   |
        +----------------------------------------------------------+
        |        Key              |          Valid Values            |
        | author                  | ForeignKey: Auth.User            |
        | attachment              | ForeignKey: Attachment           |
        | case                    | ForeignKey: Test Case            |
        | create_date             | DateTime                         |
        | default_product_version | String                           |
        | env_group               | ForeignKey: Environment Group    |
        | name                    | String                           |
        | plan_id                 | Integer                          |
        | product                 | ForeignKey: Product              |
        | tag                     | ForeignKey: Tag                  |
        | text                    | ForeignKey: Test Plan Text       |
        | type                    | ForeignKey: Test Plan Type       |
        +------------------------------------------------------------+

    Returns:     Array: Matching test plans are retuned in a list of plan object hashes.

    Example:
    # Get all of plans contain 'TCMS' in name
    >>> TestPlan.filter({'name__icontain': 'TCMS'})
    # Get all of plans create by xkuang
    >>> TestPlan.filter({'author__username': '******'})
    # Get all of plans the author name starts with x
    >>> TestPlan.filter({'author__username__startswith': 'x'})
    # Get plans contain the case ID 12345, 23456, 34567
    >>> TestPlan.filter({'case__case_id__in': [12345, 23456, 34567]})
    """
    return TestPlan.to_xmlrpc(values)
Example #5
0
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 nitrate.core import forms
    from nitrate.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)