Ejemplo n.º 1
0
    def status_matrix(self, form):
        sql, params = self._prepare_sql(
            form, sqls.by_plan_build_detail_status_matrix)
        rows = SQLExecution(sql, params, with_field_name=False).rows
        status_matrix = GroupByResult()

        plan_ids = build_ids = run_ids = []
        for plan_id, build_id, run_id, status_name, _ in rows:
            plan_ids.append(plan_id)
            build_ids.append(build_id)
            run_ids.append(run_id)

        plans = {
            plan.pk: plan for plan in TestPlan.objects.filter(
                pk__in=plan_ids).only('pk', 'name')
        }
        test_builds = {
            build.pk: build for build in TestBuild.objects.filter(
                pk__in=build_ids).only('pk', 'name')
        }
        runs = {
            run.pk: run for run in TestRun.objects.filter(
                pk__in=run_ids).only('pk', 'summary')
        }

        for row in rows:
            plan_id, build_id, run_id, status_name, total_count = row
            builds = status_matrix.setdefault(plans[plan_id], GroupByResult())
            runs = builds.setdefault(test_builds[build_id], GroupByResult())
            status_subtotal = runs.setdefault(runs[run_id], GroupByResult())
            status_subtotal[status_name] = total_count

        return status_matrix
Ejemplo n.º 2
0
    def status_matrix_groupby_builds(self, form):
        builds = GroupByResult({})
        query = self._filter_query(
            form,
            TestCaseRun.objects.values(
                'build',
                'tested_by',
                'case_run_status__name'
            ).annotate(
                total_count=Count('pk')
            )
        )

        for row in query:
            build_id = row['build']
            tested_by_id = row['tested_by']
            name = row['case_run_status__name']
            total_count = row['total_count']

            tested_by_ids = builds.setdefault(build_id, GroupByResult({}))
            status_subtotal = tested_by_ids.setdefault(tested_by_id,
                                                       GroupByResult({}))
            status_subtotal[name] = total_count

        return builds
Ejemplo n.º 3
0
    def status_matrix(self, form):
        status_matrix = GroupByResult()
        query = self._filter_query(
            form,
            TestCaseRun.objects.values(
                'run__plan',
                'run__plan__name',
                'case_run_status__name'
            ).filter(
                case_run_status__name__in=('PASSED', 'FAILED')
            ).annotate(
                total_count=Count('run', distinct=True)
            )
        )

        for row in query:
            plan_id = row['run__plan']
            plan_name = row['run__plan__name']
            status_name = row['case_run_status__name']
            total_count = row['total_count']
            plan = TestPlan(pk=plan_id, name=plan_name)
            status_subtotal = status_matrix.setdefault(plan, GroupByResult())
            status_subtotal[status_name] = total_count

        return status_matrix
