def test_load_providers_to_update(self): """Test loading pending update events.""" test_matrix = [{'koku_uuid': faker.uuid4(), 'pending_update': False, 'pending_delete': False, 'expected_list_length': 0}, {'koku_uuid': faker.uuid4(), 'pending_update': True, 'pending_delete': False, 'expected_list_length': 1}, {'koku_uuid': None, 'pending_update': True, 'pending_delete': False, 'expected_list_length': 0}] test_source_id = 3 for test in test_matrix: aws_obj = Sources(source_id=test_source_id, auth_header=self.test_header, koku_uuid=test.get('koku_uuid'), pending_update=test.get('pending_update'), pending_delete=test.get('pending_delete'), offset=3, endpoint_id=4, source_type='AWS', name='Test AWS Source', billing_source={'bucket': 'test-bucket'}) aws_obj.save() response = storage.load_providers_to_update() self.assertEquals(len(response), test.get('expected_list_length')) test_source_id += 1 aws_obj.delete()
def test_update_aws_billing_source(self): """Test to validate that the billing source dictionary is updated.""" aws_instance = Sources( source_id=3, auth_header=self.test_header, offset=3, source_type=Provider.PROVIDER_AWS, name="Test AWS Source", billing_source={"data_source": {"bucket": "my_s3_bucket"}}, ) aws_instance.save() test_matrix = [ { "instance": aws_instance, "billing_source": {"bucket": "test-bucket"}, "expected": {"data_source": {"bucket": "test-bucket"}}, }, { "instance": aws_instance, "billing_source": {"data_source": {"bucket": "test-bucket"}}, "expected": {"data_source": {"bucket": "test-bucket"}}, }, ] for test in test_matrix: with self.subTest(test=test): try: new_billing = storage._update_billing_source(aws_instance, test.get("billing_source")) self.assertEqual(new_billing, test.get("expected")) except Exception as error: self.fail(str(error)) aws_instance.delete()
def test_load_providers_to_update(self): """Test loading pending update events.""" test_matrix = [ {"koku_uuid": faker.uuid4(), "pending_update": False, "pending_delete": False, "expected_list_length": 0}, {"koku_uuid": faker.uuid4(), "pending_update": True, "pending_delete": False, "expected_list_length": 1}, {"koku_uuid": None, "pending_update": True, "pending_delete": False, "expected_list_length": 0}, ] test_source_id = 3 for test in test_matrix: aws_obj = Sources( source_id=test_source_id, auth_header=self.test_header, koku_uuid=test.get("koku_uuid"), pending_update=test.get("pending_update"), pending_delete=test.get("pending_delete"), offset=3, source_type=Provider.PROVIDER_AWS, name="Test AWS Source", billing_source={"bucket": "test-bucket"}, ) aws_obj.save() response = storage.load_providers_to_update() self.assertEquals(len(response), test.get("expected_list_length")) test_source_id += 1 aws_obj.delete()
def test_execute_source_status_beat_missing(self): """Test to execute the beat source status when a source is missing.""" source_id_local = self.aws_local_source.get("source_id") provider = Sources(**self.aws_local_source) provider.save() provider.delete() self.assertEqual( Sources.objects.filter(source_id=source_id_local).exists(), False) with patch.object(SourceStatus, "push_status") as mock_push: source_status_beat() mock_push.assert_not_called()
def test_update_azure_billing_source(self): """Test to validate that the billing source dictionary is updated.""" azure_instance = Sources( source_id=4, auth_header=self.test_header, offset=3, source_type=Provider.PROVIDER_AZURE, name="Test Azure Source", billing_source={"data_source": {"resource_group": "original-1", "storage_account": "original-2"}}, ) azure_instance.save() test_matrix = [ { "instance": azure_instance, "billing_source": {"data_source": {"resource_group": "foo", "storage_account": "bar"}}, "expected": {"data_source": {"resource_group": "foo", "storage_account": "bar"}}, }, { "instance": azure_instance, "billing_source": {"data_source": {"resource_group": "foo"}}, "expected": {"data_source": {"resource_group": "foo", "storage_account": "original-2"}}, }, { "instance": azure_instance, "billing_source": {"data_source": {"storage_account": "bar"}}, "expected": {"data_source": {"resource_group": "original-1", "storage_account": "bar"}}, }, ] for test in test_matrix: with self.subTest(test=test): try: new_billing = storage._update_billing_source(azure_instance, test.get("billing_source")) self.assertEqual(new_billing, test.get("expected")) except Exception as error: self.fail(str(error)) azure_instance.delete()