Пример #1
0
def list_all(request):
    """
    Generate the TestCase list for the UI tabs in TestPlan page view.
    """
    # Intial the plan in plan details page
    test_plan = plan_from_request_or_none(request)
    if not test_plan:
        messages.add_message(request,
                             messages.ERROR,
                             _('TestPlan not specified or does not exist'))
        return HttpResponseRedirect(reverse('core-views-index'))

    tcs, search_form = query_testcases_from_request(request, test_plan)
    tcs = sort_queried_testcases(request, tcs)
    total_cases_count = tcs.count()

    # Get the tags own by the cases
    ttags = get_tags_from_cases((case.pk for case in tcs), test_plan)

    tcs = paginate_testcases(request, tcs)

    # There are several extra information related to each TestCase to be shown
    # also. This step must be the very final one, because the calculation of
    # related data requires related TestCases' IDs, that is the queryset of
    # TestCases should be evaluated in advance.
    tcs = calculate_for_testcases(test_plan, tcs)

    # generating a query_url with order options
    #
    # FIXME: query_url is always equivlant to None&asc=True whatever what
    # criterias specified in filter form, or just with default filter
    # conditions during loading TestPlan page.
    query_url = remove_from_request_path(request, 'order_by')
    asc = bool(request.POST.get('asc', None))
    if asc:
        query_url = remove_from_request_path(query_url, 'asc')
    else:
        query_url = '%s&asc=True' % query_url

    selected_case_ids = []
    for test_case in get_selected_testcases(request):
        selected_case_ids.append(test_case.pk)

    context_data = {
        'test_cases': tcs,
        'test_plan': test_plan,
        'search_form': search_form,
        # selected_case_ids is used in template to decide whether or not this TestCase is selected
        'selected_case_ids': selected_case_ids,
        'case_status': TestCaseStatus.objects.all(),
        'priorities': Priority.objects.filter(is_active=True),
        'case_own_tags': ttags,
        'query_url': query_url,

        # Load more is a POST request, so POST parameters are required only.
        # Remember this for loading more cases with the same as criterias.
        'search_criterias': request.body.decode(),
        'total_cases_count': total_cases_count,
    }
    return render(request, 'plan/get_cases.html', context_data)
Пример #2
0
    def _report_context(self):
        errors = None
        report_data = None
        queries = self.request.GET

        if queries:
            form = self._get_form(self.request.GET)

            if form.is_valid():
                queries = form.cleaned_data
                report_data = self.get_report_data(form)
            else:
                errors = form.errors

        queries = fmt_queries(queries)
        del queries['report type']
        request_path = remove_from_request_path(self.request, 'report_type')

        data = {
            'errors': errors,
            'queries': queries,
            'request_path': request_path,
            'run_form': form,
            'report_data': report_data,
        }

        if request_path:
            data['path_without_build'] = remove_from_request_path(request_path,
                                                                  'r_build')

        return data
Пример #3
0
    def _report_context(self):
        errors = None
        report_data = None
        queries = self.request.GET

        if queries:
            form = self._get_form(self.request.GET)

            if form.is_valid():
                queries = form.cleaned_data
                report_data = self.get_report_data(form)
            else:
                errors = form.errors

        queries = fmt_queries(queries)
        del queries['report type']
        request_path = remove_from_request_path(self.request, 'report_type')

        data = {
            'errors': errors,
            'queries': queries,
            'request_path': request_path,
            'run_form': form,
            'report_data': report_data,
        }

        if request_path:
            data['path_without_build'] = remove_from_request_path(request_path,
                                                                  'r_build')

        return data
Пример #4
0
    def _report_context(self):
        errors = None
        report_data = None

        if self.request.GET:
            form = self._get_form(self.request.GET)

            if form.is_valid():
                report_data = self.get_report_data(form)
            else:
                errors = form.errors

        request_path = remove_from_request_path(self.request, 'report_type')

        data = {
            'errors': errors,
            'request_path': request_path,
            'run_form': form,
            'report_data': report_data,
        }

        if request_path:
            data['path_without_build'] = remove_from_request_path(request_path, 'build')

        return data
