Пример #1
0
    def test_to_xmlrpc(self):
        testrun1 = TestRun.objects.get(pk=self.testrun_pks[0])

        result = TestRun.to_xmlrpc(query={'pk__in': self.testrun_pks})
        self.assertEqual(len(result), 2)

        # Verify fields
        sample_testrun = result[0]
        sample_fields = set([name for name in sample_testrun.keys()])
        test_fields = set(self.test_fields)
        test_result = list(sample_fields ^ test_fields)
        self.assertEqual(test_result, [])

        result = dict([(item['run_id'], item) for item in result])

        sample_testrun1 = result[self.testrun_pks[0]]

        self.assertEqual(testrun1.errata_id, sample_testrun1['errata_id'])
        self.assertEqual(testrun1.product_version.pk,
                         sample_testrun1['product_version_id'])
        self.assertEqual(testrun1.product_version.value,
                         sample_testrun1['product_version'])
        self.assertEqual(testrun1.default_tester.pk,
                         sample_testrun1['default_tester_id'])
        self.assertEqual(testrun1.default_tester.username,
                         sample_testrun1['default_tester'])

        tags = [tag.pk for tag in testrun1.tag.all()]
        tags.sort()
        sample_tags = sample_testrun1['tag']
        sample_tags.sort()
        self.assertEqual(tags, sample_tags)
Пример #2
0
def dashboard(request):
    """List the recent plan/run"""
    runs_query = {
        'people': request.user,
        'is_active': True,
        'status': 'running',
    }

    tps = TestPlan.objects.filter(
        Q(author=request.user) | Q(owner=request.user))
    tps = tps.order_by('-plan_id')
    tps = tps.select_related('product', 'type')
    tps = tps.extra(select={
        'num_runs': RawSQL.num_runs,
    })
    tps_active = tps.filter(is_active=True)
    trs = TestRun.list(runs_query)
    latest_fifteen_testruns = trs.order_by('-run_id')[:15]
    test_plans_disable_count = tps.count() - tps_active.count()

    context_data = {
        'user_profile': {
            'user': request.user
        },
        'test_plans_count': tps.count(),
        'test_plans_disable_count': test_plans_disable_count,
        'test_runs_count': trs.count(),
        'last_15_test_plans': tps_active[:15],
        'last_15_test_runs': latest_fifteen_testruns,
    }
    return render(request, 'profile/dashboard.html', context_data)
Пример #3
0
    def generate_status_matrix(self, build_ids):
        matrix_dataset = {}
        # TODO: replace defaultdict with GroupByResult
        status_total_line = defaultdict(int)

        rows = SQLExecution(sqls.custom_details_status_matrix,
                            params=(build_ids,),
                            with_field_name=False).rows

        for row in rows:
            plan_id, plan_name, run_id, run_summary, \
                status_name, status_count = row
            plan = TestPlan(pk=plan_id, name=plan_name)
            plan_node = matrix_dataset.setdefault(plan, {})

            run = TestRun(pk=run_id, summary=run_summary)
            run_node = plan_node.setdefault(run, defaultdict(int))

            run_node[status_name] = status_count
            run_node['TOTAL'] += status_count

            # calculate the last total line
            status_total_line[status_name] += status_count
            status_total_line['TOTAL'] += status_count

        # Add total line to final data set
        matrix_dataset[None] = status_total_line
        return matrix_dataset
Пример #4
0
def filter(request, values={}):
    """Performs a search and returns the resulting list of test runs.

    :param dict values: a mapping containing these criteria.

        * build: ForeignKey: TestBuild
        * cc: ForeignKey: Auth.User
        * env_value: ForeignKey: Environment Value
        * default_tester: ForeignKey: Auth.User
        * run_id: (int)
        * manager: ForeignKey: Auth.User
        * notes: (str)
        * plan: ForeignKey: TestPlan
        * summary: (str)
        * tag: ForeignKey: Tag
        * product_version: ForeignKey: Version

    :return: list of mappings of found :class:`TestRun`.
    :rtype: list

    Example::

        # Get all of runs contain 'TCMS' in summary
        >>> TestRun.filter({'summary__icontain': 'TCMS'})
        # Get all of runs managed by xkuang
        >>> TestRun.filter({'manager__username': '******'})
        # Get all of runs the manager name starts with x
        >>> TestRun.filter({'manager__username__startswith': 'x'})
        # Get runs contain the case ID 1, 2, 3
        >>> TestRun.filter({'case_run__case__case_id__in': [1, 2, 3]})
    """
    return TestRun.to_xmlrpc(values)
Пример #5
0
def recent(request, username, template_name='profile/recent.html'):
    """List the recent plan/run"""

    if username != request.user.username:
        return http.HttpResponseRedirect(reverse('nitrate-login'))
    else:
        up = {'user': request.user}

    runs_query = {
        'people': request.user,
        'is_active': True,
        'status': 'running',
    }

    tps = TestPlan.objects.filter(Q(author=request.user) | Q(owner=request.user))
    tps = tps.order_by('-plan_id')
    tps = tps.select_related('product', 'type')
    tps = tps.extra(select={
        'num_runs': RawSQL.num_runs,
    })
    tps_active = tps.filter(is_active=True)
    trs = TestRun.list(runs_query)
    latest_fifteen_testruns = trs.order_by('-run_id')[:15]
    test_plans_disable_count = tps.count() - tps_active.count()

    context_data = {
        'module': MODULE_NAME,
        'user_profile': up,
        'test_plans_count': tps.count(),
        'test_plans_disable_count': test_plans_disable_count,
        'test_runs_count': trs.count(),
        'last_15_test_plans': tps_active[:15],
        'last_15_test_runs': latest_fifteen_testruns,
    }
    return render(request, template_name, context=context_data)
