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

Commit 5836171

Browse files
committed
feat: add use of computed_name in API
if a test has a computed name we want to return that as the test name in the GQL Test Result object instead of its uncomputed name otherwise just return its uncomputed name with the special separation character escaped
1 parent 7c3c6ae commit 5836171

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

graphql_api/tests/test_test_result.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,37 @@ 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+
results {
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 result["owner"]["repository"]["testAnalytics"]["results"]["edges"][0][
107+
"node"
108+
]["name"] == self.test.computed_name
109+
79110
def test_fetch_test_result_updated_at(self) -> None:
80111
query = """
81112
query {

graphql_api/types/test_results/test_results.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TestDict(TypedDict):
2323

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

2828

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