Пример #5
0
def view_test_run_report(request):
    templates = {
        'per_build_report': 'report/caserun_report_per_build.html',
        'per_tester_report': 'report/caserun_report_per_tester.html',
        'per_priority_report': 'report/caserun_report_per_priority.html',
        'per_plan_tag_report': 'report/testrun_report_per_plan_tag.html',
        'per_plan_build_report': 'report/testrun_report_per_plan_build.html',
        'runs_with_rates_per_plan_tag': 'report/testrun_report_by_plan_tag_with_rates.html',
        'runs_with_rates_per_plan_build': 'report/testrun_report_by_plan_build_with_rates.html',
    }
    errors  = None
    queries = request.GET
    data    = {}
    report_type = queries.get('report_type')
    PRODUCT_CHOICE = [
            (p.pk, p.name) for p in cached_entities('product')
        ]
    if queries:
        run_form = RunForm(queries)
        run_form.populate(queries)
        if run_form.is_valid():
            queries = run_form.cleaned_data
            data = test_run_report(queries, report_type)
        else:
            errors = run_form.errors
    tmpl = templates.get(report_type, 'report/common/search_run.html')
    queries = fmt_queries(queries)
    request_path = remove_from_request_path(request, 'report_type')
    if request_path:
        path_without_build = remove_from_request_path(request_path, 'r_build')
    data.update(locals())
    return direct_to_template(request, tmpl, data)
Пример #6
0
def _render_results(request, results, time_cost, queries):
    """Using a SQL "in" query and PKs as the arguments"""
    klasses = {
        'plan': {
            'class': TestPlan,
            'result_key': 'test_plans'
        },
        'case': {
            'class': TestCase,
            'result_key': 'test_cases'
        },
        'run': {
            'class': TestRun,
            'result_key': 'test_runs'
        }
    }
    asc = bool(request.GET.get('asc', None))
    query_url = remove_from_request_path(request, 'order_by')
    if asc:
        query_url = remove_from_request_path(query_url, 'asc')
    else:
        query_url = '%s&asc=True' % query_url
    context_data = {
        klasses[request.GET['target']]['result_key']: results,
        'time_cost': time_cost,
        'queries': queries,
        'query_url': query_url,
    }
    return render(request, 'search/results.html', context_data)
Пример #7
0
def get_all(request):  # pylint: disable=missing-permission-required
    """Display all testplans"""
    # TODO: this function should be deleted
    # todo: this function can be replaced with the existing JSON-RPC search
    # TODO: this function now only performs a forward feature, no queries
    # need here. All of it will be removed in the future.
    # If it's not a search the page will be blank
    tps = TestPlan.objects.none()
    query_result = False
    order_by = request.GET.get('order_by', 'create_date')
    asc = bool(request.GET.get('asc', None))
    # if it's a search request the page will be fill
    if request.GET:
        search_form = SearchPlanForm(request.GET)
        search_form.populate(product_id=request.GET.get('product'))

        if search_form.is_valid():
            query_result = True
            # build a QuerySet:
            tps = TestPlan.list(search_form.cleaned_data)
            tps = tps.select_related('author', 'type', 'product')
            tps = order_plan_queryset(tps, order_by, asc)
    else:
        # Set search active plans only by default
        search_form = SearchPlanForm(initial={'is_active': True})

    template_name = 'non-existing.html'

    # used in tree preview only
    # fixme: must be replaced by JSON RPC and the
    # JavaScript dialog that displays the preview
    # should be converted to Patternfly
    # todo: when this is done SearchPlanForm must contain only the
    # fields which are used in search.html
    if request.GET.get('t') == 'html':
        if request.GET.get('f') == 'preview':
            template_name = 'plan/preview.html'

    query_url = remove_from_request_path(request, 'order_by')
    if asc:
        query_url = remove_from_request_path(query_url, 'asc')
    else:
        query_url = '%s&asc=True' % query_url
    page_type = request.GET.get('page_type', 'pagination')
    query_url_page_type = remove_from_request_path(request, 'page_type')
    if query_url_page_type:
        query_url_page_type = remove_from_request_path(query_url_page_type,
                                                       'page')

    context_data = {
        'test_plans': tps,
        'query_result': query_result,
        'search_plan_form': search_form,
        'query_url': query_url,
        'query_url_page_type': query_url_page_type,
        'page_type': page_type
    }
    return render(request, template_name, context_data)