Пример #6
0
def ajax_search(request, template_name='run/common/json_runs.txt'):
    """Response request to search test runs from Search Runs"""
    search_form = SearchRunForm(request.GET)
    if request.GET.get('product'):
        search_form.populate(product_id=request.GET['product'])
    else:
        search_form.populate()

    if search_form.is_valid():
        trs = TestRun.list(search_form.cleaned_data)
        trs = trs.select_related(
            'manager', 'default_tester', 'plan',
            'build').only('run_id', 'summary', 'manager__username',
                          'default_tester__id', 'default_tester__username',
                          'plan__name', 'env_value', 'build__product__name',
                          'stop_date', 'product_version__value')

        # Further optimize by adding caserun attributes:
        column_names = [
            '',
            'run_id',
            'summary',
            'manager__username',
            'default_tester__username',
            'plan',
            'build__product__name',
            'product_version',
            'total_num_caseruns',
            'stop_date',
            'completed',
        ]

        data_table_result = DataTableResult(request.GET, trs, column_names)
        response_data = data_table_result.get_response_data()
        searched_runs = response_data['querySet']

        # Get associated statistics data
        run_ids = [run.pk for run in searched_runs]
        qs = TestCaseRun.objects.filter(
            run__in=run_ids).values('run').annotate(cases_count=Count('case'))
        cases_subtotal = magic_convert(qs,
                                       key_name='run',
                                       value_name='cases_count')

        for run in searched_runs:
            run_id = run.pk
            cases_count = cases_subtotal.get(run_id, 0)
            run.nitrate_stats = {
                'cases': cases_count,
            }
    else:
        response_data = {
            'sEcho': int(request.GET.get('sEcho', 0)),
            'iTotalRecords': 0,
            'iTotalDisplayRecords': 0,
            'runs': TestRun.objects.none(),
        }

    json_data = render_to_string(template_name, response_data, request=request)
    return HttpResponse(json_data, content_type='application/json')
Пример #7
0
def filter(request, values={}):
    """Performs a search and returns the resulting list of test runs.

    :param dict values: a mapping containing these criteria.

        * build: ForeignKey: TestBuild
        * cc: ForeignKey: Auth.User
        * env_value: ForeignKey: Environment Value
        * default_tester: ForeignKey: Auth.User
        * run_id: (int)
        * manager: ForeignKey: Auth.User
        * notes: (str)
        * plan: ForeignKey: TestPlan
        * summary: (str)
        * tag: ForeignKey: Tag
        * product_version: ForeignKey: Version

    :return: list of mappings of found :class:`TestRun`.
    :rtype: list

    Example::

        # Get all of runs contain 'TCMS' in summary
        TestRun.filter({'summary__icontain': 'TCMS'})
        # Get all of runs managed by xkuang
        TestRun.filter({'manager__username': '******'})
        # Get all of runs the manager name starts with x
        TestRun.filter({'manager__username__startswith': 'x'})
        # Get runs contain the case ID 1, 2, 3
        TestRun.filter({'case_run__case__case_id__in': [1, 2, 3]})
    """
    return TestRun.to_xmlrpc(values)
Пример #8
0
    def generate_status_matrix(build_ids):
        matrix_dataset = {}
        # TODO: replace defaultdict with GroupByResult
        status_total_line = defaultdict(int)

        rows = TestCaseRun.objects.filter(build__in=build_ids).values(
            'run__plan', 'run__plan__name', 'run', 'run__summary',
            'case_run_status__name').annotate(
                total_count=Count('pk')).order_by('run__plan', 'run')

        for row in rows:
            plan_id = row['run__plan']
            plan_name = row['run__plan__name']
            run_id = row['run']
            run_summary = row['run__summary']
            status_name = row['case_run_status__name']
            status_count = row['total_count']

            plan = TestPlan(pk=plan_id, name=plan_name)
            plan_node = matrix_dataset.setdefault(plan, {})

            run = TestRun(pk=run_id, summary=run_summary)
            run_node = plan_node.setdefault(run, defaultdict(int))

            run_node[status_name] = status_count
            run_node['TOTAL'] += status_count

            # calculate the last total line
            status_total_line[status_name] += status_count
            status_total_line['TOTAL'] += status_count

        # Add total line to final data set
        matrix_dataset[None] = status_total_line
        return matrix_dataset
Пример #9
0
Файл: views.py Проект: xbln/Kiwi
def recent(request, username, template_name='profile/recent.html'):
    """List the recent plan/run"""

    if username != request.user.username:
        return http.HttpResponseRedirect(reverse('tcms-login'))
    else:
        up = {'user': request.user}

    runs_query = {
        'people': request.user,
        'is_active': True,
        'status': 'running',
    }

    tps = TestPlan.objects.filter(Q(author=request.user) | Q(owner=request.user))
    tps = tps.order_by('-plan_id')
    tps = tps.select_related('product', 'type')
    tps = tps.extra(select={
        'num_runs': RawSQL.num_runs,
    })
    tps_active = tps.filter(is_active=True)
    trs = TestRun.list(runs_query)
    latest_fifteen_testruns = trs.order_by('-run_id')[:15]
    test_plans_disable_count = tps.count() - tps_active.count()

    context_data = {
        'user_profile': up,
        'test_plans_count': tps.count(),
        'test_plans_disable_count': test_plans_disable_count,
        'test_runs_count': trs.count(),
        'last_15_test_plans': tps_active[:15],
        'last_15_test_runs': latest_fifteen_testruns,
    }
    return render(request, template_name, context_data)
