Exemple #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)
Exemple #2
0
    def _addanother(self):
        form = NewCaseForm(initial=self.default_form_parameters)

        if self.plan:
            form.populate(product_id=self.plan.product_id)

        return form
Exemple #3
0
def new(request, template_name='case/edit.html'):
    """New testcase"""
    test_plan = plan_from_request_or_none(request)
    # Initial the form parameters when write new case from plan
    if test_plan:
        default_form_parameters = {
            'product': test_plan.product_id,
            'is_automated': '0',
        }
    # Initial the form parameters when write new case directly
    else:
        default_form_parameters = {'is_automated': '0'}

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

        if form.is_valid():
            test_case = create_testcase(request, form, test_plan)
            # Generate the instance of actions
            ras = ReturnActions(test_case, test_plan, default_form_parameters)
            for ra_str in ras.all_actions:
                if request.POST.get(ra_str):
                    func = getattr(ras, ra_str)
                    break
            else:
                func = ras.returntocase

            # Get the function and return back
            result = func()
            if isinstance(result, HttpResponseRedirect):
                return result
            # Assume here is the form
            form = result

    # Initial NewCaseForm for submit
    else:
        test_plan = plan_from_request_or_none(request)
        form = NewCaseForm(initial=default_form_parameters)
        if test_plan:
            form.populate(product_id=test_plan.product_id)

    context_data = {'test_plan': test_plan, 'form': form}
    return render(request, template_name, context_data)
Exemple #4
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)
Exemple #5
0
def create(values, **kwargs):
    """
    .. function:: XML-RPC TestCase.create(values)

        Create a new TestCase object and store it in the database.

        :param values: Field values for :class:`tcms.testcases.models.TestCase`
        :type values: dict
        :return: Serialized :class:`tcms.testcases.models.TestCase` object
        :rtype: dict
        :raises: PermissionDenied if missing *testcases.add_testcase* permission

        Minimal test case parameters::

            >>> values = {
                'category': 135,
                'product': 61,
            'summary': 'Testing XML-RPC',
            'priority': 1,
            }
            >>> TestCase.create(values)
    """
    request = kwargs.get(REQUEST_KEY)

    if not (values.get('category') or values.get('summary')):
        raise ValueError()

    form = NewCaseForm(values)
    form.populate(values.get('product'))

    if form.is_valid():
        # Create the case
        test_case = TestCase.create(author=request.user,
                                    values=form.cleaned_data)
    else:
        # Print the errors if the form is not passed validation.
        raise ValueError(form_errors_to_list(form))

    result = test_case.serialize()

    return result
Exemple #6
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)