Ejemplo n.º 1
0
        def link_cases(self, template_name='plan/search_case.html'):
            """
            Handle to form to add case to plans.
            """
            SUB_MODULE_NAME = 'plans'
            tcs = None

            if request.REQUEST.get('action') == 'add_to_plan':
                if request.user.has_perm('testcases.add_testcaseplan'):
                    tcs = TestCase.objects.filter(case_id__in=request.REQUEST.getlist('case'))

                    for tc in tcs:
                        tp.add_case(tc)
                else:
                    return HttpResponse("Permission Denied")

                return HttpResponseRedirect(
                    reverse('tcms.apps.testplans.views.get', args = [plan_id, ])
                )

            if request.REQUEST.get('action') == 'search':
                form = SearchCaseForm(request.REQUEST)
                form.populate(product_id = request.REQUEST.get('product'))
                if form.is_valid():
                    tcs = TestCase.list(form.cleaned_data)
                    tcs = tcs.select_related(
                        'author', 'default_tester', 'case_status',
                        'priority', 'category', 'tag__name'
                    )
                    tcs = tcs.exclude(case_id__in = tp.case.values_list(
                        'case_id', flat = True
                    ))
            else:
                form = SearchCaseForm(initial={
                    'product': tp.product_id,
                    'product_version': tp.get_version_id(),
                    'case_status_id': TestCaseStatus.get_CONFIRMED()
                })

            return direct_to_template(request, template_name, {
                'module': MODULE_NAME,
                'sub_module': SUB_MODULE_NAME,
                'test_plan': tp,
                'test_cases': tcs,
                'search_form': form,
            })
Ejemplo n.º 2
0
def get_case_status(request, id = None):
    """
    Description: Get the case status matching the given id.

    Params:      $id - Integer: ID of the priority in the database.

    Returns:     Hash: case status object hash.

    Example:
    # Get all of case status
    >>> TestCase.get_case_status()
    # Get case status by ID 1
    >>> TestCase.get_case_status(1)
    """
    from tcms.apps.testcases.models import TestCaseStatus
    if id:
        return TestCaseStatus.objects.get(id = id).serialize()

    return TestCaseStatus.to_xmlrpc()
Ejemplo n.º 3
0
def get_case_status(request, id=None):
    """
    Description: Get the case status matching the given id.

    Params:      $id - Integer: ID of the priority in the database.

    Returns:     Hash: case status object hash.

    Example:
    # Get all of case status
    >>> TestCase.get_case_status()
    # Get case status by ID 1
    >>> TestCase.get_case_status(1)
    """
    from tcms.apps.testcases.models import TestCaseStatus

    if id:
        return TestCaseStatus.objects.get(id=id).serialize()

    return TestCaseStatus.to_xmlrpc()
Ejemplo n.º 4
0
def clone(request, template_name='plan/clone.html'):
    """Clone testplan"""
    SUB_MODULE_NAME = 'plans'

    if not request.REQUEST.get('plan'):
        return HttpResponse(Prompt.render(
            request=request,
            info_type=Prompt.Info,
            info='At least one plan is required by clone function.',
            next='javascript:window.history.go(-1)',
        ))

    tps = TestPlan.objects.filter(pk__in=request.REQUEST.getlist('plan'))

    if not tps:
        return HttpResponse(Prompt.render(
            request=request,
            info_type=Prompt.Info,
            info='The plan you specific does not exist in database',
            next='javascript:window.history.go(-1)',
        ))
    # Clone the plan if the form is submitted
    if request.method == "POST":
        clone_form = ClonePlanForm(request.REQUEST)
        clone_form.populate(product_id=request.REQUEST.get('product_id'))
        if clone_form.is_valid():

            # Create new test plan.
            for tp in tps:
                tp_dest = TestPlan.objects.create(
                    product=clone_form.cleaned_data['product'],
                    author=clone_form.cleaned_data['keep_orignal_author'] and tp.author or request.user,
                    type=tp.type,
                    default_product_version=clone_form.cleaned_data['default_product_version'],
                    name = len(tps) == 1 and clone_form.cleaned_data['name'] or tp.name,
                    create_date=tp.create_date,
                    is_active=tp.is_active,
                    extra_link=tp.extra_link,
                    parent=clone_form.cleaned_data['set_parent'] and tp or None,
                )

                # Copy the plan documents
                if clone_form.cleaned_data['copy_texts']:
                    tptxts_src = tp.text.all()
                    for tptxt_src in tptxts_src:
                        tp_dest.add_text(
                            plan_text_version=tptxt_src.plan_text_version,
                            author=tptxt_src.author,
                            create_date=tptxt_src.create_date,
                            plan_text=tptxt_src.plan_text,
                        )
                else:
                    tp_dest.add_text(author=request.user, plan_text='',)

                # Copy the plan tags
                for tp_tag_src in tp.tag.all():
                    tp_dest.add_tag(tag=tp_tag_src)

                # Copy the plan attachments
                if clone_form.cleaned_data['copy_attachements']:
                    for tp_attach_src in tp.attachment.all():
                        tp_dest.add_attachment(attachment=tp_attach_src)

                # Copy the environment group
                if clone_form.cleaned_data['copy_environment_group']:
                    for env_group in tp.env_group.all():
                        tp_dest.add_env_group(env_group=env_group)

                # Link the cases of the plan
                if clone_form.cleaned_data['link_testcases']:
                    tpcases_src = tp.case.all()

                    if clone_form.cleaned_data['copy_testcases']:
                        for tpcase_src in tpcases_src:
                            tcp = get_object_or_404(TestCasePlan, plan=tp, case=tpcase_src)
                            if clone_form.cleaned_data['maintain_case_orignal_author']:
                                author = tpcase_src.author
                            else:
                                author = request.user

                            if clone_form.cleaned_data['keep_case_default_tester']:
                                if hasattr(tpcase_src, 'default_tester'):
                                    default_tester = getattr(tpcase_src, 'default_tester')
                                else:
                                    default_tester = None
                            else:
                                default_tester = request.user
                            tc_category, b_created = TestCaseCategory.objects.get_or_create(
                                name = tpcase_src.category.name,
                                product = clone_form.cleaned_data['product']
                                    )
                            tpcase_dest = TestCase.objects.create(
                                create_date=tpcase_src.create_date,
                                is_automated=tpcase_src.is_automated,
                                script=tpcase_src.script,
                                arguments=tpcase_src.arguments,
                                summary=tpcase_src.summary,
                                requirement=tpcase_src.requirement,
                                alias=tpcase_src.alias,
                                estimated_time=tpcase_src.estimated_time,
                                case_status=TestCaseStatus.get_PROPOSED(),
                                category=tc_category,
                                priority=tpcase_src.priority,
                                author=author,
                                default_tester=default_tester,
                            )

                            # Add case to plan.
                            tp_dest.add_case(tpcase_dest, tcp.sortkey)

                            for tc_tag_src in tpcase_src.tag.all():
                                tpcase_dest.add_tag(tag=tc_tag_src)
                            for component in tpcase_src.component.filter(product__id=tp.product_id):
                                try:
                                    new_c = tp_dest.product.component.get(
                                        name=component.name
                                    )
                                except ObjectDoesNotExist, error:
                                    new_c = tp_dest.product.component.create(
                                        name=component.name,
                                        initial_owner=request.user,
                                        description=component.description,
                                    )

                                tpcase_dest.add_component(new_c)

                            text = tpcase_src.latest_text()

                            if text:
                                tpcase_dest.add_text(
                                    author=text.author,
                                    action=text.action,
                                    effect=text.effect,
                                    setup=text.setup,
                                    breakdown=text.breakdown,
                                    create_date=text.create_date,
                                )

                    else:
                        for tpcase_src in tpcases_src:
                            tcp = get_object_or_404(TestCasePlan, plan=tp, case=tpcase_src)
                            tp_dest.add_case(tpcase_src, tcp.sortkey)

            if len(tps) == 1:
                return HttpResponseRedirect(
                    reverse('tcms.apps.testplans.views.get', args = [tp_dest.plan_id, ])
                )
            else:
                args = {
                    'action': 'search',
                    'product': clone_form.cleaned_data['product'].id,
                    'default_product_version': Version.string_to_id(
                        product_id=clone_form.cleaned_data['product'].id,
                        value=clone_form.cleaned_data['default_product_version']
                    )
                }

                url_args = urllib.urlencode(args)

                return HttpResponseRedirect(
                    reverse('tcms.apps.testplans.views.all') + '?' + url_args
                )