Пример #10
0
    def status_matrix(self, form):
        status_matrix = GroupByResult()
        query = self._filter_query(
            form,
            TestCaseRun.objects.values(
                'build', 'build__name', 'run__plan__tag', 'run__plan',
                'run__plan__name', 'run', 'run__summary',
                'case_run_status__name').annotate(total_count=Count('pk')))

        for row in query:
            tag_id = row['run__plan__tag']
            build_id = row['build']
            build_name = row['build__name']
            plan_id = row['run__plan']
            plan_name = row['run__plan__name']
            run_id = row['run']
            run_summary = row['run__summary']
            status_name = row['case_run_status__name']
            total_count = row['total_count']

            builds = status_matrix.setdefault(tag_id, GroupByResult())
            plans = builds.setdefault(Build(pk=build_id, name=build_name),
                                      GroupByResult())
            runs = plans.setdefault(TestPlan(pk=plan_id, name=plan_name),
                                    GroupByResult())
            status_subtotal = runs.setdefault(
                TestRun(pk=run_id, summary=run_summary), GroupByResult())
            status_subtotal[status_name] = total_count

        return status_matrix
Пример #11
0
def filter(query={}):  # pylint: disable=invalid-name
    """
    .. function:: XML-RPC TestRun.filter(query)

        Perform a search and return the resulting list of test runs.

        :param query: Field lookups for :class:`tcms.testruns.models.TestRun`
        :type query: dict
        :return: List of serialized :class:`tcms.testruns.models.TestRun` objects
        :rtype: list(dict)
    """
    return TestRun.to_xmlrpc(query)
Пример #12
0
def search_runs(request):
    """Search test runs"""
    search_form = SearchRunForm(request.GET)
    product_id = request.GET.get('product')
    search_form.populate(product_id=int(product_id) if product_id else None)

    runs = TestRun.objects.none()

    if search_form.is_valid():
        runs = (TestRun.list(search_form.cleaned_data).select_related(
            'manager', 'default_tester',
            'build', 'plan', 'build__product').only(
                'run_id', 'summary', 'manager__username', 'default_tester__id',
                'default_tester__username', 'plan__name',
                'build__product__name', 'stop_date',
                'product_version__value').extra(
                    select={'cases_count': RawSQL.total_num_caseruns}))

    column_names = [
        '',
        'run_id',
        'summary',
        'manager__username',
        'default_tester__username',
        'build__product__name',
        'product_version__value',
        'env_groups',
        'cases_count',
        'stop_date',
        'completed',
    ]

    dt = DataTableResult(request.GET,
                         runs,
                         column_names,
                         default_order_key='-pk')
    response_data = dt.get_response_data()
    calculate_associated_data(response_data['querySet'])

    if 'sEcho' in request.GET:
        resp_data = (get_template('run/common/json_runs.txt').render(
            response_data, request))
        return JsonResponse(json.loads(resp_data))
    else:
        return render(request,
                      'run/all.html',
                      context={
                          'module': MODULE_NAME,
                          'sub_module': 'runs',
                          'object_list': response_data['querySet'],
                          'search_form': search_form,
                          'total_count': runs.count()
                      })
Пример #13
0
def get_test_runs(plan_id):
    """
    Description: Get the list of runs in this plan.

    Params:      $plan_id - Integer: An integer representing the ID of this plan in the database

    Returns:     Array: An array of test run object hashes.

    Example:
    >>> TestPlan.get_test_runs(plan_id)
    """
    from tcms.testruns.models import TestRun

    query = {'plan': plan_id}
    return TestRun.to_xmlrpc(query)
Пример #14
0
def get_test_runs(request, plan_id):
    """Get the list of runs in this plan.

    :param int plan_id: plan ID.
    :return: list of mappings of found :class:`TestRun`.
    :rtype: list[dict]

    Example::

        >>> TestPlan.get_test_runs(1)
    """
    from tcms.testruns.models import TestRun

    query = {'plan': plan_id}
    return TestRun.to_xmlrpc(query)
Пример #15
0
def get_test_runs(request, plan_id):
    """Get the list of runs in this plan.

    :param int plan_id: plan ID.
    :return: list of mappings of found :class:`TestRun`.
    :rtype: list[dict]

    Example::

        TestPlan.get_test_runs(1)
    """
    from tcms.testruns.models import TestRun

    query = {'plan': plan_id}
    return TestRun.to_xmlrpc(query)
Пример #16
0
def get_test_runs(request, plan_id):
    """
    Description: Get the list of runs in this plan.

    Params:      $plan_id - Integer: An integer representing the ID of this plan in the database

    Returns:     Array: An array of test run object hashes.

    Example:
    >>> TestPlan.get_test_runs(plan_id)
    """
    from tcms.testruns.models import TestRun

    query = {'plan': plan_id}
    return TestRun.to_xmlrpc(query)