Пример #8
0
def all(request, template_name = 'run/all.html'):
    """Read the test runs from database and display them."""
    SUB_MODULE_NAME = "runs"

    if request.REQUEST.get('manager'):
        if request.user.is_authenticated() and (
            request.REQUEST.get('people') == request.user.username
            or request.REQUEST.get('people') == request.user.email
        ):
            SUB_MODULE_NAME = "my_runs"

    # Initial the values will be use if it's not a search
    query_result = False
    trs = None
    order_by = request.REQUEST.get('order_by', 'create_date')
    asc = bool(request.REQUEST.get('asc', None))
    # If it's a search
    if request.REQUEST.items():
        search_form = SearchRunForm(request.REQUEST)

        if request.REQUEST.get('product'):
            search_form.populate(product_id=request.REQUEST['product'])
        else:
            search_form.populate()

        if search_form.is_valid():
            # It's a search here.
            query_result = True
            trs = TestRun.list(search_form.cleaned_data)
            trs = trs.select_related('manager',
                                     'default_tester',
                                     'build', 'plan',
                                     'build__product__name',)

            # Further optimize by adding caserun attributes:
            trs = trs.extra(
                    select={'env_groups': RawSQL.environment_group_for_run,},
            )
            trs = order_run_queryset(trs, order_by, asc)
    else:
        search_form = SearchRunForm()
        # search_form.populate()
    # generating a query_url with order options
    query_url = remove_from_request_path(request, 'order_by')
    if asc:
        query_url = remove_from_request_path(query_url, 'asc')
    else:
        query_url = '%s&asc=True' % query_url

    return direct_to_template(request, template_name, {
        'module': MODULE_NAME,
        'sub_module': SUB_MODULE_NAME,
        'test_runs': trs,
        'query_result': query_result,
        'search_form': search_form,
        'query_url': query_url,
    })
Пример #9
0
def view_test_run_report(request):
    templates = {
        'per_build_report':
        'report/caserun_report_per_build.html',
        'per_tester_report':
        'report/caserun_report_per_tester.html',
        'per_priority_report':
        'report/caserun_report_per_priority.html',
        'per_plan_tag_report':
        'report/testrun_report_per_plan_tag.html',
        'per_plan_build_report':
        'report/testrun_report_per_plan_build.html',
        'runs_with_rates_per_plan_tag':
        'report/testrun_report_by_plan_tag_with_rates.html',
        'runs_with_rates_per_plan_build':
        'report/testrun_report_by_plan_build_with_rates.html',
    }
    errors = None
    queries = request.GET
    data = {}
    report_type = queries.get('report_type')
    PRODUCT_CHOICE = [(p.pk, p.name) for p in cached_entities('product')]
    if queries:
        run_form = RunForm(queries)
        run_form.populate(queries)
        if run_form.is_valid():
            queries = run_form.cleaned_data
            data = test_run_report(queries, report_type)
        else:
            errors = run_form.errors
    tmpl = templates.get(report_type, 'report/common/search_run.html')
    queries = fmt_queries(queries)
    request_path = remove_from_request_path(request, 'report_type')
    if request_path:
        path_without_build = remove_from_request_path(request_path, 'r_build')
    data.update(locals())
    return render_to_response(tmpl,
                              data,
                              context_instance=RequestContext(request))
