Skip to content

Commit

Permalink
Refactor RawSQL.num_case_run_bugs. Refs #36
Browse files Browse the repository at this point in the history
refactor into annotated Count
  • Loading branch information
atodorov committed Jul 2, 2018
1 parent 5956e8d commit 51b7820
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
11 changes: 1 addition & 10 deletions tcms/core/utils/raw_sql.py
@@ -1,14 +1,5 @@
# -*- coding: utf-8 -*-
class RawSQL: # pylint: disable=too-few-public-methods
"""
Record the Raw SQL for operate the database directly.
"""
num_case_run_bugs = 'SELECT COUNT(*) \
FROM testcases_bug \
WHERE testcases_bug.case_run_id = testruns_testcaserun.case_run_id'


class ReportSQL(object): # pylint: disable=too-few-public-methods
class RawSQL(object): # pylint: disable=too-few-public-methods
# Index
index_product_plans_count = 'SELECT COUNT(plan_id) \
FROM testplans_testplan \
Expand Down
2 changes: 1 addition & 1 deletion tcms/report/views.py
Expand Up @@ -12,7 +12,7 @@
from tcms.management.models import Priority
from tcms.management.models import Product
from tcms.testruns.models import TestRun, TestCaseRunStatus, TestCaseRun
from tcms.core.utils.raw_sql import ReportSQL as RawSQL
from tcms.core.utils.raw_sql import RawSQL
from tcms.report.forms import TestingReportForm
from tcms.report.forms import TestingReportCaseRunsListForm
from tcms.report.data import CustomDetailsReportData
Expand Down
7 changes: 3 additions & 4 deletions tcms/testruns/views.py
Expand Up @@ -28,7 +28,6 @@

from tcms.core.utils import clean_request
from tcms.core.utils import DataTableResult
from tcms.core.utils.raw_sql import RawSQL
from tcms.core.utils.validations import validate_bug_id
from tcms.management.models import Priority, EnvValue, Tag
from tcms.search.forms import RunForm
Expand Down Expand Up @@ -484,9 +483,9 @@ def open_run_get_case_runs(request, run):
'case__category__name')
# Get the bug count for each case run
# 5. have to show the number of bugs of each case run
tcrs = tcrs.extra(select={
'num_bug': RawSQL.num_case_run_bugs,
})
tcrs = tcrs.annotate(num_bug=Count('case_run_bug', distinct=True))

# todo: is this last distinct necessary
tcrs = tcrs.distinct()
# Continue to search the case runs with conditions
# 4. case runs preparing for render case runs table
Expand Down

0 comments on commit 51b7820

Please sign in to comment.