Example #1
0
    def test_cost_usage_source_is_reachable_bad_iam_token(self, usage_reports):
        """Test that cost_usage_source_is_reachable raises ValidationError on invalid IAM token."""
        service = MagicMock()
        service.get_resource_usage_report.side_effect = ApiException(
            code=400, message="API key is wrong")
        usage_reports.return_value = service

        provider = IBMProvider()
        creds = {"iam_token": FAKE.word()}
        billing = {"enterprise_id": FAKE.word()}

        with self.assertRaises(ValidationError) as ve:
            provider.cost_usage_source_is_reachable(creds, billing)
        self.assertIsNotNone(ve.exception.get_full_details().get(
            "credentials.iam_token", None))
Example #2
0
    def test_cost_usage_source_is_reachable_success(self, usage_reports):
        """Test that cost_usage_source_is_reachable succeeds."""
        service = MagicMock()
        usage_reports.return_value = service

        provider = IBMProvider()
        creds = {"iam_token": FAKE.word()}
        billing = {"enterprise_id": FAKE.word()}

        self.assertTrue(provider.cost_usage_source_is_reachable(
            creds, billing))
        service.get_resource_usage_report.assert_called_with(
            enterprise_id=billing.get("enterprise_id"), children=True, limit=1)