|
45 | 45 | ComplianceRequirementOverview, |
46 | 46 | DailySeveritySummary, |
47 | 47 | Finding, |
| 48 | + FindingGroupDailySummary, |
48 | 49 | Integration, |
49 | 50 | Invitation, |
50 | 51 | LighthouseProviderConfiguration, |
@@ -14689,10 +14690,16 @@ def test_mute_rule_ordering( |
14689 | 14690 | assert len(data) == 2 |
14690 | 14691 | assert data[0]["id"] == str(mute_rules_fixture[first_index].id) |
14691 | 14692 |
|
14692 | | - @patch("tasks.tasks.mute_historical_findings_task.apply_async") |
| 14693 | + @patch("api.v1.views.chain") |
| 14694 | + @patch("api.v1.views.aggregate_finding_group_summaries_task.si") |
| 14695 | + @patch("api.v1.views.mute_historical_findings_task.si") |
| 14696 | + @patch("api.v1.views.transaction.on_commit", side_effect=lambda fn: fn()) |
14693 | 14697 | def test_mute_rules_create_valid( |
14694 | 14698 | self, |
14695 | | - mock_task, |
| 14699 | + _mock_on_commit, |
| 14700 | + mock_mute_signature, |
| 14701 | + mock_aggregate_signature, |
| 14702 | + mock_chain, |
14696 | 14703 | authenticated_client, |
14697 | 14704 | findings_fixture, |
14698 | 14705 | create_test_user, |
@@ -14730,8 +14737,14 @@ def test_mute_rules_create_valid( |
14730 | 14737 | assert finding.muted_at is not None |
14731 | 14738 | assert finding.muted_reason == "Security exception approved" |
14732 | 14739 |
|
14733 | | - # Verify background task was called |
14734 | | - mock_task.assert_called_once() |
| 14740 | + # Verify background task chain was called |
| 14741 | + mock_mute_signature.assert_called_once() |
| 14742 | + mock_aggregate_signature.assert_called_once() |
| 14743 | + mock_chain.assert_called_once_with( |
| 14744 | + mock_mute_signature.return_value, |
| 14745 | + mock_aggregate_signature.return_value, |
| 14746 | + ) |
| 14747 | + mock_chain.return_value.apply_async.assert_called_once() |
14735 | 14748 |
|
14736 | 14749 | @patch("tasks.tasks.mute_historical_findings_task.apply_async") |
14737 | 14750 | def test_mute_rules_create_converts_finding_ids_to_uids( |
@@ -15840,6 +15853,48 @@ def test_finding_groups_latest_provider_id_filter( |
15840 | 15853 | assert len(data) == 1 |
15841 | 15854 | assert data[0]["id"] == "cloudtrail_enabled" |
15842 | 15855 |
|
| 15856 | + def test_finding_groups_latest_aggregates_latest_per_provider( |
| 15857 | + self, authenticated_client, providers_fixture |
| 15858 | + ): |
| 15859 | + """Test /latest aggregates latest summary from each provider for the same check.""" |
| 15860 | + provider1 = providers_fixture[0] |
| 15861 | + provider2 = providers_fixture[1] |
| 15862 | + |
| 15863 | + check_id = "cross_provider_latest_resources_total" |
| 15864 | + now = datetime.now(timezone.utc).replace(minute=0, second=0, microsecond=0) |
| 15865 | + |
| 15866 | + FindingGroupDailySummary.objects.create( |
| 15867 | + tenant_id=provider1.tenant_id, |
| 15868 | + provider=provider1, |
| 15869 | + check_id=check_id, |
| 15870 | + inserted_at=now - timedelta(days=1), |
| 15871 | + resources_total=20, |
| 15872 | + resources_fail=20, |
| 15873 | + fail_count=20, |
| 15874 | + ) |
| 15875 | + FindingGroupDailySummary.objects.create( |
| 15876 | + tenant_id=provider2.tenant_id, |
| 15877 | + provider=provider2, |
| 15878 | + check_id=check_id, |
| 15879 | + inserted_at=now, |
| 15880 | + resources_total=7, |
| 15881 | + resources_fail=7, |
| 15882 | + fail_count=7, |
| 15883 | + ) |
| 15884 | + |
| 15885 | + response = authenticated_client.get( |
| 15886 | + reverse("finding-group-latest"), |
| 15887 | + {"filter[check_id]": check_id}, |
| 15888 | + ) |
| 15889 | + |
| 15890 | + assert response.status_code == status.HTTP_200_OK |
| 15891 | + data = response.json()["data"] |
| 15892 | + assert len(data) == 1 |
| 15893 | + attrs = data[0]["attributes"] |
| 15894 | + assert attrs["resources_total"] == 27 |
| 15895 | + assert attrs["resources_fail"] == 27 |
| 15896 | + assert attrs["fail_count"] == 27 |
| 15897 | + |
15843 | 15898 | def test_finding_groups_latest_provider_type_filter( |
15844 | 15899 | self, authenticated_client, finding_groups_fixture |
15845 | 15900 | ): |
|
0 commit comments