Пример #10
0
def all(request, template_name='plan/all.html'):
    '''Display all testplans'''
    # TODO: this function now only performs a forward feature, no queries
    # need here. All of it will be removed in the future.
    # If it's not a search the page will be blank
    tps = TestPlan.objects.none()
    query_result = False
    order_by = request.GET.get('order_by', 'create_date')
    asc = bool(request.GET.get('asc', None))
    # if it's a search request the page will be fill
    if request.GET:
        search_form = SearchPlanForm(request.GET)
        if request.GET.get('product'):
            search_form.populate(product_id=request.GET['product'])
        else:
            search_form.populate()

        if search_form.is_valid():
            query_result = True
            # build a QuerySet:
            tps = TestPlan.list(search_form.cleaned_data)
            tps = tps.select_related('author', 'type', 'product')

            # We want to get the number of cases and runs, without doing
            # lots of per-test queries.
            #
            # Ideally we would get the case/run counts using m2m field tricks
            # in the ORM
            # Unfortunately, Django's select_related only works on ForeignKey
            # relationships, not on ManyToManyField attributes
            # See http://code.djangoproject.com/ticket/6432

            # SQLAlchemy can handle this kind of thing in several ways.
            # Unfortunately we're using Django

            # The cleanest way I can find to get it into one query is to
            # use QuerySet.extra()
            # See http://docs.djangoproject.com/en/dev/ref/models/querysets
            tps = tps.extra(select={
                'num_cases': RawSQL.num_cases,
                'num_runs': RawSQL.num_runs,
                'num_children': RawSQL.num_plans,
            })
            tps = order_plan_queryset(tps, order_by, asc)
    else:
        # Set search active plans only by default
        search_form = SearchPlanForm(initial={'is_active': True})

    if request.GET.get('action') == 'clone_case':
        template_name = 'case/clone_select_plan.html'
        tps = tps.order_by('name')

    if request.GET.get('t') == 'ajax':
        results = []
        for obj in tps:
            dict_obj = model_to_dict(obj, fields=('name', 'parent', 'is_active'))

            for attr in ['pk', 'num_cases', 'num_cases', 'num_runs', 'num_children']:
                dict_obj[attr] = getattr(obj, attr)
            dict_obj['get_url_path'] = obj.get_url_path()

            results.append(dict_obj)
        return JsonResponse(results, safe=False)

    if request.GET.get('t') == 'html':
        if request.GET.get('f') == 'preview':
            template_name = 'plan/preview.html'

    query_url = remove_from_request_path(request, 'order_by')
    if asc:
        query_url = remove_from_request_path(query_url, 'asc')
    else:
        query_url = '%s&asc=True' % query_url
    page_type = request.GET.get('page_type', 'pagination')
    query_url_page_type = remove_from_request_path(request, 'page_type')
    if query_url_page_type:
        query_url_page_type = remove_from_request_path(query_url_page_type, 'page')

    context_data = {
        'test_plans': tps,
        'query_result': query_result,
        'search_plan_form': search_form,
        'query_url': query_url,
        'query_url_page_type': query_url_page_type,
        'page_type': page_type
    }
    return render(request, template_name, context_data)
Пример #11
0
def get_all(request):
    """Display all testplans"""
    # TODO: this function now only performs a forward feature, no queries
    # need here. All of it will be removed in the future.
    # If it's not a search the page will be blank
    tps = TestPlan.objects.none()
    query_result = False
    order_by = request.GET.get('order_by', 'create_date')
    asc = bool(request.GET.get('asc', None))
    # if it's a search request the page will be fill
    if request.GET:
        search_form = SearchPlanForm(request.GET)
        search_form.populate(product_id=request.GET.get('product'))

        if search_form.is_valid():
            query_result = True
            # build a QuerySet:
            tps = TestPlan.list(search_form.cleaned_data)
            tps = tps.select_related('author', 'type', 'product')
            tps = order_plan_queryset(tps, order_by, asc)
    else:
        # Set search active plans only by default
        search_form = SearchPlanForm(initial={'is_active': True})

    if request.GET.get('action') == 'clone_case':
        template_name = 'case/clone_select_plan.html'
        tps = tps.order_by('name')

    # test plan TreeView
    if request.GET.get('t') == 'ajax':
        results = []
        for obj in tps:
            dict_obj = model_to_dict(obj,
                                     fields=('name', 'parent', 'is_active'))

            for attr in ['pk']:
                dict_obj[attr] = getattr(obj, attr)
            dict_obj['plan_url'] = reverse('test_plan_url_short',
                                           args=[obj.pk])

            results.append(dict_obj)
        return JsonResponse(results, safe=False)

    # used in tree preview
    if request.GET.get('t') == 'html':
        if request.GET.get('f') == 'preview':
            template_name = 'plan/preview.html'

    query_url = remove_from_request_path(request, 'order_by')
    if asc:
        query_url = remove_from_request_path(query_url, 'asc')
    else:
        query_url = '%s&asc=True' % query_url
    page_type = request.GET.get('page_type', 'pagination')
    query_url_page_type = remove_from_request_path(request, 'page_type')
    if query_url_page_type:
        query_url_page_type = remove_from_request_path(query_url_page_type,
                                                       'page')

    context_data = {
        'test_plans': tps,
        'query_result': query_result,
        'search_plan_form': search_form,
        'query_url': query_url,
        'query_url_page_type': query_url_page_type,
        'page_type': page_type
    }
    return render(request, template_name, context_data)
