Ejemplo n.º 1
0
    def post(self, request):
        if 'plan' not in request.POST:
            messages.add_message(request,
                                 messages.ERROR,
                                 _('TestPlan is required'))
            # redirect back where we came from
            return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))

        plan_id = request.POST.get('plan', 0)
        test_plan = get_object_or_404(TestPlan, pk=int(plan_id))

        post_data = request.POST.copy()
        if not request.POST.get('name'):
            post_data['name'] = test_plan.make_cloned_name()

        form = ClonePlanForm(post_data)
        form.populate(product_pk=request.POST.get('product'))

        # if required values are missing we are still going to show
        # the form below, otherwise clone & redirect
        if form.is_valid():
            form.cleaned_data['new_author'] = request.user
            cloned_plan = test_plan.clone(**form.cleaned_data)

            return HttpResponseRedirect(
                reverse('test_plan_url_short', args=[cloned_plan.pk]))

        # form wasn't valid
        context_data = {
            'test_plan': test_plan,
            'form': form,
        }

        return render(request, self.template_name, context_data)
Ejemplo n.º 2
0
def clone(request):
    """Clone testplan"""

    if 'plan' not in request.POST:
        messages.add_message(request,
                             messages.ERROR,
                             _('TestPlan is required'))
        # redirect back where we came from
        return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))

    plan_id = request.POST.get('plan')
    test_plan = get_object_or_404(TestPlan, pk=int(plan_id))

    post_data = request.POST.copy()
    if not request.POST.get('name'):
        post_data['name'] = test_plan.make_cloned_name()

    clone_form = ClonePlanForm(post_data)
    clone_form.populate(product_id=request.POST.get('product_id'))

    # if required values are missing we are still going to show
    # the form below, otherwise clone & redirect
    if clone_form.is_valid():
        clone_options = clone_form.cleaned_data

        # Create new test plan.
        new_name = clone_options['name']

        clone_params = dict(
            # Cloned plan properties
            new_name=new_name,
            product=clone_options['product'],
            version=clone_options['product_version'],
            set_parent=clone_options['set_parent'],

            # Link or copy cases
            link_cases=clone_options['link_testcases'],
            copy_cases=clone_options['copy_testcases'],
            default_component_initial_owner=request.user,
        )

        assign_me_as_plan_author = not clone_options['keep_orignal_author']
        if assign_me_as_plan_author:
            clone_params['new_original_author'] = request.user

        assign_me_as_copied_case_author = \
            clone_options['copy_testcases'] and \
            not clone_options['maintain_case_orignal_author']
        if assign_me_as_copied_case_author:
            clone_params['new_case_author'] = request.user

        # pylint: disable=invalid-name
        assign_me_as_copied_case_default_tester = \
            clone_options['copy_testcases'] and \
            not clone_options['keep_case_default_tester']
        if assign_me_as_copied_case_default_tester:
            clone_params['new_case_default_tester'] = request.user

        cloned_plan = test_plan.clone(**clone_params)

        return HttpResponseRedirect(
            reverse('test_plan_url_short', args=[cloned_plan.plan_id]))

    # clone form wasn't valid
    context_data = {
        'test_plan': test_plan,
        'clone_form': clone_form,
    }
    return render(request, 'plan/clone.html', context_data)
