Example #1
0
    def post(self, request):
        if not self._is_request_data_valid(request):
            return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))

        # Do the clone action
        clone_form = CloneCaseForm(request.POST)
        clone_form.populate(case_ids=request.POST.getlist('case'))

        if clone_form.is_valid():
            for tc_src in clone_form.cleaned_data['case']:
                tc_dest = tc_src.clone(request.user, clone_form.cleaned_data['plan'])

            # Detect the number of items and redirect to correct one
            if len(clone_form.cleaned_data['case']) == 1:
                return HttpResponseRedirect(
                    reverse('testcases-get', args=[tc_dest.pk, ])
                )

            if len(clone_form.cleaned_data['plan']) == 1:
                test_plan = clone_form.cleaned_data['plan'][0]
                return HttpResponseRedirect(
                    reverse('test_plan_url_short', args=[test_plan.pk])
                )

            # Otherwise tell the user the clone action is successful
            messages.add_message(request,
                                 messages.SUCCESS,
                                 _('TestCase cloning was successful'))
            return HttpResponseRedirect(reverse('plans-search'))
Example #2
0
    def get(self, request):
        if not self._is_request_data_valid(request):
            return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))

        # Initialize the clone case form
        clone_form = CloneCaseForm(request.GET)
        clone_form.populate(case_ids=request.GET.getlist("case"))

        context = {
            "form": clone_form,
        }
        return render(request, self.template_name, context)
Example #3
0
    def get(self, request):
        if not self._is_request_data_valid(request):
            return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))

        selected_cases = get_selected_testcases(request)
        # Initial the clone case form
        clone_form = CloneCaseForm(initial={
            'case': selected_cases,
        })
        clone_form.populate(case_ids=selected_cases)

        context = {
            'form': clone_form,
        }
        return render(request, self.template_name, context)
Example #4
0
    def get(self, request):
        if not self._is_request_data_valid(request, "c"):
            return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))

        # account for short param names in URI
        get_params = request.GET.copy()
        get_params.setlist("case", request.GET.getlist("c"))
        del get_params["c"]

        clone_form = CloneCaseForm(get_params)
        clone_form.populate(case_ids=get_params.getlist("case"))

        context = {
            "form": clone_form,
        }
        return render(request, self.template_name, context)
Example #5
0
    def post(self, request):
        if not self._is_request_data_valid(request):
            return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))

        # Do the clone action
        clone_form = CloneCaseForm(request.POST)
        clone_form.populate(case_ids=request.POST.getlist("case"))

        if clone_form.is_valid():
            for tc_src in clone_form.cleaned_data["case"]:
                tc_dest = tc_src.clone(request.user,
                                       clone_form.cleaned_data["plan"])

            # Detect the number of items and redirect to correct one
            if len(clone_form.cleaned_data["case"]) == 1:
                return HttpResponseRedirect(
                    reverse(
                        "testcases-get",
                        args=[
                            tc_dest.pk,
                        ],
                    ))

            if len(clone_form.cleaned_data["plan"]) == 1:
                test_plan = clone_form.cleaned_data["plan"][0]
                return HttpResponseRedirect(
                    reverse("test_plan_url_short", args=[test_plan.pk]))

            # Otherwise tell the user the clone action is successful
            messages.add_message(request, messages.SUCCESS,
                                 _("TestCase cloning was successful"))
            return HttpResponseRedirect(reverse("plans-search"))

        # invalid form
        messages.add_message(request, messages.ERROR, clone_form.errors)
        return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))
