|
3 | 3 | # SPDX-License-Identifier: Apache-2.0
|
4 | 4 | #
|
5 | 5 | """Test Reporting Common."""
|
| 6 | +from unittest.mock import patch |
| 7 | + |
6 | 8 | from django.utils import timezone
|
| 9 | +from django_tenants.utils import schema_context |
7 | 10 |
|
| 11 | +from api.models import Provider |
| 12 | +from api.utils import DateHelper |
| 13 | +from masu.processor.tasks import delayed_summarize_current_month |
| 14 | +from masu.processor.tasks import UPDATE_SUMMARY_TABLES_QUEUE |
| 15 | +from masu.processor.tasks import UPDATE_SUMMARY_TABLES_QUEUE_XL |
| 16 | +from masu.processor.tasks import UPDATE_SUMMARY_TABLES_TASK |
8 | 17 | from masu.test import MasuTestCase
|
9 | 18 | from reporting_common.models import CombinedChoices
|
10 | 19 | from reporting_common.models import CostUsageReportManifest
|
11 | 20 | from reporting_common.models import CostUsageReportStatus
|
| 21 | +from reporting_common.models import DelayedCeleryTasks |
12 | 22 |
|
13 | 23 |
|
14 | 24 | class TestCostUsageReportStatus(MasuTestCase):
|
@@ -107,3 +117,42 @@ def test_set_failed_status(self):
|
107 | 117 | stats.update_status(CombinedChoices.FAILED)
|
108 | 118 | self.assertIsNotNone(stats.failed_status)
|
109 | 119 | self.assertEqual(stats.status, CombinedChoices.FAILED)
|
| 120 | + |
| 121 | + @patch("masu.processor.tasks.is_customer_large") |
| 122 | + def test_delayed_summarize_current_month(self, mock_large_customer): |
| 123 | + mock_large_customer.return_value = False |
| 124 | + test_matrix = { |
| 125 | + Provider.PROVIDER_AWS: self.aws_provider, |
| 126 | + Provider.PROVIDER_AZURE: self.azure_provider, |
| 127 | + Provider.PROVIDER_GCP: self.gcp_provider, |
| 128 | + Provider.PROVIDER_OCI: self.oci_provider, |
| 129 | + Provider.PROVIDER_OCP: self.ocp_provider, |
| 130 | + } |
| 131 | + count = 0 |
| 132 | + for test_provider_type, test_provider in test_matrix.items(): |
| 133 | + with self.subTest(test_provider_type=test_provider_type, test_provider=test_provider): |
| 134 | + with schema_context(self.schema): |
| 135 | + delayed_summarize_current_month(self.schema_name, [test_provider.uuid], test_provider_type) |
| 136 | + count += 1 |
| 137 | + self.assertEqual(DelayedCeleryTasks.objects.all().count(), count) |
| 138 | + db_entry = DelayedCeleryTasks.objects.get(provider_uuid=test_provider.uuid) |
| 139 | + self.assertEqual(db_entry.task_name, UPDATE_SUMMARY_TABLES_TASK) |
| 140 | + self.assertTrue( |
| 141 | + db_entry.task_kwargs, |
| 142 | + { |
| 143 | + "provider_type": test_provider_type, |
| 144 | + "provider_uuid": str(test_provider.uuid), |
| 145 | + "start_date": str(DateHelper().this_month_start), |
| 146 | + }, |
| 147 | + ) |
| 148 | + |
| 149 | + self.assertEqual(db_entry.task_args, [self.schema_name]) |
| 150 | + self.assertEqual(db_entry.queue_name, UPDATE_SUMMARY_TABLES_QUEUE) |
| 151 | + |
| 152 | + @patch("masu.processor.tasks.is_customer_large") |
| 153 | + def test_large_customer(self, mock_large_customer): |
| 154 | + mock_large_customer.return_value = True |
| 155 | + delayed_summarize_current_month(self.schema_name, [self.aws_provider.uuid], Provider.PROVIDER_AWS) |
| 156 | + with schema_context(self.schema): |
| 157 | + db_entry = DelayedCeleryTasks.objects.get(provider_uuid=self.aws_provider.uuid) |
| 158 | + self.assertEqual(db_entry.queue_name, UPDATE_SUMMARY_TABLES_QUEUE_XL) |
0 commit comments