Пример #12
0
def all(request, template_name='plan/all.html'):
    '''Display all testplans'''
    # Define the default sub module
    SUB_MODULE_NAME = 'plans'
    # TODO: this function now only performs a forward feature, no queries
    # need here. All of it will be removed in the future.
    # If it's not a search the page will be blank
    tps = TestPlan.objects.none()
    query_result = False
    order_by = request.GET.get('order_by', 'create_date')
    asc = bool(request.GET.get('asc', None))
    # if it's a search request the page will be fill
    if request.GET.items():
        search_form = SearchPlanForm(request.GET)
        if request.GET.get('product'):
            search_form.populate(product_id=request.GET['product'])
        else:
            search_form.populate()

        if search_form.is_valid():
            # Detemine the query is the user's plans and change the sub
            # module value
            author = request.GET.get('author')
            if author and request.user.is_authenticated():
                if author == request.user.username or author == request.user.email:
                    SUB_MODULE_NAME = "my_plans"

            query_result = True
            # build a QuerySet:
            tps = TestPlan.list(search_form.cleaned_data)
            tps = tps.select_related('author', 'type', 'product')

            # We want to get the number of cases and runs, without doing
            # lots of per-test queries.
            #
            # Ideally we would get the case/run counts using m2m field tricks
            # in the ORM
            # Unfortunately, Django's select_related only works on ForeignKey
            # relationships, not on ManyToManyField attributes
            # See http://code.djangoproject.com/ticket/6432

            # SQLAlchemy can handle this kind of thing in several ways.
            # Unfortunately we're using Django

            # The cleanest way I can find to get it into one query is to
            # use QuerySet.extra()
            # See http://docs.djangoproject.com/en/dev/ref/models/querysets
            tps = tps.extra(select={
                'num_cases': RawSQL.num_cases,
                'num_runs': RawSQL.num_runs,
                'num_children': RawSQL.num_plans,
            })
            tps = order_plan_queryset(tps, order_by, asc)
    else:
        # Set search active plans only by default
        # I wish to use 'default' argument, as the same as in ModelForm
        # But it does not seem to work
        search_form = SearchPlanForm(initial={'is_active': True})

    if request.GET.get('action') == 'clone_case':
        template_name = 'case/clone_select_plan.html'
        tps = tps.order_by('name')

    if request.GET.get('t') == 'ajax':
        return HttpResponse(serializers.serialize(
            request.GET.get('f', 'json'),
            tps,
            extras=('num_cases', 'num_runs', 'num_children', 'get_url_path')
        ))

    if request.GET.get('t') == 'html':
        if request.GET.get('f') == 'preview':
            template_name = 'plan/preview.html'

    query_url = remove_from_request_path(request, 'order_by')
    if asc:
        query_url = remove_from_request_path(query_url, 'asc')
    else:
        query_url = '%s&asc=True' % query_url
    page_type = request.GET.get('page_type', 'pagination')
    query_url_page_type = remove_from_request_path(request, 'page_type')
    if query_url_page_type:
        query_url_page_type = remove_from_request_path(query_url_page_type, 'page')

    context_data = {
        'module': MODULE_NAME,
        'sub_module': SUB_MODULE_NAME,
        'test_plans': tps,
        'query_result': query_result,
        'search_plan_form': search_form,
        'query_url': query_url,
        'query_url_page_type': query_url_page_type,
        'page_type': page_type
    }
    return render_to_response(template_name, context_data,
                              context_instance=RequestContext(request))