Example #6
0
def clone(request, template_name='case/clone.html'):
    """Clone one case or multiple case into other plan or plans"""

    request_data = getattr(request, request.method)

    if 'selectAll' not in request_data and 'case' not in request_data:
        messages.add_message(request, messages.ERROR,
                             _('At least one TestCase is required'))
        # redirect back where we came from
        return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))

    test_plan_src = plan_from_request_or_none(request)
    test_plan = None
    search_plan_form = SearchPlanForm()

    # Do the clone action
    if request.method == 'POST':
        clone_form = CloneCaseForm(request.POST)
        clone_form.populate(case_ids=request.POST.getlist('case'))

        if clone_form.is_valid():
            tcs_src = clone_form.cleaned_data['case']
            for tc_src in tcs_src:
                if clone_form.cleaned_data['copy_case']:
                    tc_dest = TestCase.objects.create(
                        is_automated=tc_src.is_automated,
                        script=tc_src.script,
                        arguments=tc_src.arguments,
                        extra_link=tc_src.extra_link,
                        summary=tc_src.summary,
                        requirement=tc_src.requirement,
                        case_status=TestCaseStatus.get_proposed(),
                        category=tc_src.category,
                        priority=tc_src.priority,
                        notes=tc_src.notes,
                        text=tc_src.text,
                        author=clone_form.
                        cleaned_data['maintain_case_orignal_author']
                        and tc_src.author or request.user,
                        default_tester=clone_form.
                        cleaned_data['maintain_case_orignal_default_tester']
                        and tc_src.author or request.user,
                    )

                    for test_plan in clone_form.cleaned_data['plan']:
                        # copy a case and keep origin case's sortkey
                        if test_plan_src:
                            try:
                                tcp = TestCasePlan.objects.get(
                                    plan=test_plan_src, case=tc_src)
                                sortkey = tcp.sortkey
                            except ObjectDoesNotExist:
                                sortkey = test_plan.get_case_sortkey()
                        else:
                            sortkey = test_plan.get_case_sortkey()

                        test_plan.add_case(tc_dest, sortkey)

                    for tag in tc_src.tag.all():
                        tc_dest.add_tag(tag=tag)
                else:
                    tc_dest = tc_src
                    tc_dest.author = request.user
                    if clone_form.cleaned_data['maintain_case_orignal_author']:
                        tc_dest.author = tc_src.author

                    tc_dest.default_tester = request.user
                    if clone_form.cleaned_data[
                            'maintain_case_orignal_default_tester']:
                        tc_dest.default_tester = tc_src.default_tester

                    tc_dest.save()

                    for test_plan in clone_form.cleaned_data['plan']:
                        # create case link and keep origin plan's sortkey
                        if test_plan_src:
                            try:
                                tcp = TestCasePlan.objects.get(
                                    plan=test_plan_src, case=tc_dest)
                                sortkey = tcp.sortkey
                            except ObjectDoesNotExist:
                                sortkey = test_plan.get_case_sortkey()
                        else:
                            sortkey = test_plan.get_case_sortkey()

                        test_plan.add_case(tc_dest, sortkey)

                # Add the cases to plan
                for test_plan in clone_form.cleaned_data['plan']:
                    # Clone the categories to new product
                    if clone_form.cleaned_data['copy_case']:
                        try:
                            tc_category = test_plan.product.category.get(
                                name=tc_src.category.name)
                        except ObjectDoesNotExist:
                            tc_category = test_plan.product.category.create(
                                name=tc_src.category.name,
                                description=tc_src.category.description,
                            )

                        tc_dest.category = tc_category
                        tc_dest.save()
                        del tc_category

                    # Clone the components to new product
                    if clone_form.cleaned_data['copy_component'] and \
                            clone_form.cleaned_data['copy_case']:
                        for component in tc_src.component.all():
                            try:
                                new_c = test_plan.product.component.get(
                                    name=component.name)
                            except ObjectDoesNotExist:
                                new_c = test_plan.product.component.create(
                                    name=component.name,
                                    initial_owner=request.user,
                                    description=component.description,
                                )

                            tc_dest.add_component(new_c)

            # Detect the number of items and redirect to correct one
            cases_count = len(clone_form.cleaned_data['case'])
            plans_count = len(clone_form.cleaned_data['plan'])

            if cases_count == 1 and plans_count == 1:
                return HttpResponseRedirect(
                    '%s?from_plan=%s' %
                    (reverse('testcases-get', args=[
                        tc_dest.pk,
                    ]), test_plan.pk))

            if cases_count == 1:
                return HttpResponseRedirect(
                    reverse('testcases-get', args=[
                        tc_dest.pk,
                    ]))

            if plans_count == 1:
                return HttpResponseRedirect(
                    reverse('test_plan_url_short', args=[
                        test_plan.pk,
                    ]))

            # Otherwise it will prompt to user the clone action is successful.
            messages.add_message(request, messages.SUCCESS,
                                 _('TestCase cloning was successful'))
            return HttpResponseRedirect(reverse('plans-search'))
    else:
        selected_cases = get_selected_testcases(request)
        # Initial the clone case form
        clone_form = CloneCaseForm(
            initial={
                'case': selected_cases,
                'copy_case': False,
                'maintain_case_orignal_author': False,
                'maintain_case_orignal_default_tester': False,
                'copy_component': True,
            })
        clone_form.populate(case_ids=selected_cases)

    # Generate search plan form
    if request_data.get('from_plan'):
        test_plan = TestPlan.objects.get(plan_id=request_data['from_plan'])
        search_plan_form = SearchPlanForm(initial={
            'product': test_plan.product_id,
            'is_active': True
        })
        search_plan_form.populate(product_id=test_plan.product_id)

    submit_action = request_data.get('submit', None)
    context = {
        'test_plan': test_plan,
        'search_form': search_plan_form,
        'clone_form': clone_form,
        'submit_action': submit_action,
    }
    return render(request, template_name, context)
