示例#1
0
    def test_to_xmlrpc(self):
        testrun1 = TestRun.objects.get(pk=self.testrun_pks[0])
        testrun2 = TestRun.objects.get(pk=self.testrun_pks[1])

        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]]
        sample_testrun2 = result[self.testrun_pks[1]]

        self.assertEqual(testrun1.errata_id, sample_testrun1['errata_id'])
        self.assertEqual(testrun1.product_version,
                         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 test_to_xmlrpc(self):
        testrun1 = TestRun.objects.get(pk=self.testrun_pks[0])
        testrun2 = TestRun.objects.get(pk=self.testrun_pks[1])

        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]]
        sample_testrun2 = result[self.testrun_pks[1]]

        self.assertEqual(testrun1.errata_id, sample_testrun1['errata_id'])
        self.assertEqual(testrun1.product_version, 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)
示例#3
0
文件: views.py 项目: xltian/nitrate
def recent(request, username, template_name='profile/recent.html'):
    """
    List the recent plan/run.
    """

    if username != request.user.username:
        return HttpResponseRedirect(reverse('django.contrib.auth.views.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)
    test_plans_disable_count = tps.count() - tps_active.count()

    return direct_to_template(request, template_name, {
        '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': trs[:15],
    })
示例#4
0
文件: views.py 项目: xltian/nitrate
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,
    })
示例#5
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.apps.testruns.models import TestRun
    query = {'plan': plan_id}
    return TestRun.to_xmlrpc(query)
示例#6
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.apps.testruns.models import TestRun

    query = {'plan': plan_id}
    return TestRun.to_xmlrpc(query)
示例#7
0
文件: build.py 项目: xltian/nitrate
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.apps.testruns.models import TestRun

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

    return TestRun.to_xmlrpc(query)
示例#8
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.apps.testruns.models import TestRun

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

    return TestRun.to_xmlrpc(query)
示例#9
0
文件: views.py 项目: xltian/nitrate
def ajax_search(request, template_name ='run/common/json_runs.txt'):
    """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
    # 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,},
            )
    else:
        search_form = SearchRunForm()
        # search_form.populate()

    #columnIndexNameMap is required for correct sorting behavior, 5 should be product, but we use run.build.product
    columnIndexNameMap = { 0: '', 1: 'run_id', 2: 'summary', 3: 'manager__username', 4: 'default_tester__username',
                          5: 'plan', 6: 'build__product__name', 7: 'product_version', 8: 'env_groups',
                          9: 'total_num_caseruns', 10: 'stop_date', 11: 'completed'}
    return ajax_response(request, trs, columnIndexNameMap, jsonTemplatePath='run/common/json_runs.txt')
示例#10
0
文件: product.py 项目: xltian/nitrate
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.apps.testruns.models import TestRun
    p = pre_check_product(values = product)
    query = {'build__product': p}
    return TestRun.to_xmlrpc(query)
示例#11
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.apps.testruns.models import TestRun

    p = pre_check_product(values=product)
    query = {'build__product': p}
    return TestRun.to_xmlrpc(query)
示例#12
0
def recent(request, username, template_name='profile/recent.html'):
    """
    List the recent plan/run.
    """

    if username != request.user.username:
        return HttpResponseRedirect(reverse('django.contrib.auth.views.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_to_response(template_name, context_data,
                              context_instance=RequestContext(request))
示例#13
0
文件: testrun.py 项目: xltian/nitrate
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     | String: Product 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)
示例#14
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     | String: Product 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)
示例#15
0
文件: testrun.py 项目: xltian/nitrate
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      | MM/DD/YYYY               |
                 | 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.apps.testruns.forms import XMLRPCUpdateRunForm

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

    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))

        if form.cleaned_data['plan']:
            trs.update(plan = form.cleaned_data['plan'])

        if form.cleaned_data['build']:
            trs.update(build = form.cleaned_data['build'])

        if form.cleaned_data['errata_id']:
            trs.update(errata_id = form.cleaned_data['errata_id'])

        if form.cleaned_data['manager']:
            trs.update(manager = form.cleaned_data['manager'])
        if values.has_key('default_tester'):
            if values.get('default_tester') and form.cleaned_data['default_tester']:
                trs.update(default_tester = form.cleaned_data['default_tester'])
            else:
                trs.update(default_tester = None)
        if form.cleaned_data['summary']:
            trs.update(summary = form.cleaned_data['summary'])

        if form.cleaned_data['estimated_time']:
            trs.update(estimated_time = form.cleaned_data['estimated_time'])

        if form.cleaned_data['product_version']:
            trs.update(product_version = form.cleaned_data['product_version'])

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

        if form.cleaned_data['plan_text_version']:
            trs.update(plan_text_version = form.cleaned_data['plan_text_version'])

        if isinstance(form.cleaned_data['status'], int):
            if form.cleaned_data['status']:
                trs.update(stop_date = datetime.now())
            else:
                trs.update(stop_date = None)
    else:
        return forms.errors_to_list(form)

    query = {'pk__in': trs.values_list('pk', flat=True)}
    return TestRun.to_xmlrpc(query)
示例#16
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      | MM/DD/YYYY               |
                 | 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.apps.testruns.forms import XMLRPCUpdateRunForm

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

    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 form.cleaned_data['estimated_time']:
            _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)