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

Commit 8945e37

Browse files
feat: add use of computed_name in API (#870)
1 parent 7c3c6ae commit 8945e37

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

graphql_api/tests/test_test_result.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,40 @@ def test_fetch_test_result_name(self) -> None:
7676
0
7777
]["node"]["name"] == self.test.name.replace("\x1f", " ")
7878

79+
def test_fetch_test_result_name_with_computed_name(self) -> None:
80+
self.test.computed_name = "Computed Name"
81+
self.test.save()
82+
83+
query = """
84+
query {
85+
owner(username: "%s") {
86+
repository(name: "%s") {
87+
... on Repository {
88+
testAnalytics {
89+
testResults {
90+
edges {
91+
node {
92+
name
93+
}
94+
}
95+
}
96+
}
97+
}
98+
}
99+
}
100+
}
101+
""" % (self.owner.username, self.repository.name)
102+
103+
result = self.gql_request(query, owner=self.owner)
104+
105+
assert "errors" not in result
106+
assert (
107+
result["owner"]["repository"]["testAnalytics"]["testResults"]["edges"][0][
108+
"node"
109+
]["name"]
110+
== self.test.computed_name
111+
)
112+
79113
def test_fetch_test_result_updated_at(self) -> None:
80114
query = """
81115
query {

graphql_api/types/test_results/test_results.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ class TestDict(TypedDict):
1616
total_fail_count: int
1717
total_skip_count: int
1818
total_pass_count: int
19+
computed_name: str | None
1920

2021

2122
test_result_bindable = ObjectType("TestResult")
2223

2324

2425
@test_result_bindable.field("name")
2526
def resolve_name(test: TestDict, _: GraphQLResolveInfo) -> str:
26-
return test["name"].replace("\x1f", " ")
27+
return test.get("computed_name") or test["name"].replace("\x1f", " ")
2728

2829

2930
@test_result_bindable.field("updatedAt")

reports/tests/factories.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class Meta:
107107
name = factory.Sequence(lambda n: f"{n}")
108108
repository = factory.SubFactory(RepositoryFactory)
109109
commits_where_fail = []
110+
computed_name = None
110111

111112

112113
class TestInstanceFactory(factory.django.DjangoModelFactory):

utils/test_results.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ def generate_test_results(
197197
last_duration=Value(0.0),
198198
avg_duration=Avg("avg_duration_seconds"),
199199
name=F("test__name"),
200+
computed_name=F("test__computed_name"),
200201
)
201202

202203
return aggregation_of_test_results

0 commit comments

Comments
 (0)