Пример #17
0
def recent(request, username):
    """List the recent plan/run"""

    if username != request.user.username:
        return http.HttpResponseRedirect(reverse('nitrate-login'))

    plans_subtotal = {
        item['is_active']: item['count']
        for item in TestPlan.objects.values('is_active').annotate(
            count=Count('pk'))
    }
    plans_count = sum(plans_subtotal.values())
    disabled_plans_count = plans_subtotal.get(False, 0)

    plans = (TestPlan.objects.filter(
        Q(author=request.user) | Q(owner=request.user),
        is_active=True).select_related('product',
                                       'type').order_by('-plan_id').only(
                                           'name', 'is_active', 'type__name',
                                           'product__name'))

    plans = TestPlan.apply_subtotal(plans, runs_count=True)

    runs = (TestRun.list({
        'people': request.user,
        'is_active': True,
        'status': 'running'
    }).only('summary', 'start_date').order_by('-run_id'))

    first_15_runs = runs[:15]

    subtotal = stats_case_runs_status([item.pk for item in first_15_runs])
    for run in first_15_runs:
        run.case_runs_subtotal = subtotal[run.pk]

    return render(request,
                  'profile/recent.html',
                  context={
                      'module': MODULE_NAME,
                      'user_profile': {
                          'user': request.user
                      },
                      'test_plans_count': plans_count,
                      'test_plans_disable_count': disabled_plans_count,
                      'test_runs_count': runs.count(),
                      'last_15_test_plans': plans[:15],
                      'last_15_test_runs': first_15_runs,
                  })
Пример #18
0
def filter(query=None):  # pylint: disable=redefined-builtin
    """
    .. function:: RPC TestRun.filter(query)

        Perform a search and return the resulting list of test runs.

        :param query: Field lookups for :class:`tcms.testruns.models.TestRun`
        :type query: dict
        :return: List of serialized :class:`tcms.testruns.models.TestRun` objects
        :rtype: list(dict)
    """

    if query is None:
        query = {}

    return TestRun.to_xmlrpc(query)
Пример #19
0
def get_runs(request, build_id):
    """
    Description: Returns the list of runs that this Build is used in.

    Params:      $id -  Integer: Build ID.

    Returns:     Array: List of run object hashes.

    Example:
    >>> Build.get_runs(1234)
    """
    from tcms.testruns.models import TestRun

    tb = TestBuild.objects.get(build_id=build_id)
    query = {"build": tb}

    return TestRun.to_xmlrpc(query)
Пример #20
0
def get_runs(request, build_id):
    """Returns the list of runs that this Build is used in.

    :param int build_id: build ID.
    :return: list of test runs.
    :rtype: list

    Example::

        >>> Build.get_runs(1234)
    """
    from tcms.testruns.models import TestRun

    tb = TestBuild.objects.get(build_id=build_id)
    query = {'build': tb}

    return TestRun.to_xmlrpc(query)
Пример #21
0
def get_runs(request, build_id):
    """
    Description: Returns the list of runs that this Build is used in.

    Params:      $id -  Integer: Build ID.

    Returns:     Array: List of run object hashes.

    Example:
    >>> Build.get_runs(1234)
    """
    from tcms.testruns.models import TestRun

    tb = TestBuild.objects.get(build_id=build_id)
    query = {'build': tb}

    return TestRun.to_xmlrpc(query)
Пример #22
0
def get_runs(request, build_id):
    """Returns the list of runs that this Build is used in.

    :param int build_id: build ID.
    :return: list of test runs.
    :rtype: list

    Example::

        >>> Build.get_runs(1234)
    """
    from tcms.testruns.models import TestRun

    tb = TestBuild.objects.get(build_id=build_id)
    query = {'build': tb}

    return TestRun.to_xmlrpc(query)
Пример #23
0
def get_runs(build_id):
    """
    .. function:: XML-RPC Build.get_runs(build_id)

        Returns the list of TestRuns that this Build is used in.

        :param build_id: the object ID
        :type build_id: int
        :return: List of serialized :class:`tcms.testruns.models.TestRun` objects
        :rtype: list(dict)
        :raises: TestBuild.DoesNotExist if build not found
    """
    from tcms.testruns.models import TestRun

    tb = TestBuild.objects.get(build_id=build_id)
    query = {'build': tb}

    return TestRun.to_xmlrpc(query)
Пример #24
0
def get_runs(request, product):
    """Get the list of runs associated with this product.

    :params product: product ID or name.
    :type product: int or str
    :return: a list of mappings of test runs.
    :rtype: list

    Example::

        # Get with product id
        >>> Product.get_runs(1)
        # Get with product name
        >>> Product.get_runs('product name')
    """
    from tcms.testruns.models import TestRun

    p = pre_check_product(values=product)
    query = {'build__product': p}
    return TestRun.to_xmlrpc(query)
Пример #25
0
def get_runs(request, product):
    """Get the list of runs associated with this product.

    :params product: product ID or name.
    :type product: int or str
    :return: a list of mappings of test runs.
    :rtype: list

    Example::

        # Get with product id
        >>> Product.get_runs(1)
        # Get with product name
        >>> Product.get_runs('product name')
    """
    from tcms.testruns.models import TestRun

    p = pre_check_product(values=product)
    query = {'build__product': p}
    return TestRun.to_xmlrpc(query)
Пример #26
0
def get_runs(request, product):
    """
    Description: Get the list of runs associated with this product.

    Params:      $product - Integer/String
                            Integer: product_id of the product in the Database
                            String: Product name

    Returns:     Array: Returns an array of Test Run objects.

    Example:
    # Get with product id
    >>> Product.get_runs(61)
    # Get with product name
    >>> Product.get_runs('Red Hat Enterprise Linux 5')
    """
    from tcms.testruns.models import TestRun

    p = pre_check_product(values=product)
    query = {'build__product': p}
    return TestRun.to_xmlrpc(query)
