Beispiel #1
0
    def post(self, request, *args, **kwargs):
        test_plan = plan_from_request_or_none(request)

        form = NewCaseForm(request.POST)
        if request.POST.get('product'):
            form.populate(product_id=request.POST['product'])
        else:
            form.populate()

        notify_form = CaseNotifyForm(request.POST)

        if form.is_valid() and notify_form.is_valid():
            test_case = self.create_test_case(form, notify_form, test_plan)
            if test_plan:
                return HttpResponseRedirect('%s?from_plan=%s' % (reverse(
                    'testcases-get', args=[test_case.pk]), test_plan.pk))

            return HttpResponseRedirect(
                reverse('testcases-get', args=[test_case.pk]))

        context_data = {
            'test_plan': test_plan,
            'form': form,
            'notify_form': notify_form
        }

        return render(request, self.template_name, context_data)
Beispiel #2
0
    def get(self, request, *args, **kwargs):
        test_plan = plan_from_request_or_none(request)

        default_form_parameters = {}
        if test_plan:
            default_form_parameters['product'] = test_plan.product_id

        form = NewCaseForm(initial=default_form_parameters)

        context_data = {
            'test_plan': test_plan,
            'form': form,
            'notify_form': CaseNotifyForm(),
        }

        return render(request, self.template_name, context_data)
Beispiel #3
0
def edit(request, case_id):
    """Edit case detail"""
    try:
        test_case = TestCase.objects.select_related().get(case_id=case_id)
    except ObjectDoesNotExist:
        raise Http404

    test_plan = plan_from_request_or_none(request)
    from_plan = ""
    if test_plan:
        from_plan = "?from_plan=%d" % test_plan.pk

    if request.method == "POST":
        form = NewCaseForm(request.POST)
        if request.POST.get('product'):
            form.populate(product_id=request.POST['product'])
        elif test_plan:
            form.populate(product_id=test_plan.product_id)
        else:
            form.populate()

        n_form = CaseNotifyForm(request.POST)

        if form.is_valid() and n_form.is_valid():
            update_testcase(request, test_case, form)
            update_case_email_settings(test_case, n_form)

            return HttpResponseRedirect(
                reverse('testcases-get', args=[
                    case_id,
                ]) + from_plan)

    else:
        # Notification form initial
        n_form = CaseNotifyForm(
            initial={
                'notify_on_case_update':
                test_case.emailing.notify_on_case_update,
                'notify_on_case_delete':
                test_case.emailing.notify_on_case_delete,
                'author':
                test_case.emailing.auto_to_case_author,
                'default_tester_of_case':
                test_case.emailing.auto_to_case_tester,
                'managers_of_runs':
                test_case.emailing.auto_to_run_manager,
                'default_testers_of_runs':
                test_case.emailing.auto_to_run_tester,
                'assignees_of_case_runs':
                test_case.emailing.auto_to_case_run_assignee,
                'cc_list':
                MultipleEmailField.delimiter.join(
                    test_case.emailing.get_cc_list()),
            })

        components = []
        for component in test_case.component.all():
            components.append(component.pk)

        default_tester = None
        if test_case.default_tester_id:
            default_tester = test_case.default_tester.email

        form = NewCaseForm(
            initial={
                'summary': test_case.summary,
                'default_tester': default_tester,
                'requirement': test_case.requirement,
                'is_automated': test_case.is_automated,
                'script': test_case.script,
                'arguments': test_case.arguments,
                'extra_link': test_case.extra_link,
                'case_status': test_case.case_status_id,
                'priority': test_case.priority_id,
                'product': test_case.category.product_id,
                'category': test_case.category_id,
                'notes': test_case.notes,
                'text': test_case.text,
            })

        form.populate(product_id=test_case.category.product_id)

    context_data = {
        'test_case': test_case,
        'test_plan': test_plan,
        'form': form,
        'notify_form': n_form,
    }
    return render(request, 'testcases/mutable.html', context_data)
