Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 9101e3d

Browse files
committed
feat: add filtering by search term for test results
1 parent 18a237a commit 9101e3d

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

graphql_api/tests/test_test_analytics.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,45 @@ def test_flake_rate_filtering_on_test_results(self) -> None:
588588
]
589589
}
590590

591+
def test_flake_rate_filtering_by_term(self) -> None:
592+
repo = RepositoryFactory(author=self.owner, active=True, private=True)
593+
test = TestFactory(repository=repo, name="hello")
594+
_ = DailyTestRollupFactory(
595+
test=test,
596+
date=datetime.date.today() - datetime.timedelta(days=1),
597+
repoid=repo.repoid,
598+
pass_count=1,
599+
fail_count=1,
600+
flaky_fail_count=1,
601+
)
602+
_ = DailyTestRollupFactory(
603+
test=test,
604+
date=datetime.date.today(),
605+
repoid=repo.repoid,
606+
pass_count=3,
607+
fail_count=0,
608+
flaky_fail_count=0,
609+
)
610+
test_2 = TestFactory(repository=repo, name="world")
611+
_ = DailyTestRollupFactory(
612+
test=test_2,
613+
date=datetime.date.today(),
614+
repoid=repo.repoid,
615+
pass_count=2,
616+
fail_count=3,
617+
flaky_fail_count=1,
618+
)
619+
res = self.fetch_test_analytics(
620+
repo.name,
621+
"""testResults(filters: { term: "hello" }) { edges { node { name failureRate } } }""",
622+
)
623+
624+
assert res["testResults"] == {
625+
"edges": [
626+
{"node": {"name": test.name, "failureRate": 0.2}},
627+
]
628+
}
629+
591630
def test_desc_flake_rate_ordering_on_test_results(self) -> None:
592631
repo = RepositoryFactory(author=self.owner, active=True, private=True)
593632
test = TestFactory(repository=repo)

graphql_api/types/inputs/test_results_filters.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ input TestResultsFilters {
44
test_suites: [String!]
55
flags: [String!]
66
history: MeasurementInterval
7+
term: String
78
}
89

910
input TestResultsOrdering {

graphql_api/types/test_analytics/test_analytics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ async def resolve_test_results(
4848
parameter=parameter,
4949
testsuites=filters.get("test_suites") if filters else None,
5050
flags=filters.get("flags") if filters else None,
51+
term=filters.get("term") if filters else None,
5152
)
5253

5354
return await queryset_to_connection(

utils/test_results.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def generate_test_results(
6666
parameter: GENERATE_TEST_RESULT_PARAM | None = None,
6767
testsuites: list[str] | None = None,
6868
flags: list[str] | None = None,
69+
term: str | None = None,
6970
) -> QuerySet:
7071
"""
7172
Function that retrieves aggregated information about all tests in a given repository, for a given time range, optionally filtered by branch name.
@@ -103,6 +104,9 @@ def generate_test_results(
103104

104105
totals = totals.filter(test_id__in=test_ids)
105106

107+
if term is not None:
108+
totals = totals.filter(test__name__icontains=term)
109+
106110
match parameter:
107111
case GENERATE_TEST_RESULT_PARAM.FLAKY:
108112
flakes = Flake.objects.filter(

0 commit comments

Comments
 (0)