Пример #27
0
    def status_matrix(self, form):
        query = self._filter_query(
            form,
            TestCaseRun.objects.values(
                'run__plan', 'run__plan__name', 'build', 'build__name', 'run',
                'run__summary',
                'case_run_status__name').annotate(total_count=Count('pk')))
        status_matrix = GroupByResult()

        for row in query:
            plan = TestPlan(pk=row['run__plan'], name=row['run__plan__name'])
            builds = status_matrix.setdefault(plan, GroupByResult())

            build = Build(pk=row['build'], name=row['build__name'])
            runs = builds.setdefault(build, GroupByResult())

            run = TestRun(pk=row['run'], summary=row['run__summary'])
            status_subtotal = runs.setdefault(run, GroupByResult())
            status_subtotal[row['case_run_status__name']] = row['total_count']

        return status_matrix
Пример #28
0
def get_runs(request, product):
    """
    Description: Get the list of runs associated with this product.

    Params:      $product - Integer/String
                            Integer: product_id of the product in the Database
                            String: Product name

    Returns:     Array: Returns an array of Test Run objects.

    Example:
    # Get with product id
    >>> Product.get_runs(61)
    # Get with product name
    >>> Product.get_runs('Red Hat Enterprise Linux 5')
    """
    from tcms.testruns.models import TestRun

    p = pre_check_product(values=product)
    query = {'build__product': p}
    return TestRun.to_xmlrpc(query)
Пример #29
0
    def status_matrix(self, form):
        sql, params = self._prepare_sql(form,
                                        sqls.by_plan_tags_detail_status_matrix)
        rows = SQLExecution(sql, params, with_field_name=False).rows

        status_matrix = GroupByResult()

        for row in rows:
            (tag_id, build_id, build_name, plan_id, plan_name, run_id,
             run_summary, status_name, total_count) = row

            builds = status_matrix.setdefault(tag_id, GroupByResult())
            plans = builds.setdefault(TestBuild(pk=build_id, name=build_name),
                                      GroupByResult())
            runs = plans.setdefault(TestPlan(pk=plan_id, name=plan_name),
                                    GroupByResult())
            status_subtotal = runs.setdefault(
                TestRun(pk=run_id, summary=run_summary), GroupByResult())
            status_subtotal[status_name] = total_count

        return status_matrix
Пример #30
0
    def status_matrix(self, form):
        status_matrix = GroupByResult()
        query = self._filter_query(
            form,
            TestCaseRun.objects.values(
                'build', 'build__name', 'run__plan__tag', 'run__plan',
                'run__plan__name', 'run', 'run__summary',
                'status__name').annotate(total_count=Count('pk')))

        for row in query:
            builds = status_matrix.setdefault(row['run__plan__tag'],
                                              GroupByResult())
            plans = builds.setdefault(
                Build(pk=row['build'], name=row['build__name']),
                GroupByResult())
            runs = plans.setdefault(
                TestPlan(pk=row['run__plan'], name=row['run__plan__name']),
                GroupByResult())
            status_subtotal = runs.setdefault(
                TestRun(pk=row['run'], summary=row['run__summary']),
                GroupByResult())
            status_subtotal[row['status__name']] = row['total_count']

        return status_matrix
Пример #31
0
def filter(request, values={}):
    """
    Description: Performs a search and returns the resulting list of test runs.

    Params:      $values - Hash: keys must match valid search fields.

        +--------------------------------------------------------+
        |                 Run Search Parameters                  |
        +--------------------------------------------------------+
        |        Key          |          Valid Values            |
        | build               | ForeignKey: Build                |
        | cc                  | ForeignKey: Auth.User            |
        | env_value           | ForeignKey: Environment Value    |
        | default_tester      | ForeignKey: Auth.User            |
        | run_id              | Integer                          |
        | manager             | ForeignKey: Auth.User            |
        | notes               | String                           |
        | plan                | ForeignKey: Test Plan            |
        | summary             | String                           |
        | tag                 | ForeignKey: Tag                  |
        | product_version     | ForeignKey: Version              |
        +--------------------------------------------------------+

    Returns:     Array: Matching test runs are retuned in a list of run object hashes.

    Example:
    # Get all of runs contain 'TCMS' in summary
    >>> TestRun.filter({'summary__icontain': 'TCMS'})
    # Get all of runs managed by xkuang
    >>> TestRun.filter({'manager__username': '******'})
    # Get all of runs the manager name starts with x
    >>> TestRun.filter({'manager__username__startswith': 'x'})
    # Get runs contain the case ID 12345, 23456, 34567
    >>> TestRun.filter({'case_run__case__case_id__in': [12345, 23456, 34567]})
    """
    return TestRun.to_xmlrpc(values)