Ejemplo n.º 3
0
def clone(request, template_name='plan/clone.html'):
    """Clone testplan"""

    req_data = request.GET or request.POST
    if 'plan' not in req_data:
        messages.add_message(request,
                             messages.ERROR,
                             _('At least one TestPlan is required'))
        # redirect back where we came from
        return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))

    plan_ids = req_data.getlist('plan')
    tps = TestPlan.objects.filter(pk__in=plan_ids)

    if not tps:
        # note: if at least one of the specified plans is found
        # we're not going to show this message
        messages.add_message(request,
                             messages.ERROR,
                             _('TestPlan(s) "%s" do not exist') % plan_ids)
        # redirect back where we came from
        return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))

    # Clone the plan if the form is submitted
    if request.method == "POST":
        clone_form = ClonePlanForm(request.POST)
        clone_form.populate(product_id=request.POST.get('product_id'))

        if clone_form.is_valid():
            clone_options = clone_form.cleaned_data

            # Create new test plan.
            for tp in tps:

                new_name = len(tps) == 1 and clone_options['name'] or None

                clone_params = dict(
                    # Cloned plan properties
                    new_name=new_name,
                    product=clone_options['product'],
                    version=clone_options['product_version'],
                    set_parent=clone_options['set_parent'],

                    # Related data
                    copy_texts=clone_options['copy_texts'],
                    copy_environment_group=clone_options['copy_environment_group'],

                    # Link or copy cases
                    link_cases=clone_options['link_testcases'],
                    copy_cases=clone_options['copy_testcases'],
                    default_component_initial_owner=request.user,
                )

                assign_me_as_plan_author = not clone_options['keep_orignal_author']
                if assign_me_as_plan_author:
                    clone_params['new_original_author'] = request.user

                assign_me_as_copied_case_author = \
                    clone_options['copy_testcases'] and \
                    not clone_options['maintain_case_orignal_author']
                if assign_me_as_copied_case_author:
                    clone_params['new_case_author'] = request.user

                assign_me_as_copied_case_default_tester = \
                    clone_options['copy_testcases'] and \
                    not clone_options['keep_case_default_tester']
                if assign_me_as_copied_case_default_tester:
                    clone_params['new_case_default_tester'] = request.user

                assign_me_as_text_author = not clone_options['copy_texts']
                if assign_me_as_text_author:
                    clone_params['default_text_author'] = request.user

                cloned_plan = tp.clone(**clone_params)

            if len(tps) == 1:
                return HttpResponseRedirect(
                    reverse('test_plan_url_short', args=[cloned_plan.plan_id]))
            else:
                args = {
                    'action': 'search',
                    'product': clone_form.cleaned_data['product'].id,
                    'product_version': clone_form.cleaned_data['product_version'].id,
                }
                url_args = urlencode(args)
                return HttpResponseRedirect(
                    '{}?{}'.format(reverse('plans-all'), url_args))
    else:
        # Generate the default values for the form
        if len(tps) == 1:
            clone_form = ClonePlanForm(initial={
                'product': tps[0].product_id,
                'product_version': tps[0].product_version_id,
                'set_parent': True,
                'copy_texts': True,
                'copy_attachements': True,
                'copy_environment_group': True,
                'link_testcases': True,
                'copy_testcases': False,
                'maintain_case_orignal_author': True,
                'keep_case_default_tester': False,
                'name': tps[0].make_cloned_name(),
            })
            clone_form.populate(product_id=tps[0].product.id)
        else:
            clone_form = ClonePlanForm(initial={
                'set_parent': True,
                'copy_texts': True,
                'copy_attachements': True,
                'link_testcases': True,
                'copy_testcases': False,
                'maintain_case_orignal_author': True,
                'keep_case_default_tester': True,
            })

    context_data = {
        'testplans': tps,
        'clone_form': clone_form,
    }
    return render(request, template_name, context_data)
Ejemplo n.º 4
0
def clone(request, template_name='plan/clone.html'):
    """Clone testplan"""
    SUB_MODULE_NAME = 'plans'

    req_data = request.GET or request.POST
    if 'plan' not in req_data:
        return prompt.info(
            request,
            'At least one plan is required by clone function.',
        )

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

    if not tps:
        return prompt.info(
            request,
            'The plan you specify does not exist in database.',
        )

    # Clone the plan if the form is submitted
    if request.method == "POST":
        clone_form = ClonePlanForm(request.POST)
        clone_form.populate(product_id=request.POST.get('product_id'))

        if clone_form.is_valid():
            clone_options = clone_form.cleaned_data

            # Create new test plan.
            for tp in tps:

                new_name = len(tps) == 1 and clone_options['name'] or None

                clone_params = {
                    # Cloned plan properties
                    'new_name':
                    new_name,
                    'product':
                    clone_options['product'],
                    'version':
                    clone_options['product_version'],
                    'set_parent':
                    clone_options['set_parent'],

                    # Related data
                    'copy_texts':
                    clone_options['copy_texts'],
                    'copy_attachments':
                    clone_options['copy_attachements'],
                    'copy_environment_group':
                    clone_options['copy_environment_group'],

                    # Link or copy cases
                    'link_cases':
                    clone_options['link_testcases'],
                    'copy_cases':
                    clone_options['copy_testcases'],
                    'default_component_initial_owner':
                    request.user,
                }

                assign_me_as_plan_author = not clone_options[
                    'keep_orignal_author']
                if assign_me_as_plan_author:
                    clone_params['new_original_author'] = request.user

                assign_me_as_copied_case_author = (
                    clone_options['copy_testcases']
                    and not clone_options['maintain_case_orignal_author'])
                if assign_me_as_copied_case_author:
                    clone_params['new_case_author'] = request.user

                assign_me_as_copied_case_default_tester = (
                    clone_options['copy_testcases']
                    and not clone_options['keep_case_default_tester'])
                if assign_me_as_copied_case_default_tester:
                    clone_params['new_case_default_tester'] = request.user

                assign_me_as_text_author = not clone_options['copy_texts']
                if assign_me_as_text_author:
                    clone_params['default_text_author'] = request.user

                cloned_plan = tp.clone(**clone_params)

            if len(tps) == 1:
                return HttpResponseRedirect(
                    reverse('plan-get', args=[cloned_plan.plan_id]))
            else:
                args = {
                    'action':
                    'search',
                    'product':
                    clone_form.cleaned_data['product'].id,
                    'product_version':
                    clone_form.cleaned_data['product_version'].id,
                }
                url_args = urllib.parse.urlencode(args)
                return HttpResponseRedirect('{}?{}'.format(
                    reverse('plans-all'), url_args))
    else:
        # Generate the default values for the form
        if len(tps) == 1:
            clone_form = ClonePlanForm(
                initial={
                    'product': tps[0].product_id,
                    'product_version': tps[0].product_version_id,
                    'set_parent': True,
                    'copy_texts': True,
                    'copy_attachements': True,
                    'copy_environment_group': True,
                    'link_testcases': True,
                    'copy_testcases': False,
                    'maintain_case_orignal_author': True,
                    'keep_case_default_tester': False,
                    'name': tps[0].make_cloned_name(),
                })
            clone_form.populate(product_id=tps[0].product.id)
        else:
            clone_form = ClonePlanForm(
                initial={
                    'set_parent': True,
                    'copy_texts': True,
                    'copy_attachements': True,
                    'link_testcases': True,
                    'copy_testcases': False,
                    'maintain_case_orignal_author': True,
                    'keep_case_default_tester': True,
                })

    context_data = {
        'module': MODULE_NAME,
        'sub_module': SUB_MODULE_NAME,
        'testplans': tps,
        'clone_form': clone_form,
    }
    return render(request, template_name, context=context_data)
