import unittest

from scripts.provider_conformance_gate import (
    is_daily_quota_error,
    is_transient_provider_error,
)
from policyfaultbench.providers.base import ProviderError


class GateQuotaTests(unittest.TestCase):
    def test_gemini_free_tier_daily_quota_is_detected(self):
        error = ProviderError(
            "Provider returned HTTP 429: Quota exceeded for metric: "
            "generativelanguage.googleapis.com/"
            "generate_content_free_tier_requests, limit: 20"
        )
        self.assertTrue(is_daily_quota_error(error))
        self.assertTrue(is_transient_provider_error(error))

    def test_ordinary_transient_error_is_not_daily_quota(self):
        error = ProviderError("Provider returned HTTP 503: unavailable")
        self.assertFalse(is_daily_quota_error(error))
        self.assertTrue(is_transient_provider_error(error))

    def test_fixed_provider_error_is_not_transient(self):
        error = ProviderError("Provider returned HTTP 400: invalid request")
        self.assertFalse(is_daily_quota_error(error))
        self.assertFalse(is_transient_provider_error(error))


if __name__ == "__main__":
    unittest.main()