Пример #32
0
def filter(request, values={}):
    """
    Description: Performs a search and returns the resulting list of test runs.

    Params:      $values - Hash: keys must match valid search fields.

        +--------------------------------------------------------+
        |                 Run Search Parameters                  |
        +--------------------------------------------------------+
        |        Key          |          Valid Values            |
        | build               | ForeignKey: Build                |
        | cc                  | ForeignKey: Auth.User            |
        | env_value           | ForeignKey: Environment Value    |
        | default_tester      | ForeignKey: Auth.User            |
        | run_id              | Integer                          |
        | manager             | ForeignKey: Auth.User            |
        | notes               | String                           |
        | plan                | ForeignKey: Test Plan            |
        | summary             | String                           |
        | tag                 | ForeignKey: Tag                  |
        | product_version     | ForeignKey: Version              |
        +--------------------------------------------------------+

    Returns:     Array: Matching test runs are retuned in a list of run object hashes.

    Example:
    # Get all of runs contain 'TCMS' in summary
    >>> TestRun.filter({'summary__icontain': 'TCMS'})
    # Get all of runs managed by xkuang
    >>> TestRun.filter({'manager__username': '******'})
    # Get all of runs the manager name starts with x
    >>> TestRun.filter({'manager__username__startswith': 'x'})
    # Get runs contain the case ID 12345, 23456, 34567
    >>> TestRun.filter({'case_run__case__case_id__in': [12345, 23456, 34567]})
    """
    return TestRun.to_xmlrpc(values)
Пример #33
0
def pbuild(request,
           username,
           product_id,
           template_name='profile/product_builds.html'):
    """List the recent plan/run"""

    if username != request.user.username:
        return http.HttpResponseRedirect(reverse('tcms-login'))
    else:
        up = {'user': request.user}

    runs_query = {
        'people': request.user,
        'is_active': True,
    }
    product_id = int(product_id)

    tps = TestPlan.objects.filter(
        Q(author=request.user) | Q(owner=request.user))
    tps = tps.order_by('-plan_id')
    tps = tps.select_related('product', 'type')
    tps = tps.extra(select={
        'num_runs': RawSQL.num_runs,
    })
    tps_active = tps.filter(is_active=True)
    trs = TestRun.list(runs_query)
    latest_fifteen_testruns = trs.order_by('-run_id')[:15]
    all_test_runs = trs.order_by('-run_id')
    test_plans_disable_count = tps.count() - tps_active.count()
    # My codes
    prod_builds = {
        run.build
        for run in all_test_runs if (run.build.product_id == product_id)
    }
    prod_build_count = len(prod_builds)
    prod = dict()
    prod[1] = 'MESSAGING'
    prod[2] = 'VOICE'
    prod[3] = 'INTERNAL SYSTEM'
    prod[4] = 'PHLO'
    prod[5] = 'DATA'
    prod[6] = 'CONSOLE'
    prod[7] = 'ZENTRUNK'

    product = prod[product_id]

    all_builds = {run.build for run in all_test_runs}
    build_count = len(all_builds)

    context_data = {
        'user_profile': up,
        'test_plans_count': tps.count(),
        'test_plans_disable_count': test_plans_disable_count,
        'test_runs_count': trs.count(),
        'last_15_test_plans': tps_active[:15],
        'last_15_test_runs': latest_fifteen_testruns,
        'all_builds': all_builds,
        'build_count': build_count,
        'prod_build_count': prod_build_count,
        'prod_builds': prod_builds,
        'product_id': product_id,
        'username': username,
        'product': product,
    }

    return render(request, template_name, context_data)
Пример #34
0
def update(request, run_ids, values):
    """Updates the fields of the selected test run.

    :param run_ids: give one or more run IDs. It could be an integer, a
        string containing comma separated IDs, or a list of int each of them is
        a run ID.
    :type run_ids: int, str or list
    :param dict values: a mapping containing these data to update specified
        runs.

        * plan: (int) TestPlan.plan_id
        * product: (int) Product.id
        * build: (int) Build.id
        * errata_id: (int) Errata.id
        * manager: (int) Auth.User.id
        * default_tester: Intege Auth.User.id
        * summary: (str)
        * estimated_time: (TimeDelta) in format ``2h30m30s`` which is recommended or ``HH:MM:SS``.
        * product_version: (int)
        * plan_text_version: (int)
        * notes: (str)
        * status: (int) 0:RUNNING 1:FINISHED

    :return: list of mappings of the updated test runs.
    :rtype: list[dict]

    Example::

        # Update status to finished for run 1 and 2
        >>> TestRun.update([1, 2], {'status': 1})
    """
    from datetime import datetime
    from tcms.core import forms
    from tcms.testruns.forms import XMLRPCUpdateRunForm

    if (values.get('product_version') and not values.get('product')):
        raise ValueError('Field "product" is required by product_version')

    if values.get('estimated_time'):
        values['estimated_time'] = pre_process_estimated_time(
            values.get('estimated_time'))

    form = XMLRPCUpdateRunForm(values)
    if values.get('product_version'):
        form.populate(product_id=values['product'])

    if form.is_valid():
        trs = TestRun.objects.filter(pk__in=pre_process_ids(value=run_ids))
        _values = dict()
        if form.cleaned_data['plan']:
            _values['plan'] = form.cleaned_data['plan']

        if form.cleaned_data['build']:
            _values['build'] = form.cleaned_data['build']

        if form.cleaned_data['errata_id']:
            _values['errata_id'] = form.cleaned_data['errata_id']

        if form.cleaned_data['manager']:
            _values['manager'] = form.cleaned_data['manager']

        if 'default_tester' in values:
            if values.get('default_tester') and \
                    form.cleaned_data['default_tester']:
                _values['default_tester'] = form.cleaned_data['default_tester']
            else:
                _values['default_tester'] = None

        if form.cleaned_data['summary']:
            _values['summary'] = form.cleaned_data['summary']

        if values.get('estimated_time') is not None:
            _values['estimated_time'] = form.cleaned_data['estimated_time']

        if form.cleaned_data['product_version']:
            _values['product_version'] = form.cleaned_data['product_version']

        if 'notes' in values:
            if values['notes'] in (None, ''):
                _values['notes'] = values['notes']
            if form.cleaned_data['notes']:
                _values['notes'] = form.cleaned_data['notes']

        if form.cleaned_data['plan_text_version']:
            _values['plan_text_version'] = form.cleaned_data[
                'plan_text_version']

        if isinstance(form.cleaned_data['status'], int):
            if form.cleaned_data['status']:
                _values['stop_date'] = datetime.now()
            else:
                _values['stop_date'] = None

        trs.update(**_values)
    else:
        raise ValueError(forms.errors_to_list(form))

    query = {'pk__in': trs.values_list('pk', flat=True)}
    return TestRun.to_xmlrpc(query)