Ejemplo n.º 5
0
def clone(request, template_name='plan/clone.html'):
    """Clone testplan"""
    SUB_MODULE_NAME = 'plans'

    req_data = request.GET or request.POST
    if 'plan' not in req_data:
        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=req_data.getlist('plan'))

    if not tps:
        return HttpResponse(Prompt.render(
            request=request,
            info_type=Prompt.Info,
            info='The plan you specify 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.POST)
        clone_form.populate(product_id=request.POST.get('product_id'))

        if clone_form.is_valid():
            clone_options = clone_form.cleaned_data

            # Create new test plan.
            for tp in tps:

                new_name = len(tps) == 1 and clone_options['name'] or None

                clone_params = dict(
                    # Cloned plan properties
                    new_name=new_name,
                    product=clone_options['product'],
                    version=clone_options['product_version'],
                    set_parent=clone_options['set_parent'],

                    # Related data
                    copy_texts=clone_options['copy_texts'],
                    copy_attachments=clone_options['copy_attachements'],
                    copy_environment_group=clone_options['copy_environment_group'],

                    # Link or copy cases
                    link_cases=clone_options['link_testcases'],
                    copy_cases=clone_options['copy_testcases'],
                    default_component_initial_owner=request.user,
                )

                assign_me_as_plan_author = not clone_options['keep_orignal_author']
                if assign_me_as_plan_author:
                    clone_params['new_original_author'] = request.user

                assign_me_as_copied_case_author = \
                    clone_options['copy_testcases'] and \
                    not clone_options['maintain_case_orignal_author']
                if assign_me_as_copied_case_author:
                    clone_params['new_case_author'] = request.user

                assign_me_as_copied_case_default_tester = \
                    clone_options['copy_testcases'] and \
                    not clone_options['keep_case_default_tester']
                if assign_me_as_copied_case_default_tester:
                    clone_params['new_case_default_tester'] = request.user

                assign_me_as_text_author = not clone_options['copy_texts']
                if assign_me_as_text_author:
                    clone_params['default_text_author'] = request.user

                cloned_plan = tp.clone(**clone_params)

            if len(tps) == 1:
                return HttpResponseRedirect(
                    reverse('tcms.testplans.views.get', args=[cloned_plan.plan_id]))
            else:
                args = {
                    'action': 'search',
                    'product': clone_form.cleaned_data['product'].id,
                    'product_version': clone_form.cleaned_data['product_version'].id,
                }
                url_args = urllib.urlencode(args)
                return HttpResponseRedirect(
                    '{}?{}'.format(reverse('tcms.testplans.views.all'), url_args))
    else:
        # Generate the default values for the form
        if len(tps) == 1:
            clone_form = ClonePlanForm(initial={
                'product': tps[0].product_id,
                'product_version': tps[0].product_version_id,
                'set_parent': True,
                'copy_texts': True,
                'copy_attachements': True,
                'copy_environment_group': True,
                'link_testcases': True,
                'copy_testcases': False,
                'maintain_case_orignal_author': True,
                'keep_case_default_tester': False,
                'name': tps[0].make_cloned_name(),
            })
            clone_form.populate(product_id=tps[0].product.id)
        else:
            clone_form = ClonePlanForm(initial={
                'set_parent': True,
                'copy_texts': True,
                'copy_attachements': True,
                'link_testcases': True,
                'copy_testcases': False,
                'maintain_case_orignal_author': True,
                'keep_case_default_tester': True,
            })

    context_data = {
        'module': MODULE_NAME,
        'sub_module': SUB_MODULE_NAME,
        'testplans': tps,
        'clone_form': clone_form,
    }
    return render_to_response(template_name, context_data,
                              context_instance=RequestContext(request))