|
3 | 3 |
|
4 | 4 | from django.test import TransactionTestCase, override_settings |
5 | 5 | from freezegun import freeze_time |
| 6 | +from shared.django_apps.reports.tests.factories import FlakeFactory |
6 | 7 |
|
7 | 8 | from codecov_auth.tests.factories import OwnerFactory |
8 | 9 | from core.tests.factories import ( |
@@ -918,6 +919,105 @@ def test_branch_filter_on_test_results(self) -> None: |
918 | 919 | ) |
919 | 920 | assert res["testResults"] == {"edges": [{"node": {"name": test.name}}]} |
920 | 921 |
|
| 922 | + def test_flaky_filter_on_test_results(self) -> None: |
| 923 | + repo = RepositoryFactory(author=self.owner, active=True, private=True) |
| 924 | + test = TestFactory(repository=repo) |
| 925 | + test2 = TestFactory(repository=repo) |
| 926 | + _ = FlakeFactory(test=test2, repository=repo, end_date=None) |
| 927 | + _ = DailyTestRollupFactory( |
| 928 | + test=test, |
| 929 | + created_at=datetime.datetime.now(), |
| 930 | + repoid=repo.repoid, |
| 931 | + branch="main", |
| 932 | + ) |
| 933 | + _ = DailyTestRollupFactory( |
| 934 | + test=test2, |
| 935 | + created_at=datetime.datetime.now(), |
| 936 | + repoid=repo.repoid, |
| 937 | + branch="feature", |
| 938 | + ) |
| 939 | + res = self.fetch_repository( |
| 940 | + repo.name, |
| 941 | + """testResults(filters: { parameter: FLAKY_TESTS }) { edges { node { name } } }""", |
| 942 | + ) |
| 943 | + assert res["testResults"] == {"edges": [{"node": {"name": test2.name}}]} |
| 944 | + |
| 945 | + def test_failed_filter_on_test_results(self) -> None: |
| 946 | + repo = RepositoryFactory(author=self.owner, active=True, private=True) |
| 947 | + test = TestFactory(repository=repo) |
| 948 | + test2 = TestFactory(repository=repo) |
| 949 | + _ = DailyTestRollupFactory( |
| 950 | + test=test, |
| 951 | + created_at=datetime.datetime.now(), |
| 952 | + repoid=repo.repoid, |
| 953 | + branch="main", |
| 954 | + fail_count=0, |
| 955 | + ) |
| 956 | + _ = DailyTestRollupFactory( |
| 957 | + test=test2, |
| 958 | + created_at=datetime.datetime.now(), |
| 959 | + repoid=repo.repoid, |
| 960 | + branch="feature", |
| 961 | + fail_count=1000, |
| 962 | + ) |
| 963 | + res = self.fetch_repository( |
| 964 | + repo.name, |
| 965 | + """testResults(filters: { parameter: FAILED_TESTS }) { edges { node { name } } }""", |
| 966 | + ) |
| 967 | + assert res["testResults"] == {"edges": [{"node": {"name": test2.name}}]} |
| 968 | + |
| 969 | + def test_skipped_filter_on_test_results(self) -> None: |
| 970 | + repo = RepositoryFactory(author=self.owner, active=True, private=True) |
| 971 | + test = TestFactory(repository=repo) |
| 972 | + test2 = TestFactory(repository=repo) |
| 973 | + _ = DailyTestRollupFactory( |
| 974 | + test=test, |
| 975 | + created_at=datetime.datetime.now(), |
| 976 | + repoid=repo.repoid, |
| 977 | + branch="main", |
| 978 | + skip_count=10, |
| 979 | + pass_count=10, |
| 980 | + fail_count=10, |
| 981 | + ) |
| 982 | + _ = DailyTestRollupFactory( |
| 983 | + test=test2, |
| 984 | + created_at=datetime.datetime.now(), |
| 985 | + repoid=repo.repoid, |
| 986 | + branch="feature", |
| 987 | + skip_count=1000, |
| 988 | + pass_count=0, |
| 989 | + fail_count=0, |
| 990 | + ) |
| 991 | + res = self.fetch_repository( |
| 992 | + repo.name, |
| 993 | + """testResults(filters: { parameter: SKIPPED_TESTS }) { edges { node { name } } }""", |
| 994 | + ) |
| 995 | + assert res["testResults"] == {"edges": [{"node": {"name": test2.name}}]} |
| 996 | + |
| 997 | + def test_slowest_filter_on_test_results(self) -> None: |
| 998 | + repo = RepositoryFactory(author=self.owner, active=True, private=True) |
| 999 | + test = TestFactory(repository=repo) |
| 1000 | + test2 = TestFactory(repository=repo) |
| 1001 | + _ = DailyTestRollupFactory( |
| 1002 | + test=test, |
| 1003 | + created_at=datetime.datetime.now(), |
| 1004 | + repoid=repo.repoid, |
| 1005 | + branch="main", |
| 1006 | + avg_duration_seconds=0.1, |
| 1007 | + ) |
| 1008 | + _ = DailyTestRollupFactory( |
| 1009 | + test=test2, |
| 1010 | + created_at=datetime.datetime.now(), |
| 1011 | + repoid=repo.repoid, |
| 1012 | + branch="main", |
| 1013 | + avg_duration_seconds=20.0, |
| 1014 | + ) |
| 1015 | + res = self.fetch_repository( |
| 1016 | + repo.name, |
| 1017 | + """testResults(filters: { parameter: SLOWEST_TESTS }) { edges { node { name } } }""", |
| 1018 | + ) |
| 1019 | + assert res["testResults"] == {"edges": [{"node": {"name": test2.name}}]} |
| 1020 | + |
921 | 1021 | def test_commits_failed_ordering_on_test_results(self) -> None: |
922 | 1022 | repo = RepositoryFactory(author=self.owner, active=True, private=True) |
923 | 1023 | test = TestFactory(repository=repo) |
@@ -1294,11 +1394,11 @@ def test_test_results_aggregates(self) -> None: |
1294 | 1394 | ) |
1295 | 1395 | res = self.fetch_repository( |
1296 | 1396 | repo.name, |
1297 | | - """testResultsHeaders { totalRunTime, slowestTestsRunTime, totalFails, totalSkips }""", |
| 1397 | + """testResultsAggregates { totalRunTime, slowestTestsRunTime, totalFails, totalSkips }""", |
1298 | 1398 | ) |
1299 | | - assert res["testResultsHeaders"] == { |
1300 | | - "totalRunTime": 5940.0, |
1301 | | - "slowestTestsRunTime": 850.0, |
| 1399 | + assert res["testResultsAggregates"] == { |
| 1400 | + "totalRunTime": 5900.0, |
| 1401 | + "slowestTestsRunTime": 580.0, |
1302 | 1402 | "totalFails": 20, |
1303 | 1403 | "totalSkips": 10, |
1304 | 1404 | } |
0 commit comments