Пример #35
0
def update(request, run_ids, values):
    """Updates the fields of the selected test run.

    :param run_ids: give one or more run IDs. It could be an integer, a
        string containing comma separated IDs, or a list of int each of them is
        a run ID.
    :type run_ids: int, str or list
    :param dict values: a mapping containing these data to update specified
        runs.

        * plan: (int) TestPlan.plan_id
        * product: (int) Product.id
        * build: (int) Build.id
        * manager: (int) Auth.User.id
        * default_tester: Intege Auth.User.id
        * summary: (str)
        * estimated_time: (TimeDelta) in format ``2h30m30s`` which is recommended or ``HH:MM:SS``.
        * product_version: (int)
        * plan_text_version: (int)
        * notes: (str)
        * status: (int) 0:RUNNING 1:FINISHED

    :return: list of mappings of the updated test runs.
    :rtype: list[dict]

    .. versionchanged:: 4.5
       Argument ``errata_id`` is removed.

    Example::

        # Update status to finished for run 1 and 2
        TestRun.update([1, 2], {'status': 1})
    """
    from datetime import datetime
    from tcms.core import forms
    from tcms.testruns.forms import XMLRPCUpdateRunForm

    if (values.get('product_version') and not values.get('product')):
        raise ValueError('Field "product" is required by product_version')

    if values.get('estimated_time'):
        values['estimated_time'] = pre_process_estimated_time(
            values.get('estimated_time'))

    form = XMLRPCUpdateRunForm(values)
    if values.get('product_version'):
        form.populate(product_id=values['product'])

    if form.is_valid():
        trs = TestRun.objects.filter(pk__in=pre_process_ids(value=run_ids))
        _values = dict()
        if form.cleaned_data['plan']:
            _values['plan'] = form.cleaned_data['plan']

        if form.cleaned_data['build']:
            _values['build'] = form.cleaned_data['build']

        if form.cleaned_data['manager']:
            _values['manager'] = form.cleaned_data['manager']

        if 'default_tester' in values:
            default_tester = form.cleaned_data['default_tester']
            if values.get('default_tester') and default_tester:
                _values['default_tester'] = default_tester
            else:
                _values['default_tester'] = None

        if form.cleaned_data['summary']:
            _values['summary'] = form.cleaned_data['summary']

        if values.get('estimated_time') is not None:
            _values['estimated_time'] = form.cleaned_data['estimated_time']

        if form.cleaned_data['product_version']:
            _values['product_version'] = form.cleaned_data['product_version']

        if 'notes' in values:
            if values['notes'] in (None, ''):
                _values['notes'] = values['notes']
            if form.cleaned_data['notes']:
                _values['notes'] = form.cleaned_data['notes']

        if form.cleaned_data['plan_text_version']:
            _values['plan_text_version'] = form.cleaned_data[
                'plan_text_version']

        if isinstance(form.cleaned_data['status'], int):
            if form.cleaned_data['status']:
                _values['stop_date'] = datetime.now()
            else:
                _values['stop_date'] = None

        trs.update(**_values)
    else:
        raise ValueError(forms.errors_to_list(form))

    query = {'pk__in': trs.values_list('pk', flat=True)}
    return TestRun.to_xmlrpc(query)
