From 58361711b3b725e9f0a0c83eeb7bde456b504b39 Mon Sep 17 00:00:00 2001 From: joseph-sentry Date: Tue, 8 Oct 2024 12:05:12 -0400 Subject: [PATCH 1/4] 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 --- graphql_api/tests/test_test_result.py | 31 +++++++++++++++++++ .../types/test_results/test_results.py | 2 +- reports/tests/factories.py | 1 + utils/test_results.py | 1 + 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/graphql_api/tests/test_test_result.py b/graphql_api/tests/test_test_result.py index 8542062359..85d05ab10b 100644 --- a/graphql_api/tests/test_test_result.py +++ b/graphql_api/tests/test_test_result.py @@ -76,6 +76,37 @@ 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 { + results { + 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"]["results"]["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..5f68ff9ae3 100644 --- a/graphql_api/types/test_results/test_results.py +++ b/graphql_api/types/test_results/test_results.py @@ -23,7 +23,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 From 85274b37bdf72e346578f1bc61b3b7d937f22e3c Mon Sep 17 00:00:00 2001 From: joseph-sentry Date: Tue, 8 Oct 2024 14:31:40 -0400 Subject: [PATCH 2/4] chore: make lint --- graphql_api/tests/test_test_result.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/graphql_api/tests/test_test_result.py b/graphql_api/tests/test_test_result.py index 85d05ab10b..cbada81dca 100644 --- a/graphql_api/tests/test_test_result.py +++ b/graphql_api/tests/test_test_result.py @@ -103,9 +103,12 @@ def test_fetch_test_result_name_with_computed_name(self) -> None: result = self.gql_request(query, owner=self.owner) assert "errors" not in result - assert result["owner"]["repository"]["testAnalytics"]["results"]["edges"][0][ - "node" - ]["name"] == self.test.computed_name + assert ( + result["owner"]["repository"]["testAnalytics"]["results"]["edges"][0][ + "node" + ]["name"] + == self.test.computed_name + ) def test_fetch_test_result_updated_at(self) -> None: query = """ From c6da8c9b460e8ff0847de072c468ae3905b16005 Mon Sep 17 00:00:00 2001 From: joseph-sentry Date: Tue, 15 Oct 2024 12:09:49 -0400 Subject: [PATCH 3/4] fix: fix tests --- graphql_api/tests/test_test_result.py | 2 +- graphql_api/types/test_results/test_results.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/graphql_api/tests/test_test_result.py b/graphql_api/tests/test_test_result.py index cbada81dca..91c08c4189 100644 --- a/graphql_api/tests/test_test_result.py +++ b/graphql_api/tests/test_test_result.py @@ -86,7 +86,7 @@ def test_fetch_test_result_name_with_computed_name(self) -> None: repository(name: "%s") { ... on Repository { testAnalytics { - results { + testResults { edges { node { name diff --git a/graphql_api/types/test_results/test_results.py b/graphql_api/types/test_results/test_results.py index 5f68ff9ae3..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") From 827093a05aa29b2893112d46f1438f37bdd1c57a Mon Sep 17 00:00:00 2001 From: joseph-sentry Date: Tue, 15 Oct 2024 12:17:48 -0400 Subject: [PATCH 4/4] fix: tests --- graphql_api/tests/test_test_result.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphql_api/tests/test_test_result.py b/graphql_api/tests/test_test_result.py index 91c08c4189..266d1d90e6 100644 --- a/graphql_api/tests/test_test_result.py +++ b/graphql_api/tests/test_test_result.py @@ -104,7 +104,7 @@ def test_fetch_test_result_name_with_computed_name(self) -> None: assert "errors" not in result assert ( - result["owner"]["repository"]["testAnalytics"]["results"]["edges"][0][ + result["owner"]["repository"]["testAnalytics"]["testResults"]["edges"][0][ "node" ]["name"] == self.test.computed_name