def test_create_with_incomplete_source(self): """Test that provider is not created when source is incomplete.""" create_or_update_provider(self.aws_source.source_id) self.assertFalse(Provider.objects.filter(uuid=self.aws_source.source_uuid).exists()) create_or_update_provider(self.azure_source.source_id) self.assertFalse(Provider.objects.filter(uuid=self.azure_source.source_uuid).exists())
def test_set_status(self, mock_call, mock_status, __): """Test that set status is called when source exists.""" self.aws_source.billing_source = BILLING_SOURCES.get(Provider.PROVIDER_AWS) self.aws_source.authentication = AUTHENTICATIONS.get(Provider.PROVIDER_AWS) self.aws_source.save() with patch.object(ProviderAccessor, "cost_usage_source_ready", returns=True): create_or_update_provider(self.aws_source.source_id) mock_call.assert_called()
def test_create_with_complete_source_validation_error(self, mock_status, __): """Test that provider is created when source is complete and source status is saved.""" self.aws_source.billing_source = BILLING_SOURCES.get(Provider.PROVIDER_AWS) self.aws_source.authentication = AUTHENTICATIONS.get(Provider.PROVIDER_AWS) self.aws_source.save() logging.disable(logging.ERROR) create_or_update_provider(self.aws_source.source_id) self.assertFalse(Provider.objects.filter(uuid=self.aws_source.source_uuid).exists()) source = Sources.objects.get(source_id=self.aws_source_info.get("source_id")) self.assertEqual(source.status.get("availability_status"), "unavailable")
def test_create_with_complete_source(self, mock_status, __): """Test that provider is created when source is complete and source status is saved.""" self.aws_source.billing_source = BILLING_SOURCES.get(Provider.PROVIDER_AWS) self.aws_source.authentication = AUTHENTICATIONS.get(Provider.PROVIDER_AWS) self.aws_source.save() with patch.object(ProviderAccessor, "cost_usage_source_ready", returns=True): create_or_update_provider(self.aws_source.source_id) self.assertTrue(Provider.objects.filter(uuid=self.aws_source.source_uuid).exists()) source = Sources.objects.get(source_id=self.aws_source_info.get("source_id")) self.assertEqual(source.status.get("availability_status"), "available") self.azure_source.billing_source = BILLING_SOURCES.get(Provider.PROVIDER_AZURE) self.azure_source.authentication = AUTHENTICATIONS.get(Provider.PROVIDER_AZURE) self.azure_source.save() with patch.object(ProviderAccessor, "cost_usage_source_ready", returns=True): create_or_update_provider(self.azure_source.source_id) self.assertTrue(Provider.objects.filter(uuid=self.azure_source.source_uuid).exists()) source = Sources.objects.get(source_id=self.azure_source_info.get("source_id")) self.assertEqual(source.status.get("availability_status"), "available")
def test_create_with_nonexistent_source(self): """Test that provider is not created when source is not real.""" logging.disable(logging.NOTSET) with self.assertLogs(logger="sources.tasks", level="ERROR"): create_or_update_provider(3)