Ejemplo n.º 4
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(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
Ejemplo n.º 5
0
 def status_matrix(self, form):
     sql, params = self._prepare_sql(form,
                                     sqls.by_plan_build_status_matrix)
     rows = SQLExecution(sql, params, with_field_name=False).rows
     status_matrix = GroupByResult()
     for plan_id, plan_name, status_name, total_count in rows:
         plan = TestPlan(pk=plan_id, name=plan_name)
         status_subtotal = status_matrix.setdefault(plan, GroupByResult())
         status_subtotal[status_name] = total_count
     return status_matrix
Ejemplo n.º 6
0
 def status_matrix(self, form):
     sql, params = self._prepare_sql(form, sqls.by_plan_build_status_matrix)
     rows = list(SQLExecution(sql, params, with_field_name=False).rows)
     plans = {
         p.pk: p for p in TestPlan.objects.filter(
             pk__in=[plan_id for plan_id, _, _ in rows]).only('pk', 'name')
     }
     status_matrix = GroupByResult()
     for plan_id, status_name, total_count in rows:
         status_subtotal = status_matrix.setdefault(plans[plan_id], GroupByResult())
         status_subtotal[status_name] = total_count
     return status_matrix
Ejemplo n.º 7
0
    def passed_failed_case_runs_subtotal(self, form):
        sql, params = self._prepare_sql(
            form, sqls.by_plan_tags_passed_failed_case_runs_subtotal)
        sql_executor = SQLExecution(sql, params, with_field_name=False)
        rows = sql_executor.rows
        tags = GroupByResult()

        for tag_id, name, total_count in rows:
            status_subtotal = tags.setdefault(tag_id, GroupByResult())
            status_subtotal[name] = total_count

        return tags
Ejemplo n.º 8
0
    def status_matrix(self):
        """Case run status matrix used to render progress bar"""
        sql, params = self._prepare_sql(
            sqls.custom_builds_case_runs_subtotal_by_status)
        rows = SQLExecution(sql, params, with_field_name=False).rows

        builds = GroupByResult()
        for build_id, case_run_status_id, total_count in rows:
            status_subtotal = builds.setdefault(build_id, GroupByResult())
            status_subtotal[case_run_status_id] = total_count

        return builds
Ejemplo n.º 9
0
    def status_matrix(self, form):
        sql, params = self._prepare_sql(form, sqls.by_case_priority_subtotal)
        sql_executor = SQLExecution(sql, params, with_field_name=False)
        rows = sql_executor.rows

        builds = GroupByResult()

        for build_id, priority_id, priority_value, name, total_count in rows:
            priorities = builds.setdefault(build_id, GroupByResult())
            priority = Priority(pk=priority_id, value=priority_value)
            status_subtotal = priorities.setdefault(priority, GroupByResult())
            status_subtotal[name] = total_count

        return builds
Ejemplo n.º 10
0
    def runs_subtotal_groupby_builds(self, form):
        sql, params = self._prepare_sql(
            form, sqls.by_case_run_tester_runs_subtotal_groupby_build)
        sql_executor = SQLExecution(sql, params,
                                    with_field_name=False)
        rows = sql_executor.rows

        builds = GroupByResult({})

        for build_id, tested_by_id, total_count in rows:
            tested_by_ids = builds.setdefault(build_id, GroupByResult({}))
            tested_by_ids[tested_by_id] = total_count

        return builds
Ejemplo n.º 11
0
    def status_matrix(self, form):
        sql, params = self._prepare_sql(
            form, sqls.by_case_run_tester_status_matrix)
        sql_executor = SQLExecution(sql, params,
                                    with_field_name=False)
        status_matrix = GroupByResult({})
        rows = sql_executor.rows

        for tested_by_id, name, total_count in rows:
            status_subtotal = status_matrix.setdefault(
                tested_by_id, GroupByResult({}))
            status_subtotal[name] = total_count

        return status_matrix
Ejemplo n.º 12
0
    def status_matrix_groupby_builds(self, form):
        sql, params = self._prepare_sql(
            form, sqls.by_case_run_tester_status_matrix_groupby_build)
        sql_executor = SQLExecution(sql, params,
                                    with_field_name=False)

        builds = GroupByResult({})

        for build_id, tested_by_id, name, total_count in sql_executor.rows:
            tested_by_ids = builds.setdefault(
                build_id, GroupByResult({}))
            status_subtotal = tested_by_ids.setdefault(tested_by_id,
                                                       GroupByResult({}))
            status_subtotal[name] = total_count

        return builds
Ejemplo n.º 13
0
    def setUp(self):
        self.groupby_result = GroupByResult({
            1: 100,
            2: 300,
            4: 400,
        })

        self.nested_groupby_result = GroupByResult({
            1: GroupByResult({'a': 1,
                              'b': 2,
                              'c': 3}),
            2: GroupByResult({1: 1,
                              2: 2}),
            3: GroupByResult({'PASSED': 10,
                              'WAIVED': 20,
                              'FAILED': 30,
                              'PAUSED': 40}),
        })
Ejemplo n.º 14
0
    def runs_subtotal_groupby_builds(self, form):
        builds = GroupByResult({})
        query = self._filter_query(
            form,
            TestCaseRun.objects.values('tested_by', 'run', 'build').distinct()
        )

        for row in query:
            build_id = row['build']
            tested_by_id = row['tested_by']

            tested_by_ids = builds.setdefault(build_id, GroupByResult({}))
            if tested_by_id in tested_by_ids.keys():
                tested_by_ids[tested_by_id] += 1
            else:
                tested_by_ids[tested_by_id] = 1

        return builds
Ejemplo n.º 15
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
Ejemplo n.º 16
0
class GroupByResultCalculationTest(TestCase):
    '''Test calculation of GroupByResult'''

    def setUp(self):
        self.groupby_result = GroupByResult({
            1: 100,
            2: 300,
            4: 400,
        })

        self.nested_groupby_result = GroupByResult({
            1: GroupByResult({'a': 1,
                              'b': 2,
                              'c': 3}),
            2: GroupByResult({1: 1,
                              2: 2}),
            3: GroupByResult({'PASSED': 10,
                              'WAIVED': 20,
                              'FAILED': 30,
                              'PAUSED': 40}),
        })

    def _sample_total(self):
        return sum(count for key, count in self.groupby_result.iteritems())

    def _sample_nested_total(self):
        total = 0
        for key, nested_result in self.nested_groupby_result.iteritems():
            for n, count in nested_result.iteritems():
                total += count
        return total

    def test_total(self):
        total = self.groupby_result.total
        self.assertEqual(total, self._sample_total())

    def test_nested_total(self):
        total = self.nested_groupby_result.total
        self.assertEqual(total, self._sample_nested_total())
Ejemplo n.º 17
0
    def status_matrix(self, form):
        status_matrix = GroupByResult({})
        query = self._filter_query(
            form,
            TestCaseRun.objects.values(
                'tested_by',
                'case_run_status__name'
            ).annotate(
                total_count=Count('pk')
            )
        )

        for row in query:
            tested_by_id = row['tested_by']
            name = row['case_run_status__name']
            total_count = row['total_count']

            status_subtotal = status_matrix.setdefault(
                tested_by_id, GroupByResult({}))
            status_subtotal[name] = total_count

        return status_matrix
Ejemplo n.º 18
0
class GroupByResultDictLikeTest(TestCase):
    '''Test dict like behaviors'''

    def setUp(self):
        self.groupby_result = GroupByResult({'total': 100})

    def test_in(self):
        self.assert_('a' not in self.groupby_result)
        self.assert_('total' in self.groupby_result)

    def test_key(self):
        self.assert_(self.groupby_result.keys(), ['total'])

    def test_setdefault(self):
        ret_val = self.groupby_result.setdefault('count', {})
        self.assertEqual(ret_val, {})

        ret_val = self.groupby_result.setdefault('total', 200)
        self.assertEqual(ret_val, 100)

    def test_getitem(self):
        ret_val = self.groupby_result['total']
        self.assertEqual(ret_val, 100)

        try:
            ret_val = self.groupby_result['xxx']
        except KeyError:
            pass
        else:
            self.fail('xxx does not exist. KeyError should be raised.')

    def test_setitem(self):
        self.groupby_result['count'] = 200
        self.assertEqual(self.groupby_result['count'], 200)

        self.groupby_result['total'] = 999
        self.assertEqual(self.groupby_result['total'], 999)

    def test_get(self):
        ret_val = self.groupby_result.get('total')
        self.assertEqual(ret_val, 100)

        ret_val = self.groupby_result.get('count', 999)
        self.assertEqual(ret_val, 999)

        ret_val = self.groupby_result.get('xxx')
        self.assertEqual(ret_val, None)

    def test_len(self):
        self.assertEqual(len(self.groupby_result), 1)

    def test_del(self):
        self.groupby_result['count'] = 200
        del self.groupby_result['total']
        self.assert_('total' not in self.groupby_result)
        del self.groupby_result['count']
        self.assert_('count' not in self.groupby_result)
        self.assertEqual(len(self.groupby_result), 0)
Ejemplo n.º 19
0
    def passed_failed_case_runs_subtotal(self, form):
        query = self._filter_query(
            form,
            TestCaseRun.objects.values(
                'run__plan__tag', 'case_run_status__name'
            ).filter(case_run_status__name__in=['PASSED', 'FAILED']).annotate(
                total_count=Count('case_run_status')
            )
        )

        tags = GroupByResult()
        for row in query:
            tag_id = row['run__plan__tag']
            name = row['case_run_status__name']
            total_count = row['total_count']

            status_subtotal = tags.setdefault(tag_id, GroupByResult())
            status_subtotal[name] = total_count

        from pprint import pprint
        pprint(tags)

        return tags
Ejemplo n.º 20
0
    def status_matrix(self, form):
        builds = GroupByResult()
        query = self._filter_query(
            form,
            TestCaseRun.objects.values(
                'build',
                'case__priority',
                'case__priority__value',
                'case_run_status__name'
            ).annotate(total_count=Count('pk'))
        )

        for row in query:
            build_id = row['build']
            priority_id = row['case__priority']
            priority_value = row['case__priority__value']
            name = row['case_run_status__name']
            total_count = row['total_count']
            priorities = builds.setdefault(build_id, GroupByResult())
            priority = Priority(pk=priority_id, value=priority_value)
            status_subtotal = priorities.setdefault(priority, GroupByResult())
            status_subtotal[name] = total_count

        return builds
Ejemplo n.º 21
0
class GroupByResultDictLikeTest(unittest.TestCase):
    """Test dict like behaviors"""

    def setUp(self):
        self.groupby_result = GroupByResult({'total': 100})

    def test_in(self):
        self.assertNotIn('a', self.groupby_result)
        self.assertIn('total', self.groupby_result)

    def test_key(self):
        self.assertTrue(self.groupby_result.keys(), ['total'])

    def test_setdefault(self):
        ret_val = self.groupby_result.setdefault('count', {})
        self.assertEqual(ret_val, {})

        ret_val = self.groupby_result.setdefault('total', 200)
        self.assertEqual(ret_val, 100)

    def test_setitem(self):
        self.groupby_result['count'] = 200
        self.assertEqual(self.groupby_result['count'], 200)

        self.groupby_result['total'] = 999
        self.assertEqual(self.groupby_result['total'], 999)

    def test_get(self):
        ret_val = self.groupby_result.get('total')
        self.assertEqual(ret_val, 100)

        ret_val = self.groupby_result.get('count', 999)
        self.assertEqual(ret_val, 999)

        ret_val = self.groupby_result.get('xxx')
        self.assertEqual(ret_val, None)

    def test_len(self):
        self.assertEqual(len(self.groupby_result), 1)

    def test_del(self):
        self.groupby_result['count'] = 200
        del self.groupby_result['total']
        self.assertNotIn('total', self.groupby_result)
        del self.groupby_result['count']
        self.assertNotIn('count', self.groupby_result)
        self.assertEqual(len(self.groupby_result), 0)
Ejemplo n.º 22
0
 def setUp(self):
     self.levels_groupby_result = GroupByResult({
         'build_1': GroupByResult({
             'plan_1': GroupByResult({
                 'run_1': GroupByResult(
                     {'passed': 1, 'failed': 2, 'error': 3, }),
                 'run_2': GroupByResult(
                     {'passed': 1, 'failed': 2, 'error': 3, }),
                 'run_3': GroupByResult(
                     {'passed': 1, 'failed': 2, 'error': 3, }),
             }),
             'plan_2': GroupByResult({
                 'run_1': GroupByResult(
                     {'passed': 1, 'failed': 2, 'error': 3, }),
                 'run_2': GroupByResult(
                     {'passed': 1, 'failed': 2, 'error': 3, }),
             }),
         }),
         'build_2': GroupByResult({
             'plan_1': GroupByResult({
                 'run_1': GroupByResult(
                     {'passed': 1, 'failed': 2, 'error': 3, }),
                 'run_4': GroupByResult(
                     {'paused': 2, 'failed': 2, 'waived': 6, }),
                 'run_5': GroupByResult(
                     {'paused': 1, 'failed': 2, 'waived': 3, }),
             }),
             'plan_2': GroupByResult({
                 'run_1': GroupByResult(
                     {'passed': 1, 'failed': 2, 'error': 3, }),
                 'run_4': GroupByResult(
                     {'paused': 2, 'failed': 2, 'waived': 6, }),
                 'run_5': GroupByResult(
                     {'paused': 1, 'failed': 2, 'waived': 3, }),
             }),
         }),
     })
Ejemplo n.º 23
0
class GroupByResultCalculationTest(unittest.TestCase):
    """Test calculation of GroupByResult"""

    def setUp(self):
        self.groupby_result = GroupByResult({
            1: 100,
            2: 300,
            4: 400,
        })

        self.nested_groupby_result = GroupByResult({
            1: GroupByResult({'a': 1,
                              'b': 2,
                              'c': 3}),
            2: GroupByResult({1: 1,
                              2: 2}),
            3: GroupByResult({'PASSED': 10,
                              'WAIVED': 20,
                              'FAILED': 30,
                              'PAUSED': 40}),
        })

    def _sample_total(self):
        return sum(count for key, count in self.groupby_result.iteritems())

    def _sample_nested_total(self):
        total = 0
        for key, nested_result in self.nested_groupby_result.iteritems():
            for n, count in nested_result.iteritems():
                total += count
        return total

    def test_total(self):
        total = self.groupby_result.total
        self.assertEqual(total, self._sample_total())

    def test_nested_total(self):
        total = self.nested_groupby_result.total
        self.assertEqual(total, self._sample_nested_total())

    def test_get_total_after_add_data_based_on_empty_initial_data(self):
        result = GroupByResult()
        result['RUNNING'] = 100
        result['PASSED'] = 100
        self.assertEqual(200, result.total)

    def test_get_total_after_add_data_based_on_initial_data(self):
        result = GroupByResult({'FAILED': 20})
        result['RUNNING'] = 100
        result['PASSED'] = 100
        self.assertEqual(220, result.total)

    def test_total_is_updated_after_del_item(self):
        result = GroupByResult({'FAILED': 20, 'RUNNING': 20, 'PASSED': 10})
        del result['RUNNING']
        self.assertEqual(30, result.total)

    def test_total_is_updated_after_del_item_several_times(self):
        result = GroupByResult({'FAILED': 20, 'RUNNING': 20, 'PASSED': 10})
        del result['RUNNING']
        del result['FAILED']
        self.assertEqual(10, result.total)

    def test_percentage(self):
        result = GroupByResult({
            'IDLE': 20,
            'PASSED': 20,
            'RUNNING': 10,
        })
        self.assertEqual(40.0, result.PASSED_percent)

    def test_zero_percentage(self):
        result = GroupByResult({})
        self.assertEqual(.0, result.PASSED_percent)

    def test_default_zero(self):
        result = GroupByResult()
        result['RUNNING'] += 1
        self.assertEqual(1, result['RUNNING'])
Ejemplo n.º 24
0
class GroupByResultLevelTest(TestCase):
    def setUp(self):
        self.levels_groupby_result = GroupByResult({
            'build_1': GroupByResult({
                'plan_1': GroupByResult({
                    'run_1': GroupByResult(
                        {'passed': 1, 'failed': 2, 'error': 3, }),
                    'run_2': GroupByResult(
                        {'passed': 1, 'failed': 2, 'error': 3, }),
                    'run_3': GroupByResult(
                        {'passed': 1, 'failed': 2, 'error': 3, }),
                }),
                'plan_2': GroupByResult({
                    'run_1': GroupByResult(
                        {'passed': 1, 'failed': 2, 'error': 3, }),
                    'run_2': GroupByResult(
                        {'passed': 1, 'failed': 2, 'error': 3, }),
                }),
            }),
            'build_2': GroupByResult({
                'plan_1': GroupByResult({
                    'run_1': GroupByResult(
                        {'passed': 1, 'failed': 2, 'error': 3, }),
                    'run_4': GroupByResult(
                        {'paused': 2, 'failed': 2, 'waived': 6, }),
                    'run_5': GroupByResult(
                        {'paused': 1, 'failed': 2, 'waived': 3, }),
                }),
                'plan_2': GroupByResult({
                    'run_1': GroupByResult(
                        {'passed': 1, 'failed': 2, 'error': 3, }),
                    'run_4': GroupByResult(
                        {'paused': 2, 'failed': 2, 'waived': 6, }),
                    'run_5': GroupByResult(
                        {'paused': 1, 'failed': 2, 'waived': 3, }),
                }),
            }),
        })

    def test_value_leaf_count(self):
        value_leaf_count = self.levels_groupby_result.leaf_values_count()
        self.assertEqual(value_leaf_count, 33)

        value_leaf_count = self.levels_groupby_result[
            'build_1'].leaf_values_count()
        self.assertEqual(value_leaf_count, 15)

        level_node = self.levels_groupby_result['build_2']['plan_2']
        value_leaf_count = level_node.leaf_values_count()
        self.assertEqual(value_leaf_count, 9)

    def test_value_leaf_in_row_count(self):
        value_leaf_count = self.levels_groupby_result.leaf_values_count(
            value_in_row=True)
        self.assertEqual(value_leaf_count, 11)

        level_node = self.levels_groupby_result['build_2']
        value_leaf_count = level_node.leaf_values_count(value_in_row=True)
        self.assertEqual(value_leaf_count, 6)

        level_node = self.levels_groupby_result['build_1']['plan_2']
        value_leaf_count = level_node.leaf_values_count(value_in_row=True)
        self.assertEqual(value_leaf_count, 2)
Ejemplo n.º 25
0
 def setUp(self):
     self.groupby_result = GroupByResult({'total': 100})