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

Commit b0bfdf3

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 b6b028c commit b0bfdf3

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
"node"
7777
]["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
@@ -20,7 +20,7 @@ class TestDict(TypedDict):
2020

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

2525

2626
@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
@@ -189,6 +189,7 @@ def generate_test_results(
189189
last_duration=Subquery(latest_duration_sq),
190190
avg_duration=Avg("avg_duration_seconds"),
191191
name=F("test__name"),
192+
computed_name=F("test__computed_name"),
192193
)
193194

194195
return aggregation_of_test_results

0 commit comments

Comments
 (0)