Example #7
0
    def post(self, request):
        if not self._is_request_data_valid(request):
            return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))

        # Do the clone action
        clone_form = CloneCaseForm(request.POST)
        clone_form.populate(case_ids=request.POST.getlist('case'))

        if clone_form.is_valid():
            tcs_src = clone_form.cleaned_data['case']
            for tc_src in tcs_src:
                tc_dest = TestCase.objects.create(
                    is_automated=tc_src.is_automated,
                    script=tc_src.script,
                    arguments=tc_src.arguments,
                    extra_link=tc_src.extra_link,
                    summary=tc_src.summary,
                    requirement=tc_src.requirement,
                    case_status=TestCaseStatus.get_proposed(),
                    category=tc_src.category,
                    priority=tc_src.priority,
                    notes=tc_src.notes,
                    text=tc_src.text,
                    author=request.user,
                    default_tester=tc_src.default_tester,
                )

                # apply tags as well
                for tag in tc_src.tag.all():
                    tc_dest.add_tag(tag=tag)

                for test_plan in clone_form.cleaned_data['plan']:
                    # add new TC to selected TP
                    sortkey = test_plan.get_case_sortkey()
                    test_plan.add_case(tc_dest, sortkey)

                    # clone TC category b/c we may be cloning a 'linked'
                    # TC which has a different Product that doesn't have the
                    # same categories yet
                    try:
                        tc_category = test_plan.product.category.get(
                            name=tc_src.category.name
                        )
                    except ObjectDoesNotExist:
                        tc_category = test_plan.product.category.create(
                            name=tc_src.category.name,
                            description=tc_src.category.description,
                        )
                    tc_dest.category = tc_category
                    tc_dest.save()

                    # clone TC components b/c we may be cloning a 'linked'
                    # TC which has a different Product that doesn't have the
                    # same components yet
                    for component in tc_src.component.all():
                        try:
                            new_c = test_plan.product.component.get(name=component.name)
                        except ObjectDoesNotExist:
                            new_c = test_plan.product.component.create(
                                name=component.name,
                                initial_owner=request.user,
                                description=component.description,
                            )
                        tc_dest.add_component(new_c)

            # Detect the number of items and redirect to correct one
            cases_count = len(clone_form.cleaned_data['case'])
            plans_count = len(clone_form.cleaned_data['plan'])

            if cases_count == 1:
                return HttpResponseRedirect(
                    reverse('testcases-get', args=[tc_dest.pk, ])
                )

            if plans_count == 1:
                return HttpResponseRedirect(
                    reverse('test_plan_url_short', args=[test_plan.pk, ])
                )

            # Otherwise it will prompt to user the clone action is successful.
            messages.add_message(request,
                                 messages.SUCCESS,
                                 _('TestCase cloning was successful'))
            return HttpResponseRedirect(reverse('plans-search'))