Beispiel #4
0
def edit(request, case_id, template_name='case/edit.html'):
    """Edit case detail"""
    try:
        test_case = TestCase.objects.select_related().get(case_id=case_id)
    except ObjectDoesNotExist:
        raise Http404

    test_plan = plan_from_request_or_none(request)

    if request.method == "POST":
        form = EditCaseForm(request.POST)
        if request.POST.get('product'):
            form.populate(product_id=request.POST['product'])
        elif test_plan:
            form.populate(product_id=test_plan.product_id)
        else:
            form.populate()

        n_form = CaseNotifyForm(request.POST)

        if form.is_valid() and n_form.is_valid():

            update_testcase(request, test_case, form)

            test_case.add_text(author=request.user,
                               action=form.cleaned_data['action'],
                               effect=form.cleaned_data['effect'],
                               setup=form.cleaned_data['setup'],
                               breakdown=form.cleaned_data['breakdown'])

            # Notification
            update_case_email_settings(test_case, n_form)

            # Returns
            if request.POST.get('_continue'):
                return HttpResponseRedirect('%s?from_plan=%s' % (
                    reverse('testcases-edit', args=[
                        case_id,
                    ]),
                    request.POST.get('from_plan', None),
                ))

            if request.POST.get('_continuenext'):
                if not test_plan:
                    raise Http404

                # find out test case list which belong to the same
                # classification
                confirm_status_name = 'CONFIRMED'
                if test_case.case_status.name == confirm_status_name:
                    pk_list = test_plan.case.filter(
                        case_status__name=confirm_status_name)
                else:
                    pk_list = test_plan.case.exclude(
                        case_status__name=confirm_status_name)
                pk_list = list(
                    pk_list.defer('case_id').values_list('pk', flat=True))
                pk_list.sort()

                # Get the next case
                _prev_case, next_case = test_case.get_previous_and_next(
                    pk_list=pk_list)
                return HttpResponseRedirect('%s?from_plan=%s' % (
                    reverse('testcases-edit', args=[
                        next_case.pk,
                    ]),
                    test_plan.pk,
                ))

            if request.POST.get('_returntoplan'):
                if not test_plan:
                    raise Http404
                confirm_status_name = 'CONFIRMED'
                if test_case.case_status.name == confirm_status_name:
                    return HttpResponseRedirect(
                        '%s#testcases' %
                        (reverse('test_plan_url_short', args=[
                            test_plan.pk,
                        ]), ))
                return HttpResponseRedirect(
                    '%s#reviewcases' %
                    (reverse('test_plan_url_short', args=[
                        test_plan.pk,
                    ]), ))

            return HttpResponseRedirect('%s?from_plan=%s' % (
                reverse('testcases-get', args=[
                    case_id,
                ]),
                request.POST.get('from_plan', None),
            ))

    else:
        tctxt = test_case.latest_text()
        # Notification form initial
        n_form = CaseNotifyForm(
            initial={
                'notify_on_case_update':
                test_case.emailing.notify_on_case_update,
                'notify_on_case_delete':
                test_case.emailing.notify_on_case_delete,
                'author':
                test_case.emailing.auto_to_case_author,
                'default_tester_of_case':
                test_case.emailing.auto_to_case_tester,
                'managers_of_runs':
                test_case.emailing.auto_to_run_manager,
                'default_testers_of_runs':
                test_case.emailing.auto_to_run_tester,
                'assignees_of_case_runs':
                test_case.emailing.auto_to_case_run_assignee,
                'cc_list':
                MultipleEmailField.delimiter.join(
                    test_case.emailing.get_cc_list()),
            })

        components = []
        for component in test_case.component.all():
            components.append(component.pk)

        default_tester = None
        if test_case.default_tester_id:
            default_tester = test_case.default_tester.email

        form = EditCaseForm(
            initial={
                'summary': test_case.summary,
                'default_tester': default_tester,
                'requirement': test_case.requirement,
                'is_automated': test_case.get_is_automated_form_value(),
                'is_automated_proposed': test_case.is_automated_proposed,
                'script': test_case.script,
                'arguments': test_case.arguments,
                'extra_link': test_case.extra_link,
                'alias': test_case.alias,
                'case_status': test_case.case_status_id,
                'priority': test_case.priority_id,
                'product': test_case.category.product_id,
                'category': test_case.category_id,
                'notes': test_case.notes,
                'component': components,
                'setup': tctxt.setup,
                'action': tctxt.action,
                'effect': tctxt.effect,
                'breakdown': tctxt.breakdown,
            })

        form.populate(product_id=test_case.category.product_id)

    context_data = {
        'test_case': test_case,
        'test_plan': test_plan,
        'form': form,
        'notify_form': n_form,
    }
    return render(request, template_name, context_data)