From ac814e16867bd0dbb09bd5a0a7be8550b347a7f5 Mon Sep 17 00:00:00 2001 From: Suejung Shin Date: Tue, 8 Oct 2024 13:47:52 -0700 Subject: [PATCH 1/2] chore: Remove deprecated testAnalytics graphql fields --- graphql_api/tests/test_repository.py | 574 ------------------ graphql_api/tests/test_test_result_legacy.py | 218 ------- .../types/repository/repository.graphql | 9 - graphql_api/types/repository/repository.py | 84 +-- 4 files changed, 2 insertions(+), 883 deletions(-) delete mode 100644 graphql_api/tests/test_test_result_legacy.py diff --git a/graphql_api/tests/test_repository.py b/graphql_api/tests/test_repository.py index 742aa42dbe..2118001006 100644 --- a/graphql_api/tests/test_repository.py +++ b/graphql_api/tests/test_repository.py @@ -3,7 +3,6 @@ from django.test import TransactionTestCase, override_settings from freezegun import freeze_time -from shared.django_apps.reports.tests.factories import FlakeFactory from codecov_auth.tests.factories import OwnerFactory from core.tests.factories import ( @@ -12,12 +11,6 @@ RepositoryFactory, RepositoryTokenFactory, ) -from reports.tests.factories import ( - DailyTestRollupFactory, - RepositoryFlagFactory, - TestFactory, - TestFlagBridgeFactory, -) from services.profiling import CriticalFile from .helper import GraphQLTestHelper @@ -884,570 +877,3 @@ def test_fetch_is_github_rate_limited_but_errors( "has_owner": True, }, ) - - # TODO - remove this with #2291 - def test_test_results(self) -> None: - repo = RepositoryFactory(author=self.owner, active=True, private=True) - test = TestFactory(repository=repo) - - _ = DailyTestRollupFactory(test=test) - res = self.fetch_repository( - repo.name, """testResults { edges { node { name } } }""" - ) - assert res["testResults"] == {"edges": [{"node": {"name": test.name}}]} - - # TODO - remove this with #2291 - def test_test_results_no_tests(self) -> None: - repo = RepositoryFactory(author=self.owner, active=True, private=True) - res = self.fetch_repository( - repo.name, """testResults { edges { node { name } } }""" - ) - assert res["testResults"] == {"edges": []} - - # TODO - remove this with #2291 - def test_branch_filter_on_test_results(self) -> None: - repo = RepositoryFactory(author=self.owner, active=True, private=True) - test = TestFactory(repository=repo) - test2 = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test, - created_at=datetime.datetime.now(), - repoid=repo.repoid, - branch="main", - ) - _ = DailyTestRollupFactory( - test=test2, - created_at=datetime.datetime.now(), - repoid=repo.repoid, - branch="feature", - ) - res = self.fetch_repository( - repo.name, - """testResults(filters: { branch: "main"}) { edges { node { name } } }""", - ) - assert res["testResults"] == {"edges": [{"node": {"name": test.name}}]} - - # TODO - remove this with #2291 - def test_flaky_filter_on_test_results(self) -> None: - repo = RepositoryFactory(author=self.owner, active=True, private=True) - test = TestFactory(repository=repo) - test2 = TestFactory(repository=repo) - _ = FlakeFactory(test=test2, repository=repo, end_date=None) - _ = DailyTestRollupFactory( - test=test, - created_at=datetime.datetime.now(), - repoid=repo.repoid, - branch="main", - ) - _ = DailyTestRollupFactory( - test=test2, - created_at=datetime.datetime.now(), - repoid=repo.repoid, - branch="feature", - ) - res = self.fetch_repository( - repo.name, - """testResults(filters: { parameter: FLAKY_TESTS }) { edges { node { name } } }""", - ) - assert res["testResults"] == {"edges": [{"node": {"name": test2.name}}]} - - # TODO - remove this with #2291 - def test_failed_filter_on_test_results(self) -> None: - repo = RepositoryFactory(author=self.owner, active=True, private=True) - test = TestFactory(repository=repo) - test2 = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test, - created_at=datetime.datetime.now(), - repoid=repo.repoid, - branch="main", - fail_count=0, - ) - _ = DailyTestRollupFactory( - test=test2, - created_at=datetime.datetime.now(), - repoid=repo.repoid, - branch="feature", - fail_count=1000, - ) - res = self.fetch_repository( - repo.name, - """testResults(filters: { parameter: FAILED_TESTS }) { edges { node { name } } }""", - ) - assert res["testResults"] == {"edges": [{"node": {"name": test2.name}}]} - - # TODO - remove this with #2291 - def test_skipped_filter_on_test_results(self) -> None: - repo = RepositoryFactory(author=self.owner, active=True, private=True) - test = TestFactory(repository=repo) - test2 = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test, - created_at=datetime.datetime.now(), - repoid=repo.repoid, - branch="main", - skip_count=10, - pass_count=10, - fail_count=10, - ) - _ = DailyTestRollupFactory( - test=test2, - created_at=datetime.datetime.now(), - repoid=repo.repoid, - branch="feature", - skip_count=1000, - pass_count=0, - fail_count=0, - ) - res = self.fetch_repository( - repo.name, - """testResults(filters: { parameter: SKIPPED_TESTS }) { edges { node { name } } }""", - ) - assert res["testResults"] == {"edges": [{"node": {"name": test2.name}}]} - - # TODO - remove this with #2291 - def test_slowest_filter_on_test_results(self) -> None: - repo = RepositoryFactory(author=self.owner, active=True, private=True) - test = TestFactory(repository=repo) - test2 = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test, - created_at=datetime.datetime.now(), - repoid=repo.repoid, - branch="main", - avg_duration_seconds=0.1, - ) - _ = DailyTestRollupFactory( - test=test2, - created_at=datetime.datetime.now(), - repoid=repo.repoid, - branch="main", - avg_duration_seconds=20.0, - ) - res = self.fetch_repository( - repo.name, - """testResults(filters: { parameter: SLOWEST_TESTS }) { edges { node { name } } }""", - ) - assert res["testResults"] == {"edges": [{"node": {"name": test2.name}}]} - - # TODO - remove this with #2291 - def test_flags_filter_on_test_results(self) -> None: - repo = RepositoryFactory(author=self.owner, active=True, private=True) - test = TestFactory(repository=repo) - test2 = TestFactory(repository=repo) - - repo_flag = RepositoryFlagFactory(repository=repo, flag_name="hello_world") - - _ = TestFlagBridgeFactory(flag=repo_flag, test=test) - _ = DailyTestRollupFactory( - test=test, - created_at=datetime.datetime.now(), - repoid=repo.repoid, - branch="main", - avg_duration_seconds=0.1, - ) - _ = DailyTestRollupFactory( - test=test2, - created_at=datetime.datetime.now(), - repoid=repo.repoid, - branch="main", - avg_duration_seconds=20.0, - ) - res = self.fetch_repository( - repo.name, - """testResults(filters: { flags: ["hello_world"] }) { edges { node { name } } }""", - ) - assert res["testResults"] == {"edges": [{"node": {"name": test.name}}]} - - # TODO - remove this with #2291 - def test_testsuites_filter_on_test_results(self) -> None: - repo = RepositoryFactory(author=self.owner, active=True, private=True) - test = TestFactory(repository=repo, testsuite="hello") - test2 = TestFactory(repository=repo, testsuite="world") - - _ = DailyTestRollupFactory( - test=test, - created_at=datetime.datetime.now(), - repoid=repo.repoid, - branch="main", - avg_duration_seconds=0.1, - ) - _ = DailyTestRollupFactory( - test=test2, - created_at=datetime.datetime.now(), - repoid=repo.repoid, - branch="main", - avg_duration_seconds=20.0, - ) - res = self.fetch_repository( - repo.name, - """testResults(filters: { test_suites: ["hello"] }) { edges { node { name } } }""", - ) - assert res["testResults"] == {"edges": [{"node": {"name": test.name}}]} - - # TODO - remove this with #2291 - def test_commits_failed_ordering_on_test_results(self) -> None: - repo = RepositoryFactory(author=self.owner, active=True, private=True) - test = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test, - date=datetime.date.today() - datetime.timedelta(days=1), - repoid=repo.repoid, - commits_where_fail=["1"], - ) - _ = DailyTestRollupFactory( - test=test, - date=datetime.date.today(), - repoid=repo.repoid, - commits_where_fail=["2"], - ) - test_2 = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test_2, - date=datetime.date.today(), - repoid=repo.repoid, - commits_where_fail=["3"], - ) - res = self.fetch_repository( - repo.name, - """testResults(ordering: { parameter: COMMITS_WHERE_FAIL, direction: ASC }) { edges { node { name commitsFailed } } }""", - ) - assert res["testResults"] == { - "edges": [ - {"node": {"name": test_2.name, "commitsFailed": 1}}, - {"node": {"name": test.name, "commitsFailed": 2}}, - ] - } - - # TODO - remove this with #2291 - def test_desc_commits_failed_ordering_on_test_results(self) -> None: - repo = RepositoryFactory(author=self.owner, active=True, private=True) - test = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test, - date=datetime.date.today() - datetime.timedelta(days=1), - repoid=repo.repoid, - commits_where_fail=["1"], - ) - _ = DailyTestRollupFactory( - test=test, - date=datetime.date.today(), - repoid=repo.repoid, - commits_where_fail=["2"], - ) - test_2 = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test_2, - date=datetime.date.today(), - repoid=repo.repoid, - commits_where_fail=["3"], - ) - res = self.fetch_repository( - repo.name, - """testResults(ordering: { parameter: COMMITS_WHERE_FAIL, direction: DESC }) { edges { node { name commitsFailed } } }""", - ) - assert res["testResults"] == { - "edges": [ - {"node": {"name": test.name, "commitsFailed": 2}}, - {"node": {"name": test_2.name, "commitsFailed": 1}}, - ] - } - - # TODO - remove this with #2291 - def test_last_duration_ordering_on_test_results(self) -> None: - repo = RepositoryFactory(author=self.owner, active=True, private=True) - test = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test, - date=datetime.date.today() - datetime.timedelta(days=1), - repoid=repo.repoid, - last_duration_seconds=1, - latest_run=datetime.datetime.now() - datetime.timedelta(days=1), - ) - _ = DailyTestRollupFactory( - test=test, - date=datetime.date.today(), - repoid=repo.repoid, - last_duration_seconds=2, - latest_run=datetime.datetime.now(), - ) - test_2 = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test_2, - date=datetime.date.today(), - repoid=repo.repoid, - last_duration_seconds=3, - ) - res = self.fetch_repository( - repo.name, - """testResults(ordering: { parameter: LAST_DURATION, direction: ASC }) { edges { node { name lastDuration } } }""", - ) - assert res["testResults"] == { - "edges": [ - {"node": {"name": test.name, "lastDuration": 2.0}}, - {"node": {"name": test_2.name, "lastDuration": 3.0}}, - ] - } - - # TODO - remove this with #2291 - def test_desc_last_duration_ordering_on_test_results(self) -> None: - repo = RepositoryFactory(author=self.owner, active=True, private=True) - test = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test, - date=datetime.date.today() - datetime.timedelta(days=1), - repoid=repo.repoid, - last_duration_seconds=1, - latest_run=datetime.datetime.now() - datetime.timedelta(days=1), - ) - _ = DailyTestRollupFactory( - test=test, - date=datetime.date.today(), - repoid=repo.repoid, - last_duration_seconds=2, - latest_run=datetime.datetime.now(), - ) - test_2 = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test_2, - date=datetime.date.today(), - repoid=repo.repoid, - last_duration_seconds=3, - ) - res = self.fetch_repository( - repo.name, - """testResults(ordering: { parameter: LAST_DURATION, direction: DESC }) { edges { node { name lastDuration } } }""", - ) - assert res["testResults"] == { - "edges": [ - {"node": {"name": test_2.name, "lastDuration": 3}}, - {"node": {"name": test.name, "lastDuration": 2}}, - ] - } - - # TODO - remove this with #2291 - def test_avg_duration_ordering_on_test_results(self) -> None: - repo = RepositoryFactory(author=self.owner, active=True, private=True) - test = TestFactory(repository=repo) - test = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test, - date=datetime.date.today() - datetime.timedelta(days=1), - repoid=repo.repoid, - avg_duration_seconds=1, - ) - _ = DailyTestRollupFactory( - test=test, - date=datetime.date.today(), - repoid=repo.repoid, - avg_duration_seconds=2, - ) - test_2 = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test_2, - date=datetime.date.today(), - repoid=repo.repoid, - avg_duration_seconds=3, - ) - res = self.fetch_repository( - repo.name, - """testResults(ordering: { parameter: AVG_DURATION, direction: ASC }) { edges { node { name avgDuration } } }""", - ) - assert res["testResults"] == { - "edges": [ - {"node": {"name": test.name, "avgDuration": 1.5}}, - {"node": {"name": test_2.name, "avgDuration": 3}}, - ] - } - - # TODO - remove this with #2291 - def test_desc_avg_duration_ordering_on_test_results(self) -> None: - repo = RepositoryFactory(author=self.owner, active=True, private=True) - test = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test, - date=datetime.date.today() - datetime.timedelta(days=1), - repoid=repo.repoid, - avg_duration_seconds=1, - ) - _ = DailyTestRollupFactory( - test=test, - date=datetime.date.today(), - repoid=repo.repoid, - avg_duration_seconds=2, - ) - test_2 = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test_2, - date=datetime.date.today(), - repoid=repo.repoid, - avg_duration_seconds=3, - ) - res = self.fetch_repository( - repo.name, - """testResults(ordering: { parameter: AVG_DURATION, direction: DESC }) { edges { node { name avgDuration } } }""", - ) - assert res["testResults"] == { - "edges": [ - {"node": {"name": test_2.name, "avgDuration": 3}}, - {"node": {"name": test.name, "avgDuration": 1.5}}, - ] - } - - # TODO - remove this with #2291 - def test_failure_rate_ordering_on_test_results(self) -> None: - repo = RepositoryFactory(author=self.owner, active=True, private=True) - test = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test, - date=datetime.date.today() - datetime.timedelta(days=1), - repoid=repo.repoid, - pass_count=1, - fail_count=1, - ) - _ = DailyTestRollupFactory( - test=test, - date=datetime.date.today(), - repoid=repo.repoid, - pass_count=3, - fail_count=0, - ) - test_2 = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test_2, - date=datetime.date.today(), - repoid=repo.repoid, - pass_count=2, - fail_count=3, - ) - res = self.fetch_repository( - repo.name, - """testResults(ordering: { parameter: FAILURE_RATE, direction: ASC }) { edges { node { name failureRate } } }""", - ) - - assert res["testResults"] == { - "edges": [ - {"node": {"name": test.name, "failureRate": 0.2}}, - {"node": {"name": test_2.name, "failureRate": 0.6}}, - ] - } - - # TODO - remove this with #2291 - def test_desc_failure_rate_ordering_on_test_results(self) -> None: - repo = RepositoryFactory(author=self.owner, active=True, private=True) - test = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test, - date=datetime.date.today() - datetime.timedelta(days=1), - repoid=repo.repoid, - pass_count=1, - fail_count=1, - ) - _ = DailyTestRollupFactory( - test=test, - date=datetime.date.today(), - repoid=repo.repoid, - pass_count=3, - fail_count=0, - ) - test_2 = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test_2, - date=datetime.date.today(), - repoid=repo.repoid, - pass_count=2, - fail_count=3, - ) - res = self.fetch_repository( - repo.name, - """testResults(ordering: { parameter: FAILURE_RATE, direction: DESC }) { edges { node { name failureRate } } }""", - ) - - assert res["testResults"] == { - "edges": [ - {"node": {"name": test_2.name, "failureRate": 0.6}}, - {"node": {"name": test.name, "failureRate": 0.2}}, - ] - } - - # TODO - remove this with #2291 - def test_flake_rate_filtering_on_test_results(self) -> None: - repo = RepositoryFactory(author=self.owner, active=True, private=True) - test = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test, - date=datetime.date.today() - datetime.timedelta(days=1), - repoid=repo.repoid, - pass_count=1, - fail_count=1, - flaky_fail_count=1, - ) - _ = DailyTestRollupFactory( - test=test, - date=datetime.date.today(), - repoid=repo.repoid, - pass_count=3, - fail_count=0, - flaky_fail_count=0, - ) - test_2 = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test_2, - date=datetime.date.today(), - repoid=repo.repoid, - pass_count=2, - fail_count=3, - flaky_fail_count=1, - ) - res = self.fetch_repository( - repo.name, - """testResults(ordering: { parameter: FAILURE_RATE, direction: ASC }) { edges { node { name flakeRate } } }""", - ) - - assert res["testResults"] == { - "edges": [ - {"node": {"name": test.name, "flakeRate": 0.2}}, - {"node": {"name": test_2.name, "flakeRate": 0.2}}, - ] - } - - # TODO - remove this with #2291 - def test_desc_flake_rate_ordering_on_test_results(self) -> None: - repo = RepositoryFactory(author=self.owner, active=True, private=True) - test = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test, - date=datetime.date.today() - datetime.timedelta(days=1), - repoid=repo.repoid, - pass_count=1, - fail_count=1, - flaky_fail_count=1, - ) - _ = DailyTestRollupFactory( - test=test, - date=datetime.date.today(), - repoid=repo.repoid, - pass_count=3, - fail_count=0, - flaky_fail_count=0, - ) - test_2 = TestFactory(repository=repo) - _ = DailyTestRollupFactory( - test=test_2, - date=datetime.date.today(), - repoid=repo.repoid, - pass_count=2, - fail_count=3, - flaky_fail_count=1, - ) - res = self.fetch_repository( - repo.name, - """testResults(ordering: { parameter: FAILURE_RATE, direction: DESC }) { edges { node { name flakeRate } } }""", - ) - - assert res["testResults"] == { - "edges": [ - {"node": {"name": test_2.name, "flakeRate": 0.2}}, - {"node": {"name": test.name, "flakeRate": 0.2}}, - ] - } diff --git a/graphql_api/tests/test_test_result_legacy.py b/graphql_api/tests/test_test_result_legacy.py deleted file mode 100644 index 27632ba0c9..0000000000 --- a/graphql_api/tests/test_test_result_legacy.py +++ /dev/null @@ -1,218 +0,0 @@ -# TODO - remove this file with #2291 -from datetime import UTC, date, datetime, timedelta - -from django.test import TransactionTestCase -from freezegun import freeze_time - -from codecov_auth.tests.factories import OwnerFactory -from core.tests.factories import RepositoryFactory -from reports.tests.factories import ( - DailyTestRollupFactory, - TestFactory, -) - -from .helper import GraphQLTestHelper - - -@freeze_time(datetime.now().isoformat()) -class TestResultTestCase(GraphQLTestHelper, TransactionTestCase): - def setUp(self): - self.owner = OwnerFactory(username="randomOwner") - self.repository = RepositoryFactory( - author=self.owner, - ) - self.test = TestFactory( - name="Test\x1fName", - repository=self.repository, - ) - - _ = DailyTestRollupFactory( - test=self.test, - commits_where_fail=["123"], - date=date.today() - timedelta(days=2), - avg_duration_seconds=0.6, - latest_run=datetime.now() - timedelta(days=2), - ) - _ = DailyTestRollupFactory( - test=self.test, - commits_where_fail=["123", "456"], - date=datetime.now() - timedelta(days=1), - avg_duration_seconds=2, - latest_run=datetime.now() - timedelta(days=1), - ) - _ = DailyTestRollupFactory( - test=self.test, - commits_where_fail=["123", "789"], - date=date.today(), - last_duration_seconds=5.0, - avg_duration_seconds=3, - latest_run=datetime.now(), - ) - - def test_fetch_test_result_name(self) -> None: - query = """ - query { - owner(username: "%s") { - repository(name: "%s") { - ... on Repository { - 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"]["testResults"]["edges"][0]["node"][ - "name" - ] == self.test.name.replace("\x1f", " ") - - def test_fetch_test_result_updated_at(self) -> None: - query = """ - query { - owner(username: "%s") { - repository(name: "%s") { - ... on Repository { - testResults { - edges { - node { - updatedAt - } - } - } - } - } - } - } - """ % (self.owner.username, self.repository.name) - - result = self.gql_request(query, owner=self.owner) - - assert "errors" not in result - assert ( - result["owner"]["repository"]["testResults"]["edges"][0]["node"][ - "updatedAt" - ] - == datetime.now(UTC).isoformat() - ) - - def test_fetch_test_result_commits_failed(self) -> None: - query = """ - query { - owner(username: "%s") { - repository(name: "%s") { - ... on Repository { - testResults { - edges { - node { - commitsFailed - } - } - } - } - } - } - } - """ % (self.owner.username, self.repository.name) - - result = self.gql_request(query, owner=self.owner) - - assert "errors" not in result - assert ( - result["owner"]["repository"]["testResults"]["edges"][0]["node"][ - "commitsFailed" - ] - == 3 - ) - - def test_fetch_test_result_failure_rate(self) -> None: - query = """ - query { - owner(username: "%s") { - repository(name: "%s") { - ... on Repository { - testResults { - edges { - node { - failureRate - } - } - } - } - } - } - } - """ % (self.owner.username, self.repository.name) - - result = self.gql_request(query, owner=self.owner) - - assert "errors" not in result - assert ( - result["owner"]["repository"]["testResults"]["edges"][0]["node"][ - "failureRate" - ] - == 0.75 - ) - - def test_fetch_test_result_last_duration(self) -> None: - query = """ - query { - owner(username: "%s") { - repository(name: "%s") { - ... on Repository { - testResults { - edges { - node { - lastDuration - } - } - } - } - } - } - } - """ % (self.owner.username, self.repository.name) - - result = self.gql_request(query, owner=self.owner) - - assert "errors" not in result - assert ( - result["owner"]["repository"]["testResults"]["edges"][0]["node"][ - "lastDuration" - ] - == 5.0 - ) - - def test_fetch_test_result_avg_duration(self) -> None: - query = """ - query { - owner(username: "%s") { - repository(name: "%s") { - ... on Repository { - testResults { - edges { - node { - avgDuration - } - } - } - } - } - } - } - """ % (self.owner.username, self.repository.name) - - result = self.gql_request(query, owner=self.owner) - - assert "errors" not in result - assert result["owner"]["repository"]["testResults"]["edges"][0]["node"][ - "avgDuration" - ] == (5.6 / 3) diff --git a/graphql_api/types/repository/repository.graphql b/graphql_api/types/repository/repository.graphql index ba211d39e4..962bb1d352 100644 --- a/graphql_api/types/repository/repository.graphql +++ b/graphql_api/types/repository/repository.graphql @@ -84,15 +84,6 @@ type Repository { componentsYaml(termId: String): [ComponentsYaml]! testAnalyticsEnabled: Boolean isGithubRateLimited: Boolean - # TODO - remove with #2291 - testResults( - filters: TestResultsFilters - ordering: TestResultsOrdering - first: Int - after: String - last: Int - before: String - ): TestResultConnection! @cost(complexity: 10, multipliers: ["first", "last"]) "CoverageAnalytics are fields related to Codecov's Coverage product offering" coverageAnalytics: CoverageAnalytics diff --git a/graphql_api/types/repository/repository.py b/graphql_api/types/repository/repository.py index fab3125979..e0eed1c399 100644 --- a/graphql_api/types/repository/repository.py +++ b/graphql_api/types/repository/repository.py @@ -1,5 +1,5 @@ import logging -from datetime import datetime, timedelta +from datetime import datetime from typing import List, Mapping, Optional import shared.rate_limits as rate_limits @@ -29,17 +29,12 @@ from graphql_api.types.coverage_analytics.coverage_analytics import ( CoverageAnalyticsProps, ) -from graphql_api.types.enums import OrderingDirection, TestResultsFilterParameter -from graphql_api.types.enums.enum_types import MeasurementInterval +from graphql_api.types.enums import OrderingDirection from graphql_api.types.errors.errors import NotFoundError, OwnerNotActivatedError from services.components import ComponentMeasurements from services.profiling import CriticalFile, ProfilingSummary from services.redis_configuration import get_redis_connection from timeseries.models import Dataset, Interval, MeasurementName -from utils.test_results import ( - GENERATE_TEST_RESULT_PARAM, - generate_test_results, -) log = logging.getLogger(__name__) @@ -526,81 +521,6 @@ def resolve_is_github_rate_limited(repository: Repository, info) -> bool | None: return None -# TODO - remove with #2291 -def convert_history_to_timedelta(interval: MeasurementInterval | None) -> timedelta: - if interval is None: - return timedelta(days=30) - - match interval: - case MeasurementInterval.INTERVAL_1_DAY: - return timedelta(days=1) - case MeasurementInterval.INTERVAL_7_DAY: - return timedelta(days=7) - case MeasurementInterval.INTERVAL_30_DAY: - return timedelta(days=30) - - -# TODO - remove with #2291 -def convert_test_results_filter_parameter( - parameter: TestResultsFilterParameter | None, -) -> GENERATE_TEST_RESULT_PARAM | None: - if parameter is None: - return None - - match parameter: - case TestResultsFilterParameter.FLAKY_TESTS: - return GENERATE_TEST_RESULT_PARAM.FLAKY - case TestResultsFilterParameter.FAILED_TESTS: - return GENERATE_TEST_RESULT_PARAM.FAILED - case TestResultsFilterParameter.SLOWEST_TESTS: - return GENERATE_TEST_RESULT_PARAM.SLOWEST - case TestResultsFilterParameter.SKIPPED_TESTS: - return GENERATE_TEST_RESULT_PARAM.SKIPPED - - -# TODO - remove with #2291 -@repository_bindable.field("testResults") -async def resolve_test_results( - repository: Repository, - info: GraphQLResolveInfo, - ordering=None, - filters=None, - **kwargs, -): - parameter = ( - convert_test_results_filter_parameter(filters.get("parameter")) - if filters - else None - ) - history = ( - convert_history_to_timedelta(filters.get("history")) - if filters - else timedelta(days=30) - ) - - queryset = await sync_to_async(generate_test_results)( - repoid=repository.repoid, - history=history, - branch=filters.get("branch") if filters else None, - parameter=parameter, - testsuites=filters.get("test_suites") if filters else None, - flags=filters.get("flags") if filters else None, - ) - - return await queryset_to_connection( - queryset, - ordering=( - (ordering.get("parameter"), "name") - if ordering - else ("avg_duration", "name") - ), - ordering_direction=( - ordering.get("direction") if ordering else OrderingDirection.DESC - ), - **kwargs, - ) - - @repository_bindable.field("coverageAnalytics") def resolve_coverage_analytics( repository: Repository, From 38d71b1271bbb9fee322500164d0059acd001e5a Mon Sep 17 00:00:00 2001 From: Suejung Shin Date: Tue, 8 Oct 2024 14:59:20 -0700 Subject: [PATCH 2/2] remove test_result_legacy --- graphql_api/tests/test_test_result_legacy.py | 218 ------------------- 1 file changed, 218 deletions(-) delete mode 100644 graphql_api/tests/test_test_result_legacy.py diff --git a/graphql_api/tests/test_test_result_legacy.py b/graphql_api/tests/test_test_result_legacy.py deleted file mode 100644 index 8e5b9c0c13..0000000000 --- a/graphql_api/tests/test_test_result_legacy.py +++ /dev/null @@ -1,218 +0,0 @@ -# TODO - remove this file with #2291 -from datetime import UTC, date, datetime, timedelta - -from django.test import TransactionTestCase -from freezegun import freeze_time - -from codecov_auth.tests.factories import OwnerFactory -from core.tests.factories import RepositoryFactory -from reports.tests.factories import ( - DailyTestRollupFactory, - TestFactory, -) - -from .helper import GraphQLTestHelper - - -@freeze_time(datetime.now().isoformat()) -class TestResultTestCase(GraphQLTestHelper, TransactionTestCase): - def setUp(self): - self.owner = OwnerFactory(username="randomOwner") - self.repository = RepositoryFactory( - author=self.owner, - ) - self.test = TestFactory( - name="Test\x1fName", - repository=self.repository, - ) - - _ = DailyTestRollupFactory( - test=self.test, - commits_where_fail=["123"], - date=date.today() - timedelta(days=2), - avg_duration_seconds=0.6, - latest_run=datetime.now() - timedelta(days=2), - ) - _ = DailyTestRollupFactory( - test=self.test, - commits_where_fail=["123", "456"], - date=datetime.now() - timedelta(days=1), - avg_duration_seconds=2, - latest_run=datetime.now() - timedelta(days=1), - ) - _ = DailyTestRollupFactory( - test=self.test, - commits_where_fail=["123", "789"], - date=date.today(), - last_duration_seconds=5.0, - avg_duration_seconds=3, - latest_run=datetime.now(), - ) - - def test_fetch_test_result_name(self) -> None: - query = """ - query { - owner(username: "%s") { - repository(name: "%s") { - ... on Repository { - 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"]["testResults"]["edges"][0]["node"][ - "name" - ] == self.test.name.replace("\x1f", " ") - - def test_fetch_test_result_updated_at(self) -> None: - query = """ - query { - owner(username: "%s") { - repository(name: "%s") { - ... on Repository { - testResults { - edges { - node { - updatedAt - } - } - } - } - } - } - } - """ % (self.owner.username, self.repository.name) - - result = self.gql_request(query, owner=self.owner) - - assert "errors" not in result - assert ( - result["owner"]["repository"]["testResults"]["edges"][0]["node"][ - "updatedAt" - ] - == datetime.now(UTC).isoformat() - ) - - def test_fetch_test_result_commits_failed(self) -> None: - query = """ - query { - owner(username: "%s") { - repository(name: "%s") { - ... on Repository { - testResults { - edges { - node { - commitsFailed - } - } - } - } - } - } - } - """ % (self.owner.username, self.repository.name) - - result = self.gql_request(query, owner=self.owner) - - assert "errors" not in result - assert ( - result["owner"]["repository"]["testResults"]["edges"][0]["node"][ - "commitsFailed" - ] - == 3 - ) - - def test_fetch_test_result_failure_rate(self) -> None: - query = """ - query { - owner(username: "%s") { - repository(name: "%s") { - ... on Repository { - testResults { - edges { - node { - failureRate - } - } - } - } - } - } - } - """ % (self.owner.username, self.repository.name) - - result = self.gql_request(query, owner=self.owner) - - assert "errors" not in result - assert ( - result["owner"]["repository"]["testResults"]["edges"][0]["node"][ - "failureRate" - ] - == 0.75 - ) - - def test_fetch_test_result_last_duration(self) -> None: - query = """ - query { - owner(username: "%s") { - repository(name: "%s") { - ... on Repository { - testResults { - edges { - node { - lastDuration - } - } - } - } - } - } - } - """ % (self.owner.username, self.repository.name) - - result = self.gql_request(query, owner=self.owner) - - assert "errors" not in result - assert ( - result["owner"]["repository"]["testResults"]["edges"][0]["node"][ - "lastDuration" - ] - == 0.0 - ) - - def test_fetch_test_result_avg_duration(self) -> None: - query = """ - query { - owner(username: "%s") { - repository(name: "%s") { - ... on Repository { - testResults { - edges { - node { - avgDuration - } - } - } - } - } - } - } - """ % (self.owner.username, self.repository.name) - - result = self.gql_request(query, owner=self.owner) - - assert "errors" not in result - assert result["owner"]["repository"]["testResults"]["edges"][0]["node"][ - "avgDuration" - ] == (5.6 / 3)