Пример #36
0
def update(request, run_ids, values):
    """
    Description: Updates the fields of the selected test run.

    Params:      $run_ids - Integer/Array/String: An integer or alias representing the ID in the database,
                            an array of run_ids, or a string of comma separated run_ids.

                 $values - Hash of keys matching TestRun fields and the new values
                           to set each field to. See params of TestRun.create for description
    +-------------------+----------------+--------------------------------+
    | Field             | Type           | Description                    |
    +-------------------+----------------+--------------------------------+
    | plan              | Integer        | TestPlan.plan_id               |
    | product           | Integer        | Product.id                     |
    | build             | Integer        | Build.id                       |
    | errata_id         | Integer        | Errata.id                      |
    | manager           | Integer        | Auth.User.id                   |
    | default_tester    | Intege         | Auth.User.id                   |
    | summary           | String         |                                |
    | estimated_time    | TimeDelta      | 2h30m30s(recommend) or HH:MM:SS|
    | product_version   | Integer        |                                |
    | plan_text_version | Integer        |                                |
    | notes             | String         |                                |
    | status            | Integer        | 0:RUNNING 1:FINISHED           |
    +-------------------+----------------+ -------------------------------+
    Returns:     Hash: The updated test run object.

    Example:
    # Update status to finished for run 1193 and 1194
    >>> TestRun.update([1193, 1194], {'status': 1})
    """
    from datetime import datetime
    from tcms.core import forms
    from tcms.testruns.forms import XMLRPCUpdateRunForm

    if (values.get('product_version') and not values.get('product')):
        raise ValueError('Field "product" is required by product_version')

    if values.get('estimated_time'):
        values['estimated_time'] = pre_process_estimated_time(
            values.get('estimated_time'))

    form = XMLRPCUpdateRunForm(values)
    if values.get('product_version'):
        form.populate(product_id=values['product'])

    if form.is_valid():
        trs = TestRun.objects.filter(pk__in=pre_process_ids(value=run_ids))
        _values = dict()
        if form.cleaned_data['plan']:
            _values['plan'] = form.cleaned_data['plan']

        if form.cleaned_data['build']:
            _values['build'] = form.cleaned_data['build']

        if form.cleaned_data['errata_id']:
            _values['errata_id'] = form.cleaned_data['errata_id']

        if form.cleaned_data['manager']:
            _values['manager'] = form.cleaned_data['manager']

        if 'default_tester' in values:
            if values.get('default_tester') and \
                    form.cleaned_data['default_tester']:
                _values['default_tester'] = form.cleaned_data['default_tester']
            else:
                _values['default_tester'] = None

        if form.cleaned_data['summary']:
            _values['summary'] = form.cleaned_data['summary']

        if values.get('estimated_time') is not None:
            _values['estimated_time'] = form.cleaned_data['estimated_time']

        if form.cleaned_data['product_version']:
            _values['product_version'] = form.cleaned_data['product_version']

        if 'notes' in values:
            if values['notes'] in (None, ''):
                _values['notes'] = values['notes']
            if form.cleaned_data['notes']:
                _values['notes'] = form.cleaned_data['notes']

        if form.cleaned_data['plan_text_version']:
            _values['plan_text_version'] = form.cleaned_data[
                'plan_text_version']

        if isinstance(form.cleaned_data['status'], int):
            if form.cleaned_data['status']:
                _values['stop_date'] = datetime.now()
            else:
                _values['stop_date'] = None

        trs.update(**_values)
    else:
        raise ValueError(forms.errors_to_list(form))

    query = {'pk__in': trs.values_list('pk', flat=True)}
    return TestRun.to_xmlrpc(query)
Пример #37
0
def update(request, run_ids, values):
    """
    Description: Updates the fields of the selected test run.

    Params:      $run_ids - Integer/Array/String: An integer or alias representing the ID in the database,
                            an array of run_ids, or a string of comma separated run_ids.

                 $values - Hash of keys matching TestRun fields and the new values
                           to set each field to. See params of TestRun.create for description
    +-------------------+----------------+--------------------------------+
    | Field             | Type           | Description                    |
    +-------------------+----------------+--------------------------------+
    | plan              | Integer        | TestPlan.plan_id               |
    | product           | Integer        | Product.id                     |
    | build             | Integer        | Build.id                       |
    | manager           | Integer        | Auth.User.id                   |
    | default_tester    | Intege         | Auth.User.id                   |
    | summary           | String         |                                |
    | estimated_time    | TimeDelta      | 2h30m30s(recommend) or HH:MM:SS|
    | product_version   | Integer        |                                |
    | plan_text_version | Integer        |                                |
    | notes             | String         |                                |
    | status            | Integer        | 0:RUNNING 1:FINISHED           |
    +-------------------+----------------+ -------------------------------+
    Returns:     Hash: The updated test run object.

    Example:
    # Update status to finished for run 1193 and 1194
    >>> TestRun.update([1193, 1194], {'status': 1})
    """
    from datetime import datetime
    from tcms.core import forms
    from tcms.testruns.forms import XMLRPCUpdateRunForm

    if (values.get('product_version') and not values.get('product')):
        raise ValueError('Field "product" is required by product_version')

    if values.get('estimated_time'):
        values['estimated_time'] = pre_process_estimated_time(
            values.get('estimated_time'))

    form = XMLRPCUpdateRunForm(values)
    if values.get('product_version'):
        form.populate(product_id=values['product'])

    if form.is_valid():
        trs = TestRun.objects.filter(pk__in=pre_process_ids(value=run_ids))
        _values = dict()
        if form.cleaned_data['plan']:
            _values['plan'] = form.cleaned_data['plan']

        if form.cleaned_data['build']:
            _values['build'] = form.cleaned_data['build']

        if form.cleaned_data['manager']:
            _values['manager'] = form.cleaned_data['manager']

        if 'default_tester' in values:
            if values.get('default_tester') and \
                    form.cleaned_data['default_tester']:
                _values['default_tester'] = form.cleaned_data['default_tester']
            else:
                _values['default_tester'] = None

        if form.cleaned_data['summary']:
            _values['summary'] = form.cleaned_data['summary']

        if values.get('estimated_time') is not None:
            _values['estimated_time'] = form.cleaned_data['estimated_time']

        if form.cleaned_data['product_version']:
            _values['product_version'] = form.cleaned_data['product_version']

        if 'notes' in values:
            if values['notes'] in (None, ''):
                _values['notes'] = values['notes']
            if form.cleaned_data['notes']:
                _values['notes'] = form.cleaned_data['notes']

        if form.cleaned_data['plan_text_version']:
            _values['plan_text_version'] = form.cleaned_data[
                'plan_text_version']

        if isinstance(form.cleaned_data['status'], int):
            if form.cleaned_data['status']:
                _values['stop_date'] = datetime.now()
            else:
                _values['stop_date'] = None

        trs.update(**_values)
    else:
        raise ValueError(forms.errors_to_list(form))

    query = {'pk__in': trs.values_list('pk', flat=True)}
    return TestRun.to_xmlrpc(query)