diff --git a/graphql_api/tests/test_test_result.py b/graphql_api/tests/test_test_result.py index 8542062359..266d1d90e6 100644 --- a/graphql_api/tests/test_test_result.py +++ b/graphql_api/tests/test_test_result.py @@ -76,6 +76,40 @@ def test_fetch_test_result_name(self) -> None: 0 ]["node"]["name"] == self.test.name.replace("\x1f", " ") + def test_fetch_test_result_name_with_computed_name(self) -> None: + self.test.computed_name = "Computed Name" + self.test.save() + + query = """ + query { + owner(username: "%s") { + repository(name: "%s") { + ... on Repository { + testAnalytics { + testResults { + edges { + node { + name + } + } + } + } + } + } + } + } + """ % (self.owner.username, self.repository.name) + + result = self.gql_request(query, owner=self.owner) + + assert "errors" not in result + assert ( + result["owner"]["repository"]["testAnalytics"]["testResults"]["edges"][0][ + "node" + ]["name"] + == self.test.computed_name + ) + def test_fetch_test_result_updated_at(self) -> None: query = """ query { diff --git a/graphql_api/types/test_results/test_results.py b/graphql_api/types/test_results/test_results.py index 005fab4447..3963d975bd 100644 --- a/graphql_api/types/test_results/test_results.py +++ b/graphql_api/types/test_results/test_results.py @@ -16,6 +16,7 @@ class TestDict(TypedDict): total_fail_count: int total_skip_count: int total_pass_count: int + computed_name: str | None test_result_bindable = ObjectType("TestResult") @@ -23,7 +24,7 @@ class TestDict(TypedDict): @test_result_bindable.field("name") def resolve_name(test: TestDict, _: GraphQLResolveInfo) -> str: - return test["name"].replace("\x1f", " ") + return test.get("computed_name") or test["name"].replace("\x1f", " ") @test_result_bindable.field("updatedAt") diff --git a/reports/tests/factories.py b/reports/tests/factories.py index e8597c9e20..5f47c76e3c 100644 --- a/reports/tests/factories.py +++ b/reports/tests/factories.py @@ -107,6 +107,7 @@ class Meta: name = factory.Sequence(lambda n: f"{n}") repository = factory.SubFactory(RepositoryFactory) commits_where_fail = [] + computed_name = None class TestInstanceFactory(factory.django.DjangoModelFactory): diff --git a/utils/test_results.py b/utils/test_results.py index 464e20a4da..fef283ef7c 100644 --- a/utils/test_results.py +++ b/utils/test_results.py @@ -197,6 +197,7 @@ def generate_test_results( last_duration=Value(0.0), avg_duration=Avg("avg_duration_seconds"), name=F("test__name"), + computed_name=F("test__computed_name"), ) return aggregation_of_test_results