Beispiel #1
0
def new_run_with_caseruns(request,run_id,template_name='run/clone.html'):
    """Clone cases from filter caserun"""
    SUB_MODULE_NAME = "runs"
    tr = get_object_or_404(TestRun, run_id=run_id)

    if request.REQUEST.get('case_run'):
        tcrs=tr.case_run.filter(pk__in=request.REQUEST.getlist('case_run'))
    else:
        tcrs=[]

    if not tcrs:
        return HttpResponse(Prompt.render(
                    request=request,
                    info_type=Prompt.Info,
                    info='At least one case is required by a run',
                    next = request.META.get('HTTP_REFERER', '/')))
    estimated_time = reduce(lambda x, y: x + y, [tcr.case.estimated_time for tcr in tcrs])

    if not request.REQUEST.get('submit'):
        form=RunCloneForm(initial={
            'summary':tr.summary,
            'notes':tr.notes, 'manager':tr.manager.email, 'product':tr.plan.product_id,
            'product_version':tr.get_version_id(),
            'build':tr.build_id,
            'default_tester':tr.default_tester_id and tr.default_tester.email or '',
            'estimated_time': estimated_time,
            'use_newest_case_text':True,
        })

        form.populate(product_id=tr.plan.product_id)

        return direct_to_template(request,template_name,{
            'module':MODULE_NAME,
            'sub_module':SUB_MODULE_NAME,
            'clone_form':form,
            'test_run':tr,
            'cases_run':tcrs,
        })
Beispiel #2
0
def clone(request, template_name='run/clone.html'):
    """Clone test run to another build"""
    SUB_MODULE_NAME = "runs"

    trs = TestRun.objects.select_related()
    trs = trs.filter(pk__in=request.REQUEST.getlist('run'))

    if not trs:
        return HttpResponse(Prompt.render(
            request = request,
            info_type = Prompt.Info,
            info = 'At least one run is required',
            next = request.META.get('HTTP_REFERER', '/')
        ))

    # Generate the clone run page for one run
    if len(trs) == 1 and not request.REQUEST.get('submit'):
        tr = trs[0]
        tcrs = tr.case_run.all()
        form = RunCloneForm(initial={
            'summary': tr.summary,
            'notes': tr.notes,
            'manager': tr.manager.email,
            'product': tr.plan.product_id,
            'product_version': tr.get_version_id(),
            'build': tr.build_id,
            'default_tester': tr.default_tester_id and tr.default_tester.email or '',
            'use_newest_case_text': True,
            'errata_id': tr.errata_id,
        })
        form.populate(product_id=tr.plan.product_id)

        return direct_to_template(request, template_name, {
            'module': MODULE_NAME,
            'sub_module': SUB_MODULE_NAME,
            'clone_form': form,
            'test_run': tr,
            'cases_run': tcrs,
        })

    # Process multiple runs clone page
    template_name = 'run/clone_multiple.html'

    if request.method == "POST":
        form = MulitpleRunsCloneForm(request.REQUEST)
        form.populate(trs=trs, product_id=request.REQUEST.get('product'))
        if form.is_valid():
            for tr in trs:
                n_tr = TestRun.objects.create(
                    product_version=form.cleaned_data['product_version'].value,
                    plan_text_version=tr.plan_text_version,
                    summary=tr.summary,
                    notes=tr.notes,
                    estimated_time=tr.estimated_time,
                    plan=tr.plan,
                    build=form.cleaned_data['build'],
                    manager=(form.cleaned_data['update_manager'] and
                             form.cleaned_data['manager'] or
                             tr.manager),
                    default_tester=(form.cleaned_data['update_default_tester'] and
                                    form.cleaned_data['default_tester'] or
                                    tr.default_tester),
                    )

                for tcr in tr.case_run.all():
                    n_tr.add_case_run(
                        case=tcr.case,
                        assignee= tcr.assignee,
                        case_text_version=(form.cleaned_data['update_case_text'] and
                                             bool(tcr.get_text_versions()) and
                                             tcr.get_text_versions()[0] or
                                             tcr.case_text_version),
                        build=form.cleaned_data['build'],
                        notes=tcr.notes,
                        sortkey=tcr.sortkey,
                    )

                for env_value in tr.env_value.all():
                    n_tr.add_env_value(env_value)

                if form.cleaned_data['clone_cc']:
                    for cc in tr.cc.all():
                        n_tr.add_cc(user=cc)

                if form.cleaned_data['clone_tag']:
                    for tag in tr.tag.all():
                        n_tr.add_tag(tag=tag)

            if len(trs) == 1:
                return HttpResponseRedirect(
                    reverse('tcms.apps.testruns.views.get', args=[n_tr.pk])
                )

            params = {
                    'product': form.cleaned_data['product'].pk,
                    'product_version': form.cleaned_data['product_version'].pk,
                    'build': form.cleaned_data['build'].pk}

            return HttpResponseRedirect('%s?%s' % (
                reverse('tcms.apps.testruns.views.all'),
                urllib.urlencode(params, True)
            ))
    else:
        form = MulitpleRunsCloneForm(initial={
                'run': trs.values_list('pk', flat=True),
                'manager': request.user,
                'default_tester': request.user,
                'assignee': request.user,
                'update_manager': False,
                'update_default_tester': True,
                'update_assignee': True,
                'update_case_text': True,
                'clone_cc': True,
                'clone_tag': True,})
        form.populate(trs=trs)

    return direct_to_template(request, template_name, {
        'module': MODULE_NAME,
        'sub_module': SUB_MODULE_NAME,
        'clone_form': form,
    })