-
Notifications
You must be signed in to change notification settings - Fork 1
Test Mapping
Auto-generated from test files in
tests/. Do not edit manually.Generated: 2026-04-23 | Source:
scripts/wiki/generate_test_mapping.py
| Metric | Count |
|---|---|
| Test files | 200 |
| Test classes | 654 |
| Test functions | 3013 |
| Test directories | 22 |
| Directory | Files | Classes | Functions |
|---|---|---|---|
tests/benchmarks |
4 | 21 | 70 |
tests/billing |
1 | 0 | 16 |
tests/conceptual_model |
16 | 61 | 162 |
tests/config |
5 | 17 | 80 |
tests/db |
16 | 41 | 239 |
tests/e2e |
8 | 17 | 125 |
tests/integration |
34 | 96 | 326 |
tests/middleware |
3 | 17 | 62 |
tests/routes |
17 | 32 | 121 |
tests/schemas |
10 | 16 | 113 |
tests/security |
6 | 22 | 113 |
tests/services |
55 | 228 | 1169 |
tests/smoke |
1 | 9 | 20 |
tests/test_auth_timeout_fixes.py |
1 | 4 | 17 |
tests/test_bot_filter_span_processor.py |
1 | 3 | 19 |
tests/test_health_alerting.py |
1 | 0 | 21 |
tests/test_jwt_id_token_unit.py |
1 | 1 | 3 |
tests/test_observability_middleware.py |
1 | 8 | 34 |
tests/test_prometheus_metrics.py |
1 | 5 | 23 |
tests/test_status_page.py |
1 | 0 | 19 |
tests/unit |
1 | 5 | 17 |
tests/utils |
16 | 51 | 244 |
4 files, 70 tests
19 tests
-
TestModelConfig (4 tests)
-
test_soundsgood_config_values— Test that Soundsgood GLM config has correct values. -
test_api_key_from_env— Test that API key is read from environment. -
test_api_key_empty_when_not_set— Test that API key is empty when env var not set. -
test_custom_model_config— Test creating a custom ModelConfig.
-
-
TestBenchmarkConfig (4 tests)
-
test_default_values— Test that default values are set correctly. -
test_category_weights_sum_to_one— Test that category weights sum to 1.0. -
test_tier_thresholds— Test tier threshold values. -
test_custom_run_id— Test setting custom run ID.
-
-
TestTestCategory (2 tests)
-
test_all_categories_defined— Test that all expected categories are defined. -
test_category_values— Test category string values.
-
-
TestDifficulty (1 tests)
-
test_all_difficulties_defined— Test that all difficulty levels are defined.
-
-
TestTestCase (2 tests)
-
test_create_test_case— Test creating a test case. -
test_test_case_optional_fields— Test that optional fields default correctly.
-
-
TestTestResult (2 tests)
-
test_tokens_per_second_calculation— Test TPS calculation. -
test_tokens_per_second_zero_duration— Test TPS with zero duration returns 0.
-
-
TestBaselineModels (4 tests)
-
test_baseline_tiers_exist— Test that all tier levels are defined. -
test_tier_1_models— Test tier 1 model definitions. -
test_tier_2_models— Test tier 2 model definitions. -
test_baseline_score_ordering— Test that tier 1 models generally score higher than tier 4.
-
16 tests
-
TestLatencyMetrics (4 tests)
-
test_tokens_per_second— Test TPS calculation. -
test_total_output_tokens— Test total output tokens including reasoning. -
test_effective_tps— Test effective TPS including reasoning tokens. -
test_zero_duration_tps— Test TPS with zero duration returns 0.
-
-
TestLatencyTracker (7 tests)
-
test_record_metrics— Test recording metrics. -
test_record_from_response— Test recording from response data. -
test_get_stats— Test getting aggregated stats. -
test_get_stats_empty_raises— Test that getting stats with no data raises error. -
test_percentile_calculation— Test percentile calculations. -
test_session_duration— Test session duration tracking. -
test_to_dict— Test exporting to dictionary.
-
-
TestCategoryLatencyTracker (3 tests)
-
test_track_by_category— Test tracking metrics by category. -
test_get_all_stats— Test getting stats for all categories. -
test_get_overall_stats— Test getting combined stats across categories.
-
-
TestFormatLatencyReport (2 tests)
-
test_format_report— Test formatting a latency report. -
test_format_report_without_ttfc— Test formatting report without TTFC data.
-
19 tests
-
TestQualityScore (2 tests)
-
test_create_quality_score— Test creating a quality score. -
test_quality_score_optional_execution_result— Test that execution_result is optional.
-
-
TestQualityEvaluator (11 tests)
-
test_init_defaults— Test default initialization. -
test_init_custom_values— Test initialization with custom values. -
test_extract_code_fenced_python— Test extracting Python code from fenced block. -
test_extract_code_generic_fenced— Test extracting code from generic fenced block. -
test_extract_code_no_fence— Test extracting code without fence markers. -
test_extract_code_empty— Test extracting from response with no code. -
test_assess_code_quality_with_docstring— Test code quality assessment with docstring. -
test_assess_code_quality_minimal— Test code quality assessment with minimal code. -
test_parse_json_response_clean— Test parsing clean JSON response. -
test_parse_json_response_with_markdown— Test parsing JSON with markdown code block. -
test_parse_json_response_embedded— Test parsing JSON embedded in text.
-
-
TestCodeExecutionEvaluation (3 tests)
-
test_run_code_tests_success— Test running code tests that pass. -
test_run_code_tests_failure— Test running code tests that fail. -
test_run_code_tests_syntax_error— Test running code with syntax error.
-
-
TestEvaluateCodeGeneration (2 tests)
-
test_evaluate_code_gen_passed— Test evaluating passing code generation. -
test_evaluate_code_gen_no_code— Test evaluating response with no extractable code.
-
-
TestIntegration (1 tests)
-
test_evaluate_with_mock_judge— Test evaluation with mocked judge call.
-
16 tests
-
TestCompletionResponse (2 tests)
-
test_create_response— Test creating a completion response. -
test_response_without_reasoning— Test response with no reasoning field.
-
-
TestStreamingMetrics (1 tests)
-
test_create_metrics— Test creating streaming metrics.
-
-
TestSoundsgoodClient (7 tests)
-
test_init— Test client initialization. -
test_init_custom_timeout— Test client initialization with custom timeout. -
test_headers— Test headers property. -
test_context_manager— Test async context manager. -
test_parse_response— Test parsing non-streaming response. -
test_parse_response_no_choices— Test parsing response with no choices raises error. -
test_parse_response_missing_fields— Test parsing response with missing optional fields.
-
-
TestStreamingParsing (3 tests)
-
test_sse_line_parsing— Test that SSE lines are properly identified. -
test_parse_streaming_chunk— Test parsing a single streaming chunk. -
test_parse_final_streaming_chunk— Test parsing final streaming chunk with usage.
-
-
TestHealthCheck (3 tests)
-
test_health_check_success— Test successful health check. -
test_health_check_failure— Test failed health check. -
test_health_check_empty_response— Test health check with empty response.
-
1 files, 16 tests
16 tests
-
test_deduct_credits_uses_atomic_rpc— deduct_credits should try atomic_deduct_credits RPC as primary path. -
test_legacy_path_rolls_back_on_log_failure— Legacy path must roll back balance when transaction log fails. -
test_chat_imports_pricing_for_precheck— chat.py must import get_model_pricing_async for pre-inference validation. -
test_pricing_precheck_before_provider_dispatch— Pricing pre-check must appear BEFORE provider dispatch in chat.py. -
test_pricing_precheck_returns_422— Pricing pre-check failure must return 422, not 500. -
test_non_streaming_deduction_only_after_provider_success— Credit deduction in non-streaming path must only happen AFTER -
test_streaming_background_task_only_after_done_event— In the streaming generator, create_task(_process_stream_completion_background) -
test_reconciliation_table_exists— credit_deduction_failures table must exist for manual reconciliation. -
test_refund_transaction_type_exists— TransactionType.REFUND must exist for manual admin refunds. test_trial_duration_matches_configtest_trial_credits_is_5_dollars-
test_start_trial_default_matches_config— start_trial_for_key() default trial_days must match TRIAL_DURATION_DAYS. -
test_api_keys_uses_config_constants— api_keys.py should import from usage_limits, not hardcode values. -
test_free_model_zero_cost— Free models (:free suffix) always cost $0. -
test_zero_tokens_skip_logic_exists— deduct_credits must skip deduction for near-zero amounts. -
test_atomic_rpc_migration_exists— The atomic_deduct_credits migration must exist.
16 files, 162 tests
19 tests
-
TestCM01ApiKeyEncryptedWithFernet (1 tests)
-
test_api_key_encrypted_with_fernet— encrypt_api_key output is a valid Fernet token, not the plaintext key.
-
-
TestCM02ApiKeyDecryptionRoundtrip (1 tests)
-
test_api_key_decryption_roundtrip— decrypt(encrypt(key)) must return the original plaintext.
-
-
TestCM03ApiKeyHmacSha256Hashing (1 tests)
-
test_api_key_hmac_sha256_hashing— hash_api_key produces a hex SHA-256 HMAC, is deterministic, and
-
-
TestCM04HmacLookupWithoutDecryption (2 tests)
-
test_hmac_lookup_without_decryption— CM-1.4: get_api_key_by_hash() performs a DB lookup by key_hash -
test_hmac_lookup_returns_none_when_not_found— CM-1.4: get_api_key_by_hash() returns None when no key matches.
-
-
TestCM05EncryptedKeyNotPlaintextInDb (1 tests)
-
test_encrypted_key_not_plaintext_in_db— create_api_key must store an encrypted_key that differs from the
-
-
TestCM06RbacThreeTiersExist (1 tests)
-
test_rbac_three_tiers_exist— CM-1.6: Three RBAC tiers (admin, developer, user) are enforced by
-
-
TestCM07AdminRoleHasAllPermissions (1 tests)
-
test_admin_role_has_all_permissions— CM-1.7: Admin role passes the require_admin gate; non-admin is rejected
-
-
TestCM08FreeRoleHasMinimumPermissions (1 tests)
-
test_free_role_has_minimum_permissions— CM-1.8: The 'user' role (lowest tier) is rejected by require_admin,
-
-
TestCM09IpAllowlistBlocksNonListedIp (2 tests)
-
test_ip_allowlist_blocks_non_listed_ip— An IP not in the allowlist must be rejected. -
test_ip_allowlist_blocks_ip_outside_cidr— An IP outside the CIDR range must be rejected.
-
-
TestCM10IpAllowlistAllowsListedIp (3 tests)
-
test_ip_allowlist_allows_exact_match— An IP exactly matching an allowlist entry must be accepted. -
test_ip_allowlist_allows_cidr_match— An IP within an allowed CIDR range must be accepted. -
test_ip_allowlist_empty_means_unrestricted— An empty allowlist means no restrictions (allow all).
-
-
TestCM11DomainRestrictionBlocksWrongDomain (5 tests)
-
test_domain_restriction_blocks_wrong_domain— A referer from an unlisted domain must be rejected. -
test_domain_restriction_allows_correct_domain— A referer from a listed domain must be accepted. -
test_domain_restriction_allows_subdomain— A subdomain of an allowed domain must be accepted. -
test_domain_restriction_blocks_missing_referer— A missing referer must be rejected when domains are configured. -
test_domain_restriction_empty_means_unrestricted— An empty domain list means no restrictions.
-
17 tests
-
TestLayer1IPRateLimiting (5 tests)
-
test_ip_rate_limit_under_threshold_allows— Requests under IP RPM limit pass through (are allowed). -
test_ip_rate_limit_over_threshold_blocks— Requests exceeding IP RPM limit are blocked (return False). -
test_ip_rate_limit_applied_before_auth— CM-2.1.3: IP rate limit is applied before auth in dispatch. -
test_velocity_detection_triggers_on_anomalous_pattern— Rapid burst of 5xx errors triggers velocity mode activation. -
test_authenticated_users_exempt_from_ip_limits— Authenticated requests (with valid API key/Bearer token) bypass IP limits.
-
-
TestLayer2APIKeyRateLimiting (5 tests)
-
test_key_rate_limit_tracks_rpm— Rate limiter uses Redis INCR with rate_limit key pattern for per-minute tracking. -
test_key_rate_limit_enforces_plan_tier— CM-2.2.2: Different plan tiers enforce different RPM limits. -
test_key_rate_limit_tracks_tokens_per_day— Daily token tracking is enforced via rate_limit:{key}:day:{date}:tokens Redis key. -
test_key_rate_limit_tracks_tokens_per_month— CM-2.2.4: Monthly token tracking is not implemented as a separate window. -
test_rate_limit_returns_proper_headers— Rate limit result contains X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset.
-
-
TestLayer3AnonymousRateLimiting (3 tests)
-
test_anonymous_limits_stricter_than_authenticated— CM-2.3.1: Anonymous daily limit is much stricter than authenticated. -
test_anonymous_rate_limit_uses_ip_hash— Redis key for anonymous rate limiting uses a SHA-256 hash of the IP. -
test_anonymous_rate_limit_blocks_excess— Anonymous rate limiter returns 'allowed: False' when daily limit exceeded.
-
-
TestGracefulDegradation (4 tests)
-
test_redis_down_activates_fallback— When Redis is unavailable, the fallback InMemoryRateLimiter is used. -
test_fallback_lru_cache_500_entries— CM-2.4.2: Fallback InMemoryRateLimiter evicts LRU keys when more -
test_fallback_ttl_15_minutes— CM-2.4.3: Fallback entries expire after 15 minutes (900s TTL). -
test_requests_never_blocked_by_infra_failure— When both Redis AND fallback fail, request is ALLOWED (fail-open).
-
10 tests
test_alias_r1_resolves_to_deepseektest_alias_gpt4o_resolves_to_openai-
test_at_least_120_aliases_defined— CM-3.3: At least 120 aliases are defined and each resolves via apply_model_alias. test_canonical_id_passes_through_unchangedtest_provider_detection_explicit_override_highest_prioritytest_provider_detection_format_based_rulestest_provider_detection_org_prefix_fallbacktest_model_id_transformation_fireworks_formattest_model_id_transformation_per_providertest_unknown_alias_returns_error_or_passthrough
15 tests
-
TestGeneralRouterParsing (8 tests)
-
test_general_router_parses_quality_mode— CM-4.1.1: 'router:general:quality' parsed correctly. -
test_general_router_parses_cost_mode— CM-4.1.2: 'router:general:cost' parsed correctly. -
test_general_router_parses_latency_mode— CM-4.1.3: 'router:general:latency' parsed correctly. -
test_general_router_parses_balanced_mode— CM-4.1.4: 'router:general:balanced' or bare 'router:general' → balanced. -
test_general_router_quality_settings_produce_quality_model_string— CM-4.1.5: quality mode settings → model string that parses to quality mode. -
test_general_router_cost_settings_produce_cost_model_string— CM-4.1.6: cost mode settings → model string that parses to cost mode. -
test_general_router_latency_settings_produce_latency_model_string— CM-4.1.7: latency mode settings → model string that parses to latency mode. -
test_general_router_invalid_mode_rejected— CM-4.1.8: 'router:general:invalid' falls back; schema rejects invalid mode.
-
-
TestCodeRouterParsing (7 tests)
-
test_code_router_parses_auto_mode— CM-4.2.1: 'router:code:auto' or bare 'router:code' → auto. -
test_code_router_parses_agentic_mode— CM-4.2.2: 'router:code:agentic' parsed correctly. -
test_code_router_parses_price_mode— CM-4.2.3: 'router:code:price' parsed correctly. -
test_code_router_parses_quality_mode— CM-4.2.4: 'router:code:quality' parsed correctly. -
test_code_router_uses_swe_bench_scores— CM-4.2.5: quality mode factors in SWE-bench scores for model selection. -
test_code_router_classifies_task_complexity— CM-4.2.6: classifier assigns complexity tiers to prompts. -
test_code_router_matches_tier_to_model— CM-4.2.7: higher complexity tier maps to higher-capability model.
-
24 tests
-
TestFailoverChain (12 tests)
-
test_failover_chain_has_14_providers— CM-5.1.1: build_provider_failover_chain produces a chain with 14 providers. -
test_failover_chain_ordered_by_reliability— CM-5.1.2: build_provider_failover_chain preserves reliability ranking after initial. -
test_failover_retries_on_502— CM-5.1.3: should_failover returns True for 502. -
test_failover_retries_on_503— CM-5.1.4: should_failover returns True for 503. -
test_failover_retries_on_504— CM-5.1.5: should_failover returns True for 504. -
test_failover_retries_on_401— CM-5.1.6: should_failover returns True for 401. -
test_failover_retries_on_402— CM-5.1.7: should_failover returns True for 402. -
test_failover_retries_on_403— CM-5.1.8: should_failover returns True for 403. -
test_failover_retries_on_404— CM-5.1.9: should_failover returns True for 404. -
test_failover_does_NOT_trigger_on_400— CM-5.1.10: should_failover returns False for 400. -
test_failover_does_NOT_trigger_on_429— CM-5.1.11: should_failover returns False for 429. -
test_failover_transparent_to_caller— CM-5.1.12: A successful failover returns a normal response (the caller
-
-
TestModelAwareRules (3 tests)
-
test_openai_models_failover_only_to_openai_or_openrouter— CM-5.2.1: openai/* models are restricted to [openai, openrouter]. -
test_anthropic_models_failover_only_to_anthropic_or_openrouter— CM-5.2.2: anthropic/* models are restricted to [anthropic, openrouter]. -
test_opensource_models_failover_across_all_providers— CM-5.2.3: meta-llama/* models can fail over to any provider.
-
-
TestCircuitBreaker (9 tests)
-
test_circuit_breaker_starts_closed— CM-5.3.1: A new circuit breaker starts in CLOSED state. -
test_circuit_breaker_opens_after_5_failures— CM-5.3.2: 5 consecutive failures transition to OPEN. -
test_circuit_breaker_4_failures_stays_closed— CM-5.3.3: 4 failures keep the circuit CLOSED. -
test_circuit_breaker_open_blocks_requests— CM-5.3.4: An OPEN circuit rejects new requests with CircuitBreakerError. -
test_circuit_breaker_recovery_after_60_seconds— CM-5.3.5: After timeout_seconds elapse, OPEN transitions to HALF_OPEN. -
test_circuit_breaker_half_open_success_closes— CM-5.3.6: Reaching success_threshold (2) in HALF_OPEN transitions to CLOSED. -
test_circuit_breaker_half_open_failure_reopens— CM-5.3.7: half_open_max_failures (2) failures in HALF_OPEN re-opens circuit. -
test_circuit_breaker_success_resets_failure_count— CM-5.3.8: A successful request resets the consecutive failure counter. -
test_circuit_breaker_independent_per_provider— CM-5.3.9: Each provider has an independent circuit breaker.
-
10 tests
-
test_new_user_gets_5_dollar_credits— create_enhanced_user inserts a user row with credits=5.0 ($5.00). -
test_new_user_gets_3_day_trial— start_trial_for_key should default to trial_days=3 per CM spec. -
test_trial_1m_token_limit— track_trial_usage_for_key tracks token usage; DB enforces 1M limit. -
test_trial_10k_request_limit— track_trial_usage_for_key tracks request usage; DB enforces 10K limit. -
test_expired_trial_returns_402— An expired trial requesting a non-free model raises HTTPException (403). -
test_expired_trial_can_access_free_models— An expired trial can still use models ending with ':free'. -
test_active_trial_can_access_all_models— A valid, active trial should be able to access standard (non-free) models. -
test_plan_tiers_exist— get_all_plans returns plans; verify that 4 canonical tiers can be -
test_team_has_higher_rate_limits_than_dev— Team plan limits exceed Dev plan limits when queried via check_plan_entitlements. -
test_purchased_credits_survive_plan_change— assign_user_plan changes the plan but does NOT modify the user's
8 tests
-
TestModelMetadata (5 tests)
-
test_every_model_has_required_fields— CM-9.1.1: Calling normalize_fireworks_model on raw provider data -
test_model_id_is_canonical_format— CM-9.1.2: normalize_fireworks_model produces IDs that include the raw slug. -
test_pricing_field_never_null— CM-9.1.3: enrich_model_with_pricing populates pricing on a model. -
test_modality_is_known_type— CM-9.1.4: normalize_fireworks_model outputs a known modality type. -
test_context_length_is_positive_integer— CM-9.1.5: normalize_fireworks_model preserves context_length as a positive int.
-
-
TestCatalogInclusionRules (3 tests)
-
test_model_without_pricing_excluded— CM-9.2.1: A gateway-provider model with no pricing is excluded from the catalog. -
test_model_with_inactive_provider_excluded— CM-9.2.2: A model whose provider slug is not in GATEWAY_REGISTRY is excluded. -
test_deduplicated_view_no_duplicate_ids— CM-9.2.3: The merge/deduplicated view contains no duplicate model IDs.
-
14 tests
-
TestOpenAIResponseFormatHasChoices (1 tests)
test_openai_response_format_has_choices
-
TestOpenAIResponseFormatHasUsage (1 tests)
test_openai_response_format_has_usage
-
TestOpenAIResponseFormatHasId (1 tests)
test_openai_response_format_has_id
-
TestOpenAIResponseFormatHasModel (1 tests)
test_openai_response_format_has_model
-
TestOpenAIStreamingSSEFormat (1 tests)
test_openai_streaming_sse_format
-
TestOpenAIStreamingEndsWithDone (1 tests)
test_openai_streaming_ends_with_done
-
TestOpenAIJsonModeReturnsValidJson (1 tests)
-
test_openai_json_mode_returns_valid_json— When a provider returns JSON content, process_openrouter_response
-
-
TestOpenAIToolCallingResponseFormat (1 tests)
-
test_openai_tool_calling_response_format— extract_message_with_tools extracts tool_calls from a message dict.
-
-
TestOpenAILogprobsIncludedWhenRequested (1 tests)
-
test_openai_logprobs_included_when_requested— process_openrouter_response preserves logprobs when present in provider response.
-
-
TestAnthropicResponseFormatHasContent (1 tests)
test_anthropic_response_format_has_content
-
TestAnthropicResponseFormatHasUsage (1 tests)
test_anthropic_response_format_has_usage
-
TestAnthropicStreamingEventFormat (1 tests)
test_anthropic_streaming_event_format
-
TestResponseNormalizedRegardlessOfProvider (1 tests)
test_response_normalized_regardless_of_provider
-
TestProviderSpecificFieldsStripped (1 tests)
test_provider_specific_fields_stripped
9 tests
-
test_health_check_critical_tier_5min_interval— CM-11.1: Top 5% models (CRITICAL tier) are scheduled every 5 minutes (300s). -
test_health_check_popular_tier_30min_interval— CM-11.2: Next 20% models (POPULAR tier) are scheduled every 30 minutes (1800s). -
test_health_check_standard_tier_2_to_4hr_interval— CM-11.3: Remaining 75% models (STANDARD tier) are checked every 2-4 hours (7200-14400s). -
test_passive_health_captures_from_inference— CM-11.4: Every inference call contributes health data via capture_model_health. -
test_health_endpoint_always_returns_200— CM-11.5: /health returns HTTP 200 even when subsystems are down. -
test_health_response_contains_version— CM-11.6: /health response body must include a 'version' field. -
test_health_response_contains_status— CM-11.7: /health response includes an overall 'status' field. -
test_health_response_contains_timestamp— CM-11.8: /health response includes a timestamp. -
test_incident_severity_levels— CM-11.9: System supports Critical, High, Medium, and Low severity levels.
10 tests
-
test_login_rate_limit_10_per_15min— 11th login attempt from same IP within 15 min window returns 429 (not allowed). -
test_register_rate_limit_3_per_hour— 4th registration attempt from same IP within 1 hour returns 429. -
test_new_user_provisioned_with_basic_tier— create_enhanced_user sets tier='basic' for new users. -
test_new_user_gets_auto_created_api_key— create_enhanced_user creates a primary API key for the new user. -
test_api_key_format_gw_env_prefix— generate_secure_api_key produces keys with gw_{env}_ prefix. -
test_auth_info_priority_email_first— When user has email + Google + phone linked accounts, email is resolved first. -
test_auth_info_priority_google_over_phone— When user has Google + phone (no email account), Google email is resolved. -
test_partner_code_triggers_extended_trial— A valid partner code triggers PartnerTrialService.start_partner_trial. -
test_referral_code_stored_on_new_user— Referral code is saved to user record via _process_referral_code_background. -
test_temp_email_detection_blocks_registration— Known disposable email domains are detected by is_temporary_email_domain.
8 tests
-
TestCM1301PrometheusInferenceRequestCounter (1 tests)
-
test_prometheus_inference_request_counter— The model_inference_requests_total Prometheus Counter must exist and accept labels.
-
-
TestCM1302PrometheusInferenceDurationHistogram (1 tests)
-
test_prometheus_inference_duration_histogram— The model_inference_duration_seconds Histogram must exist and accept observations.
-
-
TestCM1303PrometheusTokensUsedCounter (1 tests)
-
test_prometheus_tokens_used_counter— The tokens_used_total Prometheus Counter must exist and accept labels.
-
-
TestCM1304PrometheusCreditsUsedCounter (1 tests)
-
test_prometheus_credits_used_counter— The credits_used_total Prometheus Counter must exist and accept labels.
-
-
TestCM1305PrometheusTtfcHistogram (1 tests)
-
test_prometheus_ttfc_histogram— The time_to_first_chunk_seconds Histogram must exist and accept observations.
-
-
TestCM1306SentryCapturesExceptions (1 tests)
-
test_sentry_captures_exceptions— AutoSentryMiddleware calls sentry_sdk.capture_exception
-
-
TestCM1307OpentelemetryTraceCreatedPerRequest (1 tests)
-
test_opentelemetry_trace_created_per_request— OpenTelemetryConfig.initialize() returns a bool indicating success/failure.
-
-
TestCM1308AuditLogOnSecurityViolation (1 tests)
-
test_audit_log_on_security_violation— log_security_event writes a row to security_audit_log with the
-
3 tests
-
TestCM1401TokenEstimationFallback1Per4Chars (1 tests)
-
test_token_estimation_fallback_1_per_4_chars— CM specifies 1 token per 4 characters (400 chars -> ~100 tokens).
-
-
TestCM1402TokenEstimationUsedWhenProviderOmitsUsage (1 tests)
-
test_token_estimation_used_when_provider_omits_usage— When no explicit max_tokens is provided and messages exist,
-
-
TestCM1403RealUsagePreferredOverEstimation (1 tests)
-
test_real_usage_preferred_over_estimation— When max_tokens is explicitly provided, estimate_message_tokens
-
3 tests
-
TestCM1501ImageGenerationDeductsCredits (1 tests)
-
test_image_generation_deducts_credits— The image generation route calculates a positive cost for images
-
-
TestCM1502ImageGenerationInsufficientCredits402 (1 tests)
-
test_image_generation_insufficient_credits_402— When a user has 0 credits, the image endpoint raises HTTP 402.
-
-
TestCM1503AudioTranscriptionReturnsText (1 tests)
-
test_audio_transcription_returns_text— The audio transcription endpoint returns a response containing
-
6 tests
-
TestCM1601WebhookPayloadHmacSigned (1 tests)
-
test_webhook_payload_hmac_signed— generate_webhook_signature produces a valid HMAC-SHA256 hex digest
-
-
TestCM1602WebhookCreditsLowEventTriggered (2 tests)
-
test_webhook_credits_low_event_triggered— check_low_balance_alert returns a LowBalanceAlert when the user's -
test_no_alert_when_credits_above_threshold— check_low_balance_alert returns None when credits are above $5.
-
-
TestCM1603WebhookCreditsDepletedEventTriggered (1 tests)
-
test_webhook_credits_depleted_event_triggered— The low balance alert fires when credits are 0 (depleted),
-
-
TestCM1604WebhookRetryExponentialBackoff (1 tests)
-
test_webhook_retry_exponential_backoff— send_webhook_notification should retry failed deliveries with
-
-
TestCM1605StripeWebhookAlwaysReturns200 (1 tests)
-
test_stripe_webhook_always_returns_200— The Stripe webhook handler returns HTTP 200 even when processing
-
3 tests
-
TestCM1701CreateAppReturnsFastapiInstance (1 tests)
-
test_create_app_returns_fastapi_instance— create_app() must return a FastAPI application instance.
-
-
TestCM1702VercelEntryPointImportsApp (1 tests)
-
test_vercel_entry_point_imports_app— api/index.py must export an 'app' object that is a FastAPI instance.
-
-
TestCM1703AppIncludesAllRouteGroups (1 tests)
-
test_app_includes_all_route_groups— The app must have routes for chat, auth, users, admin, health,
-
3 tests
-
TestCM1801AtLeast30ProvidersRegistered (1 tests)
-
test_at_least_30_providers_registered— GATEWAY_REGISTRY must contain at least 30 provider entries,
-
-
TestCM1802EachProviderHasClientModule (1 tests)
-
test_each_provider_has_client_module— Key providers from GATEWAY_REGISTRY should have importable *_client modules.
-
-
TestCM1803ProviderClientImplementsRequiredInterface (1 tests)
-
test_provider_client_implements_required_interface— Provider client modules should have callable functions for sending
-
5 files, 80 tests
42 tests
-
TestConfigEnvironmentDetection (8 tests)
-
test_is_production_detection— Test production environment detection -
test_is_staging_detection— Test staging environment detection -
test_is_development_detection— Test development environment detection (default) -
test_is_testing_detection_with_testing_env— Test testing environment detection with APP_ENV=testing -
test_is_testing_detection_with_test_env— Test testing environment detection with APP_ENV=test -
test_is_testing_detection_with_testing_flag_true— Test testing environment detection with TESTING=true -
test_is_testing_detection_with_testing_flag_1— Test testing environment detection with TESTING=1 -
test_is_testing_detection_with_testing_flag_yes— Test testing environment detection with TESTING=yes
-
-
TestConfigProviderKeys (4 tests)
-
test_openrouter_keys— Test OpenRouter configuration -
test_openrouter_defaults— Test OpenRouter default values -
test_openrouter_key_strips_whitespace— Ensure OpenRouter API key trimming removes accidental whitespace -
test_all_provider_keys— Test all provider API keys are loaded
-
-
TestConfigGoogleVertex (2 tests)
-
test_google_vertex_defaults— Test Google Vertex AI default configuration -
test_google_vertex_custom_values— Test Google Vertex AI custom configuration
-
-
TestConfigMonitoring (9 tests)
-
test_prometheus_enabled_by_default— Test Prometheus is enabled by default -
test_prometheus_enabled_explicit_true— Test Prometheus enabled with explicit true values -
test_prometheus_disabled— Test Prometheus can be disabled -
test_prometheus_scrape_enabled_by_default— Test Prometheus scrape is enabled by default -
test_tempo_enabled_by_default— Test Tempo is enabled by default when env var is not set -
test_tempo_enabled— Test Tempo can be enabled -
test_loki_disabled_by_default— Test Loki is disabled by default -
test_loki_enabled— Test Loki can be enabled -
test_otel_service_name_default— Test OTEL service name default
-
-
TestConfigValidation (14 tests)
-
test_validate_success_with_all_vars— Test validate succeeds with all required variables -
test_validate_skips_in_vercel_environment— Test validate skips validation in Vercel environment -
test_validate_raises_on_missing_supabase_url— Test validate raises error on missing SUPABASE_URL -
test_validate_raises_on_missing_multiple_vars— Test validate raises error listing all missing variables -
test_validate_critical_env_vars_success— Test validate_critical_env_vars with all variables present -
test_validate_critical_env_vars_missing_vars— Test validate_critical_env_vars with missing variables -
test_validate_critical_env_vars_skips_in_vercel— Test validate_critical_env_vars skips in Vercel environment -
test_validate_raises_on_supabase_url_missing_protocol— Test validate raises error when SUPABASE_URL lacks http:// or https:// protocol -
test_validate_accepts_http_protocol— Test validate accepts SUPABASE_URL with http:// protocol -
test_validate_accepts_https_protocol— Test validate accepts SUPABASE_URL with https:// protocol -
test_validate_critical_env_vars_detects_missing_protocol— Test validate_critical_env_vars detects SUPABASE_URL without protocol -
test_validate_raises_in_vercel_when_url_missing_protocol— Test validate raises error in Vercel env when SUPABASE_URL lacks protocol -
test_validate_critical_env_vars_detects_missing_protocol_in_vercel— Test validate_critical_env_vars detects SUPABASE_URL without protocol in Vercel -
test_validate_skips_presence_check_in_vercel— Test validate skips checking presence of keys in Vercel env (but validates URL format)
-
-
TestConfigGetSupabaseConfig (1 tests)
-
test_get_supabase_config_returns_tuple— Test get_supabase_config returns URL and key as tuple
-
-
TestConfigClarifai (1 tests)
-
test_clarifai_configuration— Test Clarifai API configuration
-
-
TestConfigAiHubMix (1 tests)
-
test_aihubmix_configuration— Test AiHubMix API configuration
-
-
TestConfigAdminAndAnalytics (2 tests)
-
test_admin_email_configuration— Test admin email configuration -
test_openrouter_cookie_configuration— Test OpenRouter cookie configuration
-
32 tests
-
TestDatabaseConfig (5 tests)
-
test_default_configuration— Test default database configuration values -
test_custom_configuration— Test custom database configuration from environment -
test_psycopg2_not_available— Test configuration when psycopg2 is not installed -
test_get_connection_string— Test connection string generation -
test_get_connection_dict— Test connection dictionary generation
-
-
TestConnectionPool (7 tests)
-
test_get_connection_pool_success— Test successful connection pool creation -
test_get_connection_pool_reuses_existing— Test connection pool reuse -
test_get_connection_pool_not_available— Test connection pool when psycopg2 not available -
test_get_connection_pool_failure— Test connection pool creation failure -
test_close_all_connections— Test closing all connections in pool -
test_close_all_connections_when_none— Test closing connections when pool is None -
test_close_all_connections_error— Test error handling when closing connections
-
-
TestConnectionContextManager (6 tests)
-
test_get_connection_not_available— Test get_connection when psycopg2 not available -
test_get_connection_success— Test successful connection retrieval -
test_get_connection_getconn_returns_none— Test when getconn returns None -
test_get_connection_with_exception— Test connection rollback on exception -
test_get_connection_rollback_fails— Test when rollback itself fails -
test_get_connection_putconn_fails— Test when putconn fails
-
-
TestDatabaseOperations (9 tests)
-
test_test_connection_not_available— Test test_connection when psycopg2 not available -
test_test_connection_success— Test successful connection test -
test_test_connection_failure— Test failed connection test -
test_get_database_info_not_available— Test get_database_info when psycopg2 not available -
test_get_database_info_success— Test successful database info retrieval -
test_execute_query_success— Test successful query execution -
test_execute_query_with_params— Test query execution with parameters -
test_execute_query_fetch_one— Test query execution with fetch_one=True -
test_execute_many_success— Test batch execution success
-
-
TestGlobalFunctions (5 tests)
-
test_get_db_config_singleton— Test get_db_config returns singleton -
test_get_db_connection— Test get_db_connection helper -
test_test_db_connection— Test test_db_connection helper -
test_close_db_connections— Test close_db_connections helper -
test_is_db_available— Test is_db_available helper
-
2 tests
-
TestLoggingConfig (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module has expected public API
-
2 tests
-
TestOpentelemetryConfig (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module has expected public API
-
2 tests
-
TestRedisConfig (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module has expected public API
-
16 files, 239 tests
27 tests
-
TestLogActivity (4 tests)
-
test_log_activity_success— Test successfully logging an activity -
test_log_activity_with_defaults— Test logging activity with default values -
test_log_activity_no_data— Test logging activity when no data is returned -
test_log_activity_error— Test error handling during activity logging
-
-
TestActivityStatistics (5 tests)
-
test_get_activity_stats_with_data— Test retrieving activity statistics with data -
test_get_activity_stats_empty— Test retrieving statistics when no activity -
test_get_activity_stats_with_date_range— Test retrieving statistics with specific date range -
test_get_activity_stats_default_30_days— Test default 30-day lookback -
test_get_activity_stats_error— Test error handling in statistics
-
-
TestActivityLogRetrieval (7 tests)
-
test_get_activity_log_success— Test retrieving activity log -
test_get_activity_log_with_pagination— Test activity log with pagination -
test_get_activity_log_with_date_filters— Test activity log with date filtering -
test_get_activity_log_with_model_filter— Test activity log with model filter -
test_get_activity_log_with_provider_filter— Test activity log with provider filter -
test_get_activity_log_empty— Test retrieving empty activity log -
test_get_activity_log_error— Test error handling in activity log retrieval
-
-
TestProviderDetection (9 tests)
-
test_detect_openai_models— Test detecting OpenAI models -
test_detect_anthropic_models— Test detecting Anthropic models -
test_detect_google_models— Test detecting Google models -
test_detect_meta_models— Test detecting Meta models -
test_detect_mistral_models— Test detecting Mistral AI models -
test_detect_alibaba_models— Test detecting Alibaba models -
test_detect_deepseek_models— Test detecting DeepSeek models -
test_detect_unknown_models— Test detecting unknown/other models -
test_provider_detection_case_insensitive— Test provider detection is case-insensitive
-
-
TestActivityIntegration (2 tests)
-
test_log_and_retrieve_activity— Test logging activity and retrieving it -
test_stats_include_logged_activity— Test that logged activities appear in statistics
-
5 tests
test_create_and_get_session_with_messagestest_get_user_chat_sessions_pagination_and_sorttest_update_and_delete_chat_sessiontest_chat_session_statstest_search_chat_sessions_title_and_message
8 tests
-
test_save_message_no_duplicate_normal_path— Test normal save when no duplicate exists -
test_save_message_duplicate_detected_returns_existing— Test that duplicate message returns existing instead of creating new -
test_save_message_skip_duplicate_check_creates_new— Test that skip_duplicate_check=True bypasses duplicate detection -
test_save_message_empty_content_allowed— Test that empty content is allowed and saved -
test_save_message_different_sessions_not_duplicate— Test that same content in different sessions is not considered duplicate -
test_save_message_different_roles_not_duplicate— Test that same content with different roles is not considered duplicate -
test_save_message_updates_session_timestamp— Test that saving a message updates session updated_at -
test_save_message_with_model_updates_session_model— Test that saving a message with model updates session model
24 tests
-
TestCreateCoupon (5 tests)
-
test_create_global_coupon_success— Test creating a global coupon -
test_create_user_specific_coupon_success— Test creating a user-specific coupon -
test_create_user_specific_without_user_id_fails— Test creating user-specific coupon without user ID fails -
test_create_global_coupon_with_user_id_fails— Test creating global coupon with user ID fails -
test_create_user_specific_with_max_uses_not_1_fails— Test creating user-specific coupon with max_uses != 1 fails
-
-
TestGetCoupon (5 tests)
-
test_get_coupon_by_code_success— Test retrieving coupon by code -
test_get_coupon_by_code_not_found— Test retrieving non-existent coupon -
test_get_coupon_by_id_success— Test retrieving coupon by ID -
test_list_coupons_all— Test listing all coupons -
test_list_coupons_with_filters— Test listing coupons with filters
-
-
TestUpdateCoupon (3 tests)
-
test_update_coupon_success— Test updating coupon fields -
test_update_coupon_filters_invalid_fields— Test that invalid fields are filtered out -
test_deactivate_coupon_success— Test deactivating a coupon
-
-
TestValidateCoupon (2 tests)
-
test_validate_coupon_valid— Test validating a valid coupon -
test_validate_coupon_invalid— Test validating an invalid coupon
-
-
TestRedeemCoupon (2 tests)
-
test_redeem_coupon_success— Test successfully redeeming a coupon -
test_redeem_coupon_invalid— Test redeeming an invalid coupon
-
-
TestUserCouponQueries (2 tests)
-
test_get_available_coupons_for_user— Test getting available coupons for a user -
test_get_user_redemption_history— Test getting user redemption history
-
-
TestCouponAnalytics (2 tests)
-
test_get_coupon_analytics— Test getting analytics for a coupon -
test_get_all_coupons_stats— Test getting overall coupon stats
-
-
TestCouponErrorHandling (3 tests)
-
test_get_coupon_by_code_error— Test error handling when getting coupon by code -
test_list_coupons_error— Test error handling when listing coupons -
test_validate_coupon_error— Test error handling during coupon validation
-
26 tests
test_save_thumbs_up_feedbacktest_save_thumbs_down_feedback_with_commenttest_save_regenerate_feedback_with_metadatatest_save_feedback_invalid_type_raises_errortest_save_feedback_invalid_rating_raises_errortest_get_user_feedback_alltest_get_user_feedback_by_typetest_get_user_feedback_by_sessiontest_get_user_feedback_by_modeltest_get_user_feedback_paginationtest_get_feedback_by_sessiontest_get_feedback_by_messagetest_update_feedback_typetest_update_feedback_ratingtest_update_feedback_commenttest_update_feedback_wrong_user_returns_nonetest_update_feedback_invalid_type_raises_errortest_update_feedback_invalid_rating_raises_errortest_delete_feedback_successtest_delete_feedback_wrong_user_returns_falsetest_delete_feedback_nonexistent_returns_falsetest_get_feedback_stats_basictest_get_feedback_stats_with_ratingstest_get_feedback_stats_by_modeltest_get_feedback_stats_filter_by_modeltest_get_feedback_stats_empty
8 tests
-
TestGetProviderStats (5 tests)
-
test_get_provider_stats_success— Test successfully getting provider statistics -
test_get_provider_stats_with_user_filter— Test getting provider stats filtered by user -
test_get_provider_stats_no_data— Test provider stats with no matching data -
test_get_provider_stats_error_handling— Test error handling in provider stats -
test_get_provider_stats_with_gateway_filter— Test provider stats with gateway filter
-
-
TestGetGatewayStats (3 tests)
-
test_get_gateway_stats_success— Test successfully getting gateway statistics -
test_get_gateway_stats_with_user_filter— Test getting gateway stats with user filter -
test_get_gateway_stats_time_ranges— Test gateway stats with different time ranges
-
20 tests
-
TestCreatePayment (4 tests)
-
test_create_payment_success— Test successful payment creation -
test_create_payment_with_metadata— Test payment creation with metadata -
test_create_payment_no_data_returned— Test handling when no data returned -
test_create_payment_exception— Test exception handling during creation
-
-
TestRetrievePayments (7 tests)
-
test_get_payment_success— Test retrieving payment by ID -
test_get_payment_not_found— Test getting non-existent payment -
test_get_payment_by_stripe_intent_payment_intent— Test getting payment by Stripe payment intent ID -
test_get_payment_by_stripe_intent_session_id— Test getting payment by Stripe session ID (fallback) -
test_get_user_payments— Test getting all payments for a user -
test_get_user_payments_with_status_filter— Test getting user payments filtered by status -
test_get_recent_payments— Test getting recent payments (admin function)
-
-
TestUpdatePayments (4 tests)
-
test_update_payment_status_to_completed— Test updating payment status to completed -
test_update_payment_status_sets_checkout_session_id— Ensure stripe session updates use the checkout session column -
test_update_payment_status_to_failed_with_error— Test updating payment status to failed with error message -
test_update_payment_metadata— Test updating payment metadata
-
-
TestDeletePayment (2 tests)
-
test_delete_payment_success— Test successful payment deletion -
test_delete_payment_failure— Test payment deletion failure
-
-
TestPaymentStatistics (3 tests)
-
test_get_payment_statistics_user_specific— Test getting payment statistics for specific user -
test_get_total_revenue— Test getting total revenue statistics -
test_get_payment_trends— Test getting payment trends over time
-
24 tests
-
TestCreatePaymentWithRetry (7 tests)
-
test_create_payment_success— Test successful payment creation with retry wrapper -
test_create_payment_no_data_returned— Test payment creation fails when no data returned -
test_create_payment_http2_connection_error— Test HTTP/2 ConnectionTerminated error during payment creation -
test_create_payment_stream_id_error— Test StreamIDTooLowError during payment creation -
test_create_payment_send_headers_error— Test SEND_HEADERS LocalProtocolError during payment creation -
test_create_payment_with_metadata— Test payment creation with custom metadata -
test_create_payment_amount_calculation— Test payment amount is correctly converted to cents
-
-
TestUpdatePaymentStatusWithRetry (7 tests)
-
test_update_payment_status_success— Test successful payment status update -
test_update_payment_status_to_failed— Test updating payment status to failed with error message -
test_update_payment_status_no_data_returned— Test update fails when no data returned -
test_update_payment_status_http2_error— Test HTTP/2 connection error during status update -
test_update_payment_status_stream_id_error— Test StreamIDTooLowError during status update -
test_update_payment_status_remote_protocol_error— Test RemoteProtocolError during status update -
test_update_payment_status_with_stripe_fields— Test status update with Stripe payment intent and session IDs
-
-
TestPaymentsIntegration (3 tests)
-
test_payment_creation_and_update_flow— Test full payment flow: create -> update status -
test_resilience_to_transient_errors— Test that execute_with_retry handles transient errors gracefully -
test_multiple_payment_operations— Test multiple payment operations with consistent retry behavior
-
-
TestPaymentErrorHandling (7 tests)
-
test_create_payment_generic_exception— Test generic exception handling during payment creation -
test_get_payment_with_retry_success— Test get_payment with retry wrapper -
test_get_payment_http2_error— Test get_payment with HTTP/2 connection error -
test_get_payment_not_found— Test get_payment when payment not found -
test_update_payment_status_generic_exception— Test generic exception handling during status update -
test_create_payment_with_zero_amount— Test payment creation with zero amount -
test_create_payment_with_large_amount— Test payment creation with large amount
-
2 tests
-
TestPing (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module exports
-
2 tests
test_refresh_postgrest_schema_cache_falls_back_to_direct_notifytest_refresh_postgrest_schema_cache_returns_false_without_dsn
2 tests
-
TestRanking (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module exports
-
10 tests
-
test_module_imports— Smoke test to ensure the module imports correctly after migration -
TestGetUserRateLimitsConfigsMigration (3 tests)
-
test_get_rate_limits_from_configs_table— Test retrieving rate limits from rate_limit_configs table -
test_get_rate_limits_returns_none_when_no_config— Test that None is returned when no rate limits are configured -
test_get_rate_limits_handles_missing_api_key— Test handling when API key doesn't exist
-
-
TestSetUserRateLimitsConfigsMigration (3 tests)
-
test_set_rate_limits_creates_new_config— Test creating new rate limit config in rate_limit_configs table -
test_set_rate_limits_updates_existing_config— Test updating existing rate limit config -
test_set_rate_limits_raises_error_for_missing_key— Test that ValueError is raised when API key not found
-
-
TestRateLimitsLegacyTableRemoval (2 tests)
-
test_no_fallback_to_legacy_table— Test that get_user_rate_limits does NOT fallback to legacy rate_limits table. -
test_set_user_rate_limits_uses_configs_table— Verify that set_user_rate_limits uses rate_limit_configs table.
-
-
TestRateLimitConfigsIntegration (1 tests)
-
test_full_lifecycle_create_retrieve_update— Test full lifecycle: create config, retrieve it, update it
-
16 tests
-
TestReferralCodeGeneration (3 tests)
-
test_generate_referral_code_length— Test referral code has correct length -
test_generate_referral_code_uppercase_digits— Test referral code contains only uppercase and digits -
test_generate_referral_code_uniqueness— Test that multiple codes are likely unique
-
-
TestUserModel (7 tests)
-
test_user_init— Test User initialization -
test_user_init_with_referral— Test User initialization with referral code -
test_user_to_dict— Test User to_dict method -
test_user_get_remaining_referral_uses_zero_used— Test remaining uses when none used -
test_user_get_remaining_referral_uses_some_used— Test remaining uses when partially used -
test_user_get_remaining_referral_uses_max_used— Test remaining uses when max reached -
test_user_get_remaining_referral_uses_over_max— Test remaining uses when over max (edge case)
-
-
TestCouponUsageModel (3 tests)
-
test_coupon_usage_to_dict— Test CouponUsage to_dict method -
test_coupon_usage_default_bonus— Test CouponUsage default bonus amount -
test_coupon_usage_default_is_valid— Test CouponUsage default is_valid
-
-
TestPurchaseModel (3 tests)
-
test_purchase_to_dict— Test Purchase to_dict method -
test_purchase_default_referral_bonus— Test Purchase default referral bonus -
test_purchase_default_referral_code— Test Purchase default referral code
-
34 tests
-
TestPermissionChecking (7 tests)
-
test_check_user_permission_granted— Test permission check when permission is granted -
test_check_user_permission_denied— Test permission check when permission is denied -
test_check_user_permission_no_data— Test permission check when no data is returned -
test_check_user_permission_error— Test permission check with database error -
test_get_user_permissions_success— Test retrieving all user permissions -
test_get_user_permissions_empty— Test retrieving permissions when user has none -
test_get_user_permissions_error— Test error handling when retrieving permissions
-
-
TestUserRoleManagement (8 tests)
-
test_get_user_role_success— Test retrieving user's role -
test_get_user_role_not_found— Test retrieving role for non-existent user -
test_get_user_role_error— Test error handling when getting user role -
test_update_user_role_success— Test successfully updating user's role -
test_update_user_role_with_audit_log— Test role update creates audit log entry -
test_update_user_role_invalid_role— Test updating to invalid role -
test_update_user_role_no_data— Test role update when no data is returned -
test_update_user_role_error— Test error handling during role update
-
-
TestRoleAuditLog (4 tests)
-
test_get_role_audit_log_all— Test retrieving all audit log entries -
test_get_role_audit_log_by_user— Test retrieving audit log for specific user -
test_get_role_audit_log_empty— Test retrieving empty audit log -
test_get_role_audit_log_error— Test error handling when retrieving audit log
-
-
TestUsersByRole (4 tests)
-
test_get_users_by_role_success— Test retrieving users with specific role -
test_get_users_by_role_admin— Test retrieving admin users -
test_get_users_by_role_empty— Test retrieving users when none have role -
test_get_users_by_role_error— Test error handling when retrieving users by role
-
-
TestRolePermissionsManagement (8 tests)
-
test_get_role_permissions_success— Test retrieving all permissions for a role -
test_get_role_permissions_empty— Test retrieving permissions when role has none -
test_add_role_permission_success— Test adding permission to a role -
test_add_role_permission_no_data— Test adding permission when no data is returned -
test_add_role_permission_error— Test error handling when adding permission -
test_remove_role_permission_success— Test removing permission from a role -
test_remove_role_permission_no_data— Test removing permission when no data is returned -
test_remove_role_permission_error— Test error handling when removing permission
-
-
TestRoleConstants (3 tests)
-
test_user_role_constants— Test role constant values -
test_role_constants_are_strings— Test all role constants are strings -
test_role_constants_uniqueness— Test all role constants are unique
-
16 tests
-
test_generate_share_token_is_unique— Test that generate_share_token produces unique tokens -
test_generate_share_token_is_url_safe— Test that generated tokens are URL-safe -
test_create_shared_chat_success— Test successfully creating a shared chat -
test_create_shared_chat_with_expiry— Test creating shared chat with expiration date -
test_get_shared_chat_by_token_success— Test getting shared chat by token -
test_get_shared_chat_by_token_not_found— Test getting non-existent shared chat -
test_get_shared_chat_by_token_expired— Test getting expired shared chat returns None -
test_get_user_shared_chats_success— Test getting user's shared chats -
test_get_user_shared_chats_empty— Test getting shared chats when user has none -
test_delete_shared_chat_success— Test deleting a shared chat -
test_delete_shared_chat_not_found— Test deleting non-existent shared chat -
test_verify_session_ownership_true— Test verifying session ownership returns True for owner -
test_verify_session_ownership_false— Test verifying session ownership returns False for non-owner -
test_check_share_rate_limit_within_limit— Test rate limit check when within limit -
test_check_share_rate_limit_exceeded— Test rate limit check when limit exceeded -
test_check_share_rate_limit_custom_limit— Test rate limit check with custom limit
15 tests
-
TestSubscriptionProducts (15 tests)
-
test_get_tier_from_product_id_pro— Test getting tier from PRO product ID -
test_get_tier_from_product_id_max— Test getting tier from MAX product ID -
test_get_tier_from_product_id_not_found— Test getting tier from unknown product ID defaults to basic -
test_get_tier_from_product_id_recovers_from_schema_cache_miss— Ensure schema cache refresh is attempted when PostgREST cannot find the table. -
test_get_tier_from_product_id_schema_cache_refresh_failure— Ensure we fall back to basic tier when schema cache refresh cannot run. -
test_get_credits_from_tier_pro— Test getting credits for PRO tier -
test_get_credits_from_tier_max— Test getting credits for MAX tier -
test_get_credits_from_tier_not_found— Test getting credits from unknown tier defaults to 0 -
test_get_subscription_product— Test getting full product configuration -
test_get_all_active_products— Test getting all active products -
test_add_subscription_product— Test adding new subscription product -
test_add_subscription_product_failure— Test adding product failure -
test_update_subscription_product— Test updating subscription product -
test_update_subscription_product_no_fields— Test updating product with no fields returns False -
test_database_error_handling— Test that database errors are handled gracefully
-
8 files, 125 tests
15 tests
-
TestAllenAIModelsE2E (11 tests)
-
test_allenai_model_basic_request— Test basic chat completion request for each AllenAI model. -
test_allenai_model_streaming— Test streaming chat completion for each AllenAI model. -
test_allenai_model_with_system_prompt— Test AllenAI models with system prompt. -
test_allenai_model_conversation_history— Test AllenAI models with conversation history. -
test_allenai_model_with_temperature— Test AllenAI models with custom temperature. -
test_allenai_model_with_top_p— Test AllenAI models with top_p parameter. -
test_olmo_instruct_follows_instructions— Test that OLMo instruct model follows instructions. -
test_thinking_models_reasoning_task— Test thinking models with a reasoning task. -
test_allenai_model_with_openrouter_provider— Test AllenAI models with explicit OpenRouter provider. -
test_allenai_model_response_has_usage— Test that AllenAI model responses include usage information. -
test_allenai_model_invalid_should_fail— Test that invalid AllenAI model ID returns appropriate error.
-
-
TestAllenAIModelsStreamingE2E (2 tests)
-
test_streaming_with_custom_params— Test streaming with custom temperature and max_tokens. -
test_streaming_response_structure— Test that streaming responses have correct SSE structure.
-
-
TestAllenAIModelsDeveloperRoleE2E (2 tests)
-
test_allenai_model_with_developer_role— Test AllenAI models with developer role instead of system role. -
test_allenai_model_developer_role_streaming— Test streaming with developer role for AllenAI models.
-
21 tests
-
TestChatCompletionsE2E (18 tests)
-
test_chat_completions_basic_request— Test basic chat completion request and response. -
test_chat_completions_with_system_prompt— Test chat completion with system prompt. -
test_chat_completions_with_all_parameters— Test chat completion with all optional parameters. -
test_chat_completions_streaming— Test streaming chat completion. -
test_chat_completions_with_provider_openrouter— Test chat completion with explicit OpenRouter provider. -
test_chat_completions_with_provider_featherless— Test chat completion with Featherless provider. -
test_chat_completions_with_provider_fireworks— Test chat completion with Fireworks provider. -
test_chat_completions_missing_api_key— Test chat completion without API key. -
test_chat_completions_empty_messages— Test chat completion with empty messages array. -
test_chat_completions_invalid_role— Test chat completion with invalid message role. -
test_chat_completions_empty_content— Test chat completion with empty message content. -
test_chat_completions_multiple_messages— Test chat completion with conversation history. -
test_chat_completions_with_tools— Test chat completion with function calling tools. -
test_chat_completions_response_format_json— Test chat completion with JSON response format. -
test_chat_completions_very_long_message— Test chat completion with very long message. -
test_chat_completions_session_id_parameter— Test chat completion with session_id query parameter. -
test_chat_completions_default_max_tokens— Test that max_tokens defaults to 950. -
test_chat_completions_default_temperature— Test that temperature defaults to 1.0.
-
-
TestChatCompletionsDeveloperRoleE2E (3 tests)
-
test_chat_completions_with_developer_role— Test chat completion with developer role message. -
test_chat_completions_developer_role_streaming— Test streaming chat completion with developer role. -
test_reasoning_models_with_developer_role— Test OpenAI reasoning models (o1/o3) with developer role.
-
17 tests
-
TestImagesE2E (17 tests)
-
test_images_basic_request— Test basic image generation request and response. -
test_images_with_single_image— Test image generation with single image. -
test_images_with_multiple_images— Test image generation with multiple images. -
test_images_different_sizes— Test image generation with different sizes. -
test_images_with_deepinfra_provider— Test image generation with DeepInfra provider. -
test_images_with_google_vertex_provider— Test image generation with Google Vertex AI provider. -
test_images_with_fal_provider— Test image generation with Fal.ai provider. -
test_images_invalid_provider— Test image generation with unsupported provider. -
test_images_missing_prompt— Test image generation without prompt. -
test_images_empty_prompt— Test image generation with empty prompt. -
test_images_missing_api_key— Test image generation without API key. -
test_images_very_long_prompt— Test image generation with very long prompt. -
test_images_special_characters_in_prompt— Test image generation with special characters in prompt. -
test_images_invalid_size— Test image generation with invalid size. -
test_images_invalid_number_of_images— Test image generation with invalid n parameter. -
test_images_default_size— Test image generation without size (should use default). -
test_images_default_provider— Test image generation without provider (should default to deepinfra).
-
19 tests
-
TestMessagesE2E (19 tests)
-
test_messages_basic_request— Test basic messages API request and response. -
test_messages_with_system_prompt— Test messages API with system prompt (Anthropic style). -
test_messages_with_all_parameters— Test messages API with all optional parameters. -
test_messages_streaming— Test streaming messages API. -
test_messages_with_provider_openrouter— Test messages API with explicit OpenRouter provider. -
test_messages_with_provider_featherless— Test messages API with Featherless provider. -
test_messages_missing_api_key— Test messages API without API key. -
test_messages_missing_max_tokens— Test messages API without required max_tokens (Anthropic requirement). -
test_messages_invalid_max_tokens— Test messages API with invalid max_tokens. -
test_messages_empty_messages— Test messages API with empty messages array. -
test_messages_invalid_role— Test messages API with invalid message role (Anthropic only allows user/assistant). -
test_messages_empty_content— Test messages API with empty message content. -
test_messages_conversation_history— Test messages API with conversation history. -
test_messages_with_tools— Test messages API with tool definitions (Claude tool use). -
test_messages_with_tool_choice— Test messages API with tool_choice parameter. -
test_messages_with_stop_sequences— Test messages API with stop_sequences (Claude feature). -
test_messages_with_top_k— Test messages API with top_k parameter (Anthropic-specific). -
test_messages_very_long_content— Test messages API with very long message. -
test_messages_metadata— Test messages API with metadata parameter.
-
15 tests
-
TestResponsesE2E (15 tests)
-
test_responses_basic_request— Test basic unified responses endpoint request and response. -
test_responses_with_all_parameters— Test responses endpoint with all optional parameters. -
test_responses_streaming— Test streaming responses endpoint. -
test_responses_with_provider— Test responses endpoint with specific provider. -
test_responses_with_json_response_format— Test responses endpoint with JSON response format. -
test_responses_multimodal_input— Test responses endpoint with multimodal input (text + image). -
test_responses_multiple_input_items— Test responses endpoint with multiple input items. -
test_responses_missing_api_key— Test responses endpoint without API key. -
test_responses_empty_input— Test responses endpoint with empty input array. -
test_responses_missing_model— Test responses endpoint without model. -
test_responses_with_tools— Test responses endpoint with tool definitions. -
test_responses_very_long_input— Test responses endpoint with very long input. -
test_responses_default_max_tokens— Test that max_tokens defaults to 950. -
test_responses_with_featherless_provider— Test responses endpoint with Featherless provider. -
test_responses_with_fireworks_provider— Test responses endpoint with Fireworks provider.
-
15 tests
-
TestSimplismartModelsE2E (8 tests)
-
test_simplismart_model_basic_request— Test basic chat completion request for each Simplismart model. -
test_simplismart_model_streaming— Test streaming chat completion for each Simplismart model. -
test_simplismart_model_with_system_prompt— Test Simplismart models with system prompt. -
test_simplismart_model_conversation_history— Test Simplismart models with conversation history. -
test_simplismart_model_with_temperature— Test Simplismart models with custom temperature. -
test_simplismart_model_with_top_p— Test Simplismart models with top_p parameter. -
test_simplismart_model_response_has_usage— Test that Simplismart model responses include usage information. -
test_simplismart_model_invalid_should_fail— Test that invalid Simplismart model ID returns appropriate error.
-
-
TestSimplismartModelAliasesE2E (1 tests)
-
test_simplismart_alias_resolution— Test that model aliases are correctly resolved.
-
-
TestSimplismartStreamingE2E (2 tests)
-
test_streaming_with_custom_params— Test streaming with custom temperature and max_tokens. -
test_streaming_response_structure— Test that streaming responses have correct SSE structure.
-
-
TestSimplismartLlamaModelsE2E (2 tests)
-
test_llama_3_1_8b_instruction_following— Test that Llama 3.1 8B follows instructions. -
test_llama_3_3_70b_reasoning_task— Test Llama 3.3 70B with a reasoning task.
-
-
TestSimplismartGemmaModelsE2E (1 tests)
-
test_gemma_3_27b_basic— Test Gemma 3 27B basic functionality.
-
-
TestSimplismartQwenModelsE2E (1 tests)
-
test_qwen_2_5_32b_basic— Test Qwen 2.5 32B basic functionality.
-
19 tests
-
TestStreamingE2E (6 tests)
-
test_streaming_chat_completions— Test streaming on chat completions endpoint. -
test_streaming_messages— Test streaming on messages endpoint. -
test_streaming_responses— Test streaming on responses endpoint. -
test_streaming_with_custom_parameters— Test streaming with custom temperature and tokens. -
test_non_streaming_chat_completions— Test non-streaming chat completions. -
test_non_streaming_messages— Test non-streaming messages endpoint.
-
-
TestProviderParameterE2E (13 tests)
-
test_provider_openrouter_chat— Test explicit OpenRouter provider on chat endpoint. -
test_provider_featherless_chat— Test explicit Featherless provider on chat endpoint. -
test_provider_fireworks_chat— Test explicit Fireworks provider on chat endpoint. -
test_provider_together_chat— Test explicit Together provider on chat endpoint. -
test_provider_huggingface_chat— Test explicit HuggingFace provider on chat endpoint. -
test_provider_openrouter_messages— Test explicit OpenRouter provider on messages endpoint. -
test_provider_openrouter_responses— Test explicit OpenRouter provider on responses endpoint. -
test_provider_deepinfra_images— Test explicit DeepInfra provider on images endpoint. -
test_provider_default_fallback— Test default provider fallback when not specified. -
test_provider_auto_detection_from_model_id— Test provider auto-detection from model ID. -
test_provider_alias_hug_to_huggingface— Test provider alias normalization (hug -> huggingface). -
test_provider_with_streaming— Test provider parameter works with streaming. -
test_multiple_providers_in_sequence— Test using different providers in sequence.
-
4 tests
-
TestSybilModelsE2E (4 tests)
-
test_sybil_model_basic_request— Test basic chat completion request for each Sybil model. -
test_sybil_model_streaming— Test streaming chat completion for each Sybil model. -
test_sybil_model_with_tools— Test Sybil model with tool calling (for models that support it). -
test_sybil_model_with_json_mode— Test Sybil model with JSON mode (for models that support it).
-
34 files, 326 tests
7 tests
-
TestAllenAIModelsDirectOpenRouter (5 tests)
-
test_model_basic_response— Test that each AllenAI model responds to a basic prompt. -
test_model_streaming— Test that each AllenAI model supports streaming. -
test_thinking_models_reasoning— Test that thinking models provide reasoning for complex questions. -
test_olmo_instruct_follows_instructions— Test that OLMo instruct model follows instructions well. -
test_model_with_conversation_history— Test that models handle multi-turn conversations.
-
-
TestAllenAIModelsViaGatewayz (2 tests)
-
test_model_via_gatewayz— Test AllenAI models through Gatewayz API. -
test_model_streaming_via_gatewayz— Test AllenAI models streaming through Gatewayz API.
-
19 tests
-
test_auth_users— Create test users for auth testing -
TestAuthRegistrationReferralIntegration (3 tests)
-
test_new_user_signup_with_referral_code— Test that new user signup WITH referral code: -
test_new_user_signup_with_invalid_referral_code— Test that invalid referral code doesn't block signup -
test_existing_user_login_ignores_referral_code— Test that existing users logging in don't process referral codes
-
-
TestReferralTrackingIntegration (3 tests)
-
test_track_referral_signup_creates_pending_record— Test that track_referral_signup creates pending referral record -
test_store_referred_by_code_on_signup— Test that referred_by_code is stored correctly -
test_multiple_signups_same_code— Test that multiple users can sign up with the same referral code
-
-
TestReferralNotificationIntegration (5 tests)
-
test_signup_notification_sent_to_referrer— Test that referrer receives email when someone signs up with their code -
test_notification_failure_doesnt_block_signup— Test that notification failures don't block the signup process -
test_notification_logs_attempt_before_sending— Test that notification logs attempt before sending email -
test_notification_logs_success_with_email— Test that successful notification logs include email address -
test_notification_logs_warning_on_failure— Test that failed notification logs warning with email address
-
-
TestReferralBackgroundTaskLogging (4 tests)
-
test_background_task_logs_when_referrer_has_no_email— Test that background task logs warning when referrer has no email -
test_background_task_logs_success_with_email— Test that background task logs success with referrer email -
test_background_task_logs_warning_when_notification_returns_false— Test that background task logs warning when notification returns False -
test_background_task_logs_notification_error_with_details— Test that background task logs notification errors with full details
-
-
TestReferralValidationDuringSignup (3 tests)
-
test_validate_code_before_signup— Test validating referral code before signup -
test_validate_prevents_self_referral_during_signup— Test that validation prevents self-referral during signup -
test_validate_checks_usage_limit— Test that validation checks usage limit
-
5 tests
-
test_braintrust_import— Test that Braintrust can be imported -
test_api_key_configured— Test that BRAINTRUST_API_KEY is configured -
test_logger_initialization— Test that Braintrust logger can be initialized -
test_basic_tracing— Test basic tracing functionality -
test_endpoint_tracing_syntax— Test that the chat endpoint tracing syntax is correct
8 tests
-
test_cerebras_qwen_api_direct— Direct test without pytest fixtures - useful for manual testing -
TestCerebrasQwen (7 tests)
-
test_cerebras_qwen_basic— Test basic Qwen model inference -
test_cerebras_qwen_streaming— Test streaming Qwen model inference -
test_cerebras_qwen_system_prompt— Test Qwen model with system prompt -
test_cerebras_qwen_multi_turn— Test multi-turn conversation with Qwen model -
test_cerebras_qwen_temperature_variation— Test Qwen model with different temperature settings -
test_cerebras_qwen_max_tokens— Test Qwen model with different max_tokens settings -
test_cerebras_qwen_response_format— Test response format from Qwen model
-
21 tests
-
TestChatCompletionsErrors (21 tests)
-
test_invalid_api_key— Test invalid API key returns detailed error. -
test_missing_authorization_header— Test missing authorization header returns detailed error. -
test_model_not_found— Test model not found returns suggestions. -
test_model_typo_suggests_correct_model— Test that typo in model name suggests correct model. -
test_empty_messages_array— Test empty messages array error. -
test_missing_messages_field— Test missing messages field error. -
test_invalid_message_format— Test invalid message format error. -
test_invalid_temperature— Test invalid parameter error for temperature. -
test_negative_max_tokens— Test invalid max_tokens parameter. -
test_insufficient_credits— Test insufficient credits error. -
test_request_id_in_all_errors— Test that all errors include request_id. -
test_request_id_propagation— Test that provided X-Request-ID is propagated. -
test_timestamp_in_errors— Test that all errors include timestamp. -
test_docs_url_in_errors— Test that appropriate errors include docs_url. -
test_suggestions_in_errors— Test that errors include actionable suggestions. -
test_provider_error— Test provider error returns detailed error. -
test_streaming_error_format— Test that errors in streaming mode are properly formatted. -
test_error_response_structure_complete— Test that error response has all expected fields. -
test_concurrent_requests_unique_ids— Test that concurrent requests get unique request IDs. -
test_internal_error_detailed— Test that internal errors return detailed responses. -
test_no_error_fields_are_none_in_response— Test that no fields with None values are included in response.
-
33 tests
-
TestDuplicateDetection (3 tests)
-
test_exact_duplicate_messages_same_content— Test that exact duplicate messages are detected -
test_duplicate_messages_different_timestamps— Test duplicate messages with different timestamps (e.g., retry scenario) -
test_similar_but_different_messages— Test that similar but different messages are both saved
-
-
TestHistoryInjection (3 tests)
-
test_history_injection_prepends_correctly— Test that history is prepended to new messages in correct order -
test_empty_history_handling— Test handling of session with no history -
test_history_respects_user_ownership— Test that users can only access their own chat history
-
-
TestMessageOrdering (2 tests)
-
test_messages_ordered_by_created_at— Test that messages are returned in chronological order -
test_alternating_user_assistant_pattern— Test proper conversation flow alternating between user and assistant
-
-
TestEdgeCases (5 tests)
-
test_empty_message_content— Test handling of empty message content -
test_very_long_message_content— Test handling of very long messages -
test_special_characters_in_content— Test handling of special characters and unicode -
test_null_model_field— Test handling when model field is None -
test_zero_and_negative_tokens— Test handling of zero and negative token counts
-
-
TestMultimodalContent (2 tests)
-
test_text_only_content— Test standard text-only message -
test_json_string_content— Test handling of JSON-like string content
-
-
TestSessionManagement (4 tests)
-
test_create_session_with_defaults— Test session creation with default values -
test_update_session_title— Test updating session title -
test_delete_session_soft_delete— Test that delete is a soft delete (sets is_active=False) -
test_get_user_sessions_excludes_deleted— Test that deleted sessions are not returned
-
-
TestPagination (2 tests)
-
test_session_pagination— Test pagination of user sessions -
test_session_ordering_by_updated_at— Test that sessions are ordered by updated_at desc
-
-
TestSearch (3 tests)
-
test_search_by_title— Test searching sessions by title -
test_search_by_message_content— Test searching sessions by message content -
test_search_case_insensitive— Test that search is case-insensitive
-
-
TestStatistics (2 tests)
-
test_session_stats_accuracy— Test that session stats are calculated correctly -
test_stats_exclude_inactive_sessions— Test that stats exclude deleted (inactive) sessions
-
-
TestConcurrency (2 tests)
-
test_concurrent_message_saves— Test saving messages concurrently to same session -
test_concurrent_session_creation— Test creating sessions concurrently
-
-
TestErrorHandling (3 tests)
-
test_get_nonexistent_session— Test getting a session that doesn't exist -
test_update_nonexistent_session— Test updating a session that doesn't exist -
test_delete_nonexistent_session— Test deleting a session that doesn't exist
-
-
TestRealWorldScenarios (2 tests)
-
test_full_conversation_flow— Test complete conversation lifecycle -
test_multi_session_user— Test user with multiple concurrent sessions
-
1 tests
-
test_chutes_models— Test loading Chutes models from the catalog
14 tests
-
TestCreditDeductionForOpenAIModels (4 tests)
-
test_gpt4o_pricing_lookup— Test that GPT-4o model gets correct pricing -
test_gpt4o_without_prefix_uses_alias— Test that 'gpt-4o' (without openai/ prefix) resolves via alias -
test_cost_calculation_openai— Test cost calculation for OpenAI models -
test_credit_handler_deducts_for_openai— Test that credit handler deducts credits for OpenAI model
-
-
TestCreditDeductionForAnthropicModels (4 tests)
-
test_claude_opus_pricing_lookup— Test that Claude Opus model gets correct pricing -
test_claude_sonnet_pricing_lookup— Test that Claude Sonnet model gets correct pricing -
test_cost_calculation_anthropic— Test cost calculation for Anthropic Claude Opus -
test_credit_handler_deducts_for_anthropic— Test that credit handler deducts credits for Anthropic model
-
-
TestTrialUserCreditHandling (1 tests)
-
test_trial_user_no_credit_deduction— Test that trial users don't have credits deducted
-
-
TestTrialOverrideForPaidUsers (1 tests)
-
test_paid_user_with_stale_trial_gets_charged— Test that paid users with stale is_trial=True flag get charged
-
-
TestDefaultPricingAlerts (2 tests)
-
test_unknown_model_uses_default_pricing— Test that unknown models fall back to default pricing and are tracked -
test_high_value_model_default_pricing_alert— Test that high-value models (OpenAI, Anthropic) trigger alerts on default pricing
-
-
TestAsyncCostCalculation (2 tests)
-
test_calculate_cost_async_works— Test that async cost calculation works correctly -
test_free_model_returns_zero_cost_async— Test that free models return $0 cost in async version
-
26 tests
-
test_api_keys— Create test users with API keys -
TestCouponAdminEndpoints (10 tests)
-
test_create_global_coupon— Test creating a global promotional coupon -
test_create_user_specific_coupon— Test creating a user-specific coupon -
test_create_coupon_invalid_negative_value— Test that negative coupon values are rejected -
test_create_user_specific_without_assigned_user— Test that user-specific coupons require assigned_to_user_id -
test_list_coupons— Test listing all coupons -
test_list_coupons_with_filters— Test listing coupons with filters -
test_get_coupon_by_id— Test getting a specific coupon by ID -
test_get_nonexistent_coupon— Test getting a coupon that doesn't exist -
test_update_coupon— Test updating coupon fields -
test_deactivate_coupon— Test deactivating a coupon
-
-
TestCouponUserEndpoints (10 tests)
-
test_get_available_coupons— Test getting available coupons for a user -
test_get_available_coupons_unauthorized— Test that getting available coupons requires authentication -
test_redeem_global_coupon— Test redeeming a global coupon -
test_redeem_user_specific_coupon— Test redeeming a user-specific coupon -
test_redeem_coupon_twice_rejected— Test that redeeming the same coupon twice is rejected -
test_redeem_invalid_coupon— Test redeeming an invalid coupon code -
test_redeem_expired_coupon— Test that expired coupons cannot be redeemed -
test_redeem_deactivated_coupon— Test that deactivated coupons cannot be redeemed -
test_get_redemption_history— Test getting user redemption history -
test_get_redemption_history_with_limit— Test getting redemption history with limit parameter
-
-
TestCouponAnalytics (2 tests)
-
test_get_coupon_analytics— Test getting analytics for a specific coupon -
test_get_system_stats— Test getting system-wide coupon statistics
-
-
TestCouponEdgeCases (3 tests)
-
test_create_coupon_without_admin_key— Test that creating coupons requires admin API key -
test_redeem_without_authentication— Test that redeeming requires authentication -
test_wrong_user_cannot_redeem_user_specific_coupon— Test that user-specific coupons can only be redeemed by the assigned user
-
16 tests
-
test_users— Create test users with API keys for referral testing -
TestEndToEndReferralFlow (8 tests)
-
test_complete_referral_flow_success— Test complete successful referral flow: -
test_referral_stats_accuracy— Test that referral stats are accurate after multiple referrals -
test_referral_bonus_minimum_purchase_enforcement— Test that referral bonus requires minimum $10 purchase -
test_self_referral_prevention— Test that users cannot use their own referral code -
test_max_referral_uses_enforcement— Test that referral codes cannot exceed maximum uses -
test_one_referral_code_per_user— Test that users can only use one referral code -
test_referral_code_uniqueness— Test that all generated referral codes are unique -
test_bonus_only_on_first_purchase— Test that referral bonus only applies on first purchase
-
-
TestReferralEdgeCases (3 tests)
-
test_invalid_referral_code— Test handling of invalid referral code -
test_deleted_referrer— Test handling when referrer is deleted -
test_partial_credit_failure_handling— Test handling when credit addition fails for one user
-
-
TestReferralAPIEndpoints (4 tests)
-
test_get_referral_code_endpoint— Test GET /referral/code endpoint -
test_get_referral_stats_endpoint— Test GET /referral/stats endpoint -
test_validate_referral_endpoint— Test POST /referral/validate endpoint -
test_generate_referral_endpoint— Test POST /referral/generate endpoint
-
2 tests
-
test_fireworks_with_transform— Test that Fireworks accepts model IDs after transformation -
test_openrouter_with_transform— Test that OpenRouter still works with transformed model IDs
28 tests
-
TestHealthEndpoints (3 tests)
-
test_health_endpoint_exists— Regression: GET /health must exist and return 200 -
test_ping_endpoint_exists— Regression: GET /ping must exist -
test_root_endpoint_exists— Regression: GET / must exist
-
-
TestAuthenticationEndpoints (3 tests)
-
test_user_balance_endpoint_exists— Regression: GET /user/balance must exist -
test_user_profile_endpoint_exists— Regression: GET /user/profile must exist -
test_user_monitor_endpoint_exists— Regression: GET /user/monitor must exist
-
-
TestChatCompletionsEndpoints (2 tests)
-
test_v1_chat_completions_endpoint_exists— CRITICAL: POST /v1/chat/completions must exist and process requests -
test_v1_chat_completions_streaming_exists— CRITICAL: POST /v1/chat/completions with stream=true must work
-
-
TestUnifiedResponsesEndpoint (2 tests)
-
test_v1_responses_endpoint_exists— CRITICAL: POST /v1/responses must exist (unified API) -
test_v1_responses_with_json_format— Regression: /v1/responses must support response_format parameter
-
-
TestAnthropicMessagesEndpoint (2 tests)
-
test_v1_messages_endpoint_exists— CRITICAL: POST /v1/messages must exist (Anthropic/Claude API) -
test_v1_messages_with_system_parameter— Regression: /v1/messages must support separate 'system' parameter
-
-
TestAPIKeyEndpoints (2 tests)
-
test_list_api_keys_endpoint_exists— Regression: GET /user/api-keys must exist -
test_create_api_key_endpoint_exists— Regression: POST /user/api-keys must exist
-
-
TestPaymentEndpoints (2 tests)
-
test_stripe_checkout_session_endpoint_exists— Regression: Stripe checkout session endpoint must exist -
test_list_payments_endpoint_exists— Regression: Payments list endpoint must exist
-
-
TestChatHistoryEndpoints (3 tests)
-
test_list_chat_sessions_endpoint_exists— Regression: Chat sessions list endpoint must exist -
test_create_chat_session_endpoint_exists— Regression: Chat session creation endpoint must exist -
test_get_chat_session_endpoint_exists— Regression: GET /chat-history/sessions/{session_id} must exist
-
-
TestCatalogEndpoints (2 tests)
-
test_catalog_models_endpoint_exists— Regression: GET /v1/models must exist -
test_catalog_providers_endpoint_exists— Regression: GET /v1/provider must exist
-
-
TestRankingEndpoints (2 tests)
-
test_ranking_models_endpoint_exists— Regression: GET /ranking/models must exist -
test_ranking_apps_endpoint_exists— Regression: GET /ranking/apps must exist
-
-
TestAdminEndpoints (2 tests)
-
test_admin_list_users_endpoint_exists— Regression: Admin list users endpoint must exist -
test_admin_add_credits_endpoint_exists— Regression: Admin add credits endpoint must exist
-
-
TestRateLimitEndpoints (1 tests)
-
test_get_rate_limits_endpoint_exists— Regression: Rate limits endpoint must exist
-
-
TestActivityEndpoints (1 tests)
-
test_get_activity_endpoint_exists— Regression: Activity endpoint must exist
-
-
TestNotificationEndpoints (1 tests)
-
test_get_notifications_endpoint_exists— Regression: Notifications endpoint must exist
-
28 tests
-
TestHealthEndpoints (3 tests)
-
test_health_check— Test GET /health returns 200 -
test_root_endpoint— Test GET / returns welcome message -
test_ping_endpoint— Test GET /ping returns pong
-
-
TestAuthEndpoints (2 tests)
-
test_auth_endpoint_exists— Test POST /auth endpoint exists -
test_user_balance_endpoint— Test GET /user/balance requires authentication
-
-
TestChatEndpoints (2 tests)
-
test_chat_completions_endpoint_exists— Test POST /v1/chat/completions endpoint exists and processes requests -
test_chat_completions_requires_auth— Test /v1/chat/completions requires authentication
-
-
TestUserEndpoints (3 tests)
-
test_credit_transactions_endpoint— Test GET /user/credit-transactions endpoint exists -
test_user_profile_endpoint— Test GET /user/profile endpoint exists -
test_user_monitor_endpoint— Test GET /user/monitor endpoint exists
-
-
TestPaymentEndpoints (3 tests)
-
test_stripe_checkout_session_endpoint— Test POST /api/stripe/checkout-session endpoint exists -
test_stripe_webhook_endpoint_exists— Test POST /api/stripe/webhook endpoint exists -
test_payments_list_endpoint— Test GET /api/stripe/payments endpoint exists
-
-
TestRankingEndpoints (2 tests)
-
test_ranking_models_endpoint— Test GET /ranking/models endpoint exists -
test_ranking_apps_endpoint— Test GET /ranking/apps endpoint exists
-
-
TestAPIKeyEndpoints (2 tests)
-
test_list_api_keys_endpoint— Test GET /api-keys endpoint exists -
test_create_api_key_endpoint— Test POST /api-keys endpoint exists
-
-
TestAdminEndpoints (2 tests)
-
test_admin_list_users_endpoint— Test GET /admin/users endpoint exists -
test_admin_add_credits_endpoint— Test POST /admin/users/{user_id}/credits endpoint exists
-
-
TestCatalogEndpoints (6 tests)
-
test_catalog_models_endpoint— Test GET /catalog/models endpoint exists -
test_catalog_providers_endpoint— Test GET /catalog/providers endpoint exists -
test_public_models_endpoint— Test GET /models endpoint mirrors catalog route -
test_public_model_detail_endpoint_with_hf_developer— Test GET /models/{developer}/{model} supports Hugging Face-style slugs -
test_catalog_models_groq_gateway— Test GET /catalog/models with Groq gateway parameter -
test_public_models_groq_gateway— Test GET /models with Groq gateway parameter
-
-
TestChatHistoryEndpoints (2 tests)
-
test_chat_sessions_list_endpoint— Test GET /chat/sessions endpoint exists -
test_create_chat_session_endpoint— Test POST /chat/sessions endpoint exists
-
-
TestIntegration (1 tests)
-
test_full_chat_flow— Test complete chat completion flow: auth -> credit check -> API call -> deduct credits
-
1 tests
-
test_fireworks_api— Test Fireworks API directly
2 tests
-
TestFunctionCallingIntegration (2 tests)
-
test_chat_completions_with_tools— Test that tools parameter is passed through to provider -
test_huggingface_with_tools— Test that HuggingFace receives tools parameter
-
6 tests
-
test_user— Create a test user with initial credits -
TestGoogleVertexE2E (4 tests)
-
test_01_vertex_credentials_available— Test that Google Vertex credentials are properly configured -
test_02_create_user_and_purchase_credits— Test user creation and credit purchase -
test_03_call_all_gemini_models— Test all Google Gemini models via Vertex AI -
test_04_verify_streaming_support— Test streaming support for Google Gemini models
-
-
TestVertexAIDirectCall (1 tests)
-
test_vertex_client_can_make_request— Test that the Vertex AI client can make a direct API call
-
1 tests
test_hf_case
5 tests
-
test_fetch_models— Test fetching models from Hugging Face API -
test_cache— Test caching mechanism -
test_fetch_hug_wrapper— Test the fetch_models_from_hug wrapper function -
test_search— Test search functionality -
test_model_info— Test fetching specific model info
1 tests
-
test_api— Test the API with different model formats
1 tests
-
test_near_qwen_api— Test Near AI API with Qwen3-30B model
2 tests
-
test_openrouter_auto— Send a test message to openrouter/auto -
test_code_only— Test just the code paths without making API calls
1 tests
test_model
8 tests
-
test_users_for_webhook— Create test users for webhook testing -
TestPaymentWebhookReferralIntegration (5 tests)
-
test_checkout_completed_triggers_referral_bonus— Test that checkout.session.completed webhook triggers referral bonus -
test_checkout_below_minimum_no_bonus— Test that purchases < $10 do NOT trigger referral bonus -
test_second_purchase_no_bonus— Test that second purchase does NOT trigger referral bonus -
test_payment_without_referral_code— Test that users without referral code just get payment credits -
test_payment_succeeds_even_if_referral_fails— CRITICAL: Test that payment processing succeeds even if referral bonus fails
-
-
TestWebhookEdgeCases (2 tests)
-
test_webhook_with_missing_metadata— Test webhook handling when metadata is missing -
test_webhook_with_invalid_user_id— Test webhook handling with non-existent user ID
-
1 tests
test_provider_case_sensitivity
10 tests
-
test_constants— Verify referral system constants -
TestReferralSignupTracking (4 tests)
-
test_track_referral_signup_success— Test successful tracking of referral signup -
test_track_referral_signup_invalid_code— Test tracking with invalid referral code -
test_track_referral_signup_self_referral— Test that self-referral is blocked -
test_track_referral_signup_max_uses_reached— Test that codes with max uses cannot be used
-
-
TestReferralNotifications (2 tests)
-
test_send_referral_signup_notification— Test sending signup notification to referrer -
test_send_referral_bonus_notification— Test sending bonus notification to both users
-
-
TestReferralBonusWithPendingRecord (1 tests)
-
test_apply_bonus_updates_pending_referral— Test that bonus application updates existing pending referral record
-
-
TestTrialCredits (1 tests)
-
test_new_user_gets_trial_credits— Test new users receive $5 trial credits
-
-
TestEndToEndReferralFlow (1 tests)
-
test_complete_referral_flow— Test complete referral flow:
-
12 tests
-
test_db_users— Create test users for database testing -
TestReferralCodeUniqueness (2 tests)
-
test_referral_code_uniqueness_constraint— Test that database enforces referral code uniqueness -
test_generate_unique_codes_at_scale— Test that code generation produces unique codes at scale
-
-
TestConcurrentReferralUsage (2 tests)
-
test_concurrent_signup_same_code— Test multiple users signing up with same code concurrently -
test_concurrent_bonus_application— Test concurrent bonus applications (edge case)
-
-
TestReferralUsageLimits (1 tests)
-
test_usage_limit_enforced_in_database— Test that database correctly tracks and enforces usage limits
-
-
TestReferralStatusTransitions (2 tests)
-
test_pending_to_completed_transition— Test that referral status correctly transitions from pending to completed -
test_cannot_complete_twice— Test that referral cannot be completed twice
-
-
TestDataIntegrity (3 tests)
-
test_orphaned_referral_prevention— Test that referral records reference valid users -
test_referral_code_persistence— Test that referral codes persist correctly in database -
test_referred_by_code_persistence— Test that referred_by_code persists correctly
-
-
TestCreditTransactionIntegrity (1 tests)
-
test_credit_transactions_created_for_bonuses— Test that credit transactions are created when bonuses are applied
-
18 tests
-
TestProviderSelectorBasics (2 tests)
-
test_get_model_providers— Test getting available providers for a model -
test_check_provider_health— Test checking provider health status
-
-
TestMultiProviderRegistry (3 tests)
-
test_get_model— Test retrieving a model from registry -
test_select_provider— Test provider selection logic -
test_get_fallback_providers— Test getting fallback providers
-
-
TestProviderFailover (3 tests)
-
test_execute_with_failover_success— Test successful execution with failover -
test_execute_with_failover_retry— Test failover retries with different providers -
test_execute_with_failover_all_fail— Test when all providers fail
-
-
TestCircuitBreaker (3 tests)
-
test_health_tracker_records_success— Test recording successful requests -
test_health_tracker_records_failure— Test recording failed requests -
test_circuit_breaker_opens_after_threshold— Test circuit breaker opens after failure threshold
-
-
TestModelPrompting (2 tests)
-
test_prompt_gpt4_through_api— Test prompting GPT-4 through the chat API -
test_model_routing_with_mock_providers— Test model routing with mocked provider responses
-
-
TestProviderSpecificRouting (2 tests)
-
test_route_to_openrouter— Test explicit routing to OpenRouter -
test_route_gemini_model— Test routing Google Gemini model
-
-
TestModelTransformation (1 tests)
-
test_detect_provider_from_model_id— Test automatic provider detection from model ID
-
-
TestCatalogIntegration (2 tests)
-
test_get_models_catalog— Test retrieving models catalog -
test_catalog_includes_multi_provider_models— Test that catalog includes multi-provider model info
-
3 tests
-
test_streaming_response— Test 1: Streaming Response -
test_non_streaming_response— Test 2: Non-Streaming Response (for comparison) -
test_all_smoke_tests_summary— Final summary after all smoke tests
11 tests
-
TestCheckoutSessionMetadata (2 tests)
-
test_checkout_session_includes_credits_cents_field— Verify checkout session metadata includes 'credits_cents' field -
test_checkout_session_includes_backward_compatible_credits_field— Verify checkout session metadata includes 'credits' field for backward compatibility
-
-
TestWebhookMetadataHandling (3 tests)
-
test_webhook_parses_credits_cents_field— Verify webhook correctly parses credits_cents from metadata -
test_webhook_handles_missing_credits_cents_fallback_to_credits— Verify webhook falls back to 'credits' field if 'credits_cents' missing -
test_webhook_always_marked_processed_even_on_error— Verify webhook is marked as processed even if handler fails
-
-
TestWebhookHttpStatus (2 tests)
-
test_webhook_endpoint_returns_200_on_success— Verify webhook endpoint returns HTTP 200 on success -
test_webhook_endpoint_returns_200_on_error— Verify webhook endpoint returns HTTP 200 even on processing errors
-
-
TestMetadataExtraction (4 tests)
-
test_coerce_to_int_handles_string_numbers— Verify _coerce_to_int correctly converts string numbers -
test_coerce_to_int_handles_float_numbers— Verify _coerce_to_int correctly converts floats -
test_coerce_to_int_handles_none— Verify _coerce_to_int handles None gracefully -
test_metadata_to_dict_handles_various_formats— Verify _metadata_to_dict handles various metadata formats
-
7 tests
-
TestSupabaseHttpxClientAuth (5 tests)
-
test_httpx_client_with_auth_headers_can_query_supabase— Test that an httpx client configured like our production client can query Supabase. -
test_httpx_client_without_auth_headers_fails— Test that an httpx client WITHOUT auth headers fails to authenticate. -
test_httpx_client_with_only_apikey_header_succeeds— Test that apikey header alone is sufficient for read operations. -
test_supabase_client_initialization_succeeds— Test that the actual Supabase client can be initialized and query the database. -
test_postgrest_session_has_correct_headers— Test that after initialization, the postgrest session has the correct auth headers.
-
-
TestSupabaseConnectionHealth (2 tests)
-
test_can_reach_supabase_health_endpoint— Test basic connectivity to Supabase. -
test_supabase_url_has_correct_format— Test that SUPABASE_URL is correctly formatted.
-
1 tests
-
test_thinking_tags_in_stream— Test that thinking tags are properly passed through in streaming responses
11 tests
-
TestTrialCreditAllocation (2 tests)
-
test_new_user_receives_5_dollar_credits— Test that new users receive $5 in trial credits -
test_trial_credits_configuration— Test that configuration is set correctly
-
-
TestDailyLimitDuringTrial (2 tests)
-
test_trial_user_limited_to_1_dollar_per_day— Test that trial users can only use $1/day even with $5 credits -
test_multiple_small_requests_within_daily_limit— Test multiple small API calls that stay within $1/day limit
-
-
TestTrialPeriodScenario (1 tests)
-
test_three_day_trial_usage_pattern— Simulate a user using $1/day for 3 days during trial
-
-
TestPostTrialCredits (1 tests)
-
test_post_trial_credits_available— Test that $2 remaining credits can be used after trial expires
-
-
TestFraudMitigation (1 tests)
-
test_bot_cannot_drain_credits_instantly— Test that a bot cannot drain all $5 credits in one day
-
-
TestConfigurationValues (4 tests)
-
test_trial_credits_is_5_dollars— Verify TRIAL_CREDITS_AMOUNT is $5 -
test_daily_limit_is_1_dollar— Verify DAILY_USAGE_LIMIT is $1 -
test_trial_duration_is_3_days— Verify TRIAL_DURATION_DAYS is 3 -
test_trial_daily_limit_is_1_dollar— Verify TRIAL_DAILY_LIMIT is $1
-
10 tests
-
TestUniqueModelsBasic (10 tests)
-
test_database_layer_get_unique_models— Test database layer can fetch unique models. -
test_database_layer_transformation— Test database-to-API transformation. -
test_service_layer_unique_models_cache— Test service layer unique models caching. -
test_service_layer_get_cached_models_flat_mode— Test backward compatibility - flat mode. -
test_service_layer_get_cached_models_unique_mode— Test unique mode via get_cached_models. -
test_route_layer_default_behavior— Test /models endpoint default behavior (backward compatibility). -
test_route_layer_unique_models_false— Test /models endpoint with unique_models=false. -
test_route_layer_unique_models_true— Test /models endpoint with unique_models=true. -
test_route_layer_unique_models_with_specific_gateway— Test that unique_models is ignored for provider-specific queries. -
test_deduplication_check— Test that unique_models=true actually deduplicates.
-
6 tests
-
test_vercel_config— Test that Vercel AI Gateway configuration is present -
test_vercel_client_import— Test that the Vercel AI Gateway client can be imported -
test_vercel_model_mappings— Test Vercel AI Gateway model ID transformations -
test_vercel_provider_detection— Test that Vercel AI Gateway models are properly detected -
test_failover_chain— Test that Vercel AI Gateway is in the failover chain -
test_chat_route_integration— Test that Vercel AI Gateway is integrated in the chat route
3 files, 62 tests
16 tests
-
TestAutoSentryMiddleware (13 tests)
-
test_successful_request_no_sentry_capture— Test that successful requests don't trigger Sentry -
test_error_captured_to_sentry— Test that errors are captured to Sentry with context -
test_request_context_extraction— Test that request context is properly extracted -
test_endpoint_type_detection_inference— Test endpoint type detection for inference endpoints -
test_endpoint_type_detection_payment— Test endpoint type detection for payment endpoints -
test_endpoint_type_detection_auth— Test endpoint type detection for auth endpoints -
test_sensitive_headers_sanitized— Test that sensitive headers are sanitized -
test_revenue_critical_tag— Test that revenue-critical endpoints are tagged -
test_http_exception_handling— Test that HTTPExceptions are not captured by middleware to avoid duplicates -
test_sentry_unavailable_no_error— Test that middleware works even when Sentry is unavailable -
test_slow_request_breadcrumb— Test that slow requests generate breadcrumbs -
test_middleware_determines_endpoint_types_correctly— Test endpoint type determination logic -
test_middleware_categorizes_http_errors_correctly— Test HTTP error categorization
-
-
TestAutoSentryMiddlewareEdgeCases (3 tests)
-
test_missing_client_info— Test handling when request.client is None -
test_empty_headers— Test handling of empty headers -
test_sanitize_headers_edge_cases— Test header sanitization with various input
-
34 tests
-
TestVelocityModeActivation (4 tests)
-
test_velocity_mode_not_activated_below_threshold— Test that velocity mode does not activate when error rate is below threshold -
test_velocity_mode_activated_above_threshold— Test that velocity mode activates when error rate exceeds threshold -
test_velocity_mode_not_activated_insufficient_samples— Test that velocity mode requires minimum sample size -
test_velocity_mode_activation_increments_counter— Test that activation counter increments
-
-
TestVelocityModeDeactivation (2 tests)
-
test_velocity_mode_deactivates_after_cooldown— Test that velocity mode deactivates after cooldown period -
test_velocity_mode_stays_active_during_cooldown— Test that velocity mode stays active during cooldown
-
-
TestErrorClassification (4 tests)
-
test_4xx_errors_not_counted— Test that 4xx errors (client errors) are not counted as system errors -
test_5xx_errors_counted— Test that 5xx errors (server errors) are counted -
test_499_slow_requests_counted— Test that 499 errors with slow duration (>5s) are counted -
test_499_fast_requests_not_counted— Test that 499 errors with fast duration (<5s) are not counted
-
-
TestRateLimitCalculation (3 tests)
-
test_effective_limit_normal_mode— Test that limits are normal when velocity mode is inactive -
test_effective_limit_velocity_mode— Test that limits are reduced during velocity mode -
test_effective_limit_minimum_of_one— Test that effective limit never goes below 1
-
-
TestAuthenticatedUserExemption (5 tests)
-
test_bearer_token_detected— Test that Bearer token format is detected -
test_gw_api_key_detected— Test that Gatewayz API key format is detected -
test_generic_api_key_detected— Test that generic long API keys are detected -
test_no_authorization_header— Test that request without auth header is not authenticated -
test_short_authorization_header— Test that short auth headers are not considered authenticated
-
-
TestIPTierDetection (3 tests)
-
test_datacenter_user_agent_detected— Test that datacenter IPs are detected by user agent -
test_proxy_headers_detected— Test that proxy headers indicate datacenter IP -
test_residential_ip_not_detected_as_datacenter— Test that residential IPs are not flagged as datacenter
-
-
TestFingerprintGeneration (3 tests)
-
test_fingerprint_generation— Test that fingerprint is generated from headers -
test_same_headers_produce_same_fingerprint— Test that identical headers produce identical fingerprints -
test_different_headers_produce_different_fingerprints— Test that different headers produce different fingerprints
-
-
TestRequestOutcomeRecording (2 tests)
-
test_request_outcome_recorded— Test that request outcomes are recorded -
test_old_entries_cleaned— Test that old entries are removed from request log
-
-
TestRateLimitHeaders (1 tests)
-
test_rate_limit_headers_present— Test that 429 responses include rate limit headers
-
-
TestIntegrationScenarios (2 tests)
-
test_health_endpoint_bypasses_security— Test that health endpoints bypass security checks -
test_normal_request_allowed— Test that normal requests are allowed
-
-
TestVelocityModeConfiguration (2 tests)
-
test_configuration_constants— Test that configuration constants are set correctly -
test_ip_limit_constants— Test that IP limit constants are set correctly
-
-
TestEdgeCases (3 tests)
-
test_empty_request_log— Test that velocity mode doesn't activate with empty log -
test_deque_max_length_respected— Test that request log respects maxlen (10000) -
test_client_ip_extraction— Test client IP extraction from X-Forwarded-For
-
12 tests
-
TestSelectiveGZipMiddleware (8 tests)
-
test_small_json_not_compressed— Test that small JSON responses are NOT compressed (below minimum_size) -
test_large_json_compressed— Test that large JSON responses ARE compressed -
test_sse_stream_not_compressed— Test that SSE streaming responses are NOT compressed -
test_sse_stream_without_explicit_headers_not_compressed— Test that SSE streaming is NOT compressed even without explicit headers -
test_ndjson_stream_not_compressed— Test that NDJSON streaming responses are NOT compressed -
test_binary_stream_with_no_buffering_header_not_compressed— Test that responses with X-Accel-Buffering: no are NOT compressed -
test_no_gzip_without_accept_encoding— Test that responses are NOT compressed when client doesn't accept gzip -
test_vary_header_added_for_compressed_response— Test that Vary: Accept-Encoding header is added for compressed responses
-
-
TestSelectiveGZipMiddlewareEdgeCases (2 tests)
-
test_streaming_media_types_constant— Test that STREAMING_MEDIA_TYPES contains expected types -
test_compress_method— Test the internal _compress method
-
-
TestStreamingHeadersIntegration (2 tests)
-
test_sse_headers_complete— Test that all expected SSE headers are present -
test_chunks_received_individually— Test that SSE chunks can be received as they stream
-
17 files, 121 tests
2 tests
-
TestAvailabilityRoutes (2 tests)
-
test_router_exists— Test that router is defined -
test_module_imports— Test that module imports successfully
-
17 tests
-
TestNormalizeDeveloperSegment (5 tests)
test_normalize_nonetest_normalize_empty_stringtest_normalize_with_at_symboltest_normalize_regular_stringtest_normalize_non_string
-
TestNormalizeModelSegment (5 tests)
test_normalize_nonetest_normalize_empty_stringtest_normalize_preserves_casingtest_normalize_strips_whitespacetest_normalize_non_string
-
TestAnnotateProviderSources (7 tests)
test_annotate_empty_listtest_annotate_nonetest_annotate_single_providertest_annotate_multiple_providerstest_annotate_preserves_existing_datatest_annotate_doesnt_duplicate_sourcetest_annotate_adds_new_source
1 tests
-
test_chat_history_data— Check if chat history data exists in database
9 tests
-
TestChatHistoryPerformance (9 tests)
-
test_create_session_uses_cached_user_lookup— create_session should use cached user lookup -
test_create_session_uses_background_logging— create_session should use background activity logging -
test_create_session_logs_performance_metrics— create_session should log performance metrics -
test_create_session_returns_success_response— create_session should return successful response -
test_create_session_invalid_api_key— create_session should return 401 for invalid API key -
test_create_session_handles_background_logging_failure— create_session should handle background logging failures gracefully -
test_create_session_background_logging_includes_metadata— create_session should pass metadata to background logging -
test_create_session_with_default_model— create_session should work without explicit model -
test_create_session_with_empty_title— create_session should generate title if not provided
-
2 tests
-
TestCouponsRoutes (2 tests)
-
test_router_exists— Test that router is defined -
test_module_imports— Test that module imports successfully
-
2 tests
-
TestErrorMonitorRoutes (2 tests)
-
test_router_exists— Test that router is defined -
test_module_imports— Test that module imports successfully
-
4 tests
-
test_health_timeline_imports_successfully— Test that health_timeline module imports without errors. -
test_health_timeline_uses_correct_supabase_import— Test that health_timeline uses get_supabase_client (not get_supabase_admin). -
test_supabase_config_exports— Test that supabase_config exports the correct functions. -
test_health_timeline_endpoints_defined— Test that health timeline endpoints are properly defined.
29 tests
-
TestHealthEndpoints (2 tests)
-
test_get_all_provider_health— Test getting health scores for all providers -
test_get_provider_health— Test getting health score for specific provider
-
-
TestErrorEndpoints (2 tests)
-
test_get_provider_errors— Test getting recent errors for a provider -
test_get_provider_errors_with_limit— Test error endpoint with custom limit
-
-
TestStatsEndpoints (2 tests)
-
test_get_realtime_stats— Test getting real-time statistics -
test_get_hourly_stats— Test getting hourly stats for a provider
-
-
TestCircuitBreakerEndpoints (2 tests)
-
test_get_all_circuit_breakers— Test getting all circuit breaker states -
test_get_provider_circuit_breakers— Test getting circuit breakers for specific provider
-
-
TestProviderComparisonEndpoint (1 tests)
-
test_get_provider_comparison— Test provider comparison endpoint
-
-
TestLatencyEndpoints (3 tests)
-
test_get_latency_percentiles— Test getting latency percentiles -
test_get_latency_percentiles_custom— Test latency percentiles with custom percentiles -
test_get_latency_trends— Test getting latency trends
-
-
TestAnomalyEndpoints (1 tests)
-
test_get_anomalies— Test anomaly detection endpoint
-
-
TestBusinessMetricsEndpoints (4 tests)
-
test_get_trial_analytics— Test trial analytics endpoint -
test_get_cost_analysis— Test cost analysis endpoint -
test_get_error_rates— Test error rates endpoint -
test_get_token_efficiency— Test token efficiency endpoint
-
-
TestSentryTunnelEndpoint (12 tests)
-
test_sentry_tunnel_empty_body— Test that empty body returns 400 -
test_sentry_tunnel_invalid_envelope— Test that invalid envelope format returns 400 -
test_sentry_tunnel_no_dsn— Test that envelope without DSN returns 400 -
test_sentry_tunnel_blocked_host— Test that non-Sentry hosts are blocked -
test_sentry_tunnel_ssrf_prevention_suffix_attack— Test that SSRF attacks via suffix matching are blocked (e.g., evil-sentry.io) -
test_sentry_tunnel_ssrf_prevention_malicious_subdomain— Test that SSRF attacks via malicious subdomains are blocked -
test_sentry_tunnel_null_hostname— Test that malformed DSN with null hostname is rejected -
test_sentry_tunnel_non_dict_json— Test that non-dict JSON envelope returns 400 -
test_sentry_tunnel_string_json— Test that string JSON envelope returns 400 -
test_sentry_tunnel_number_json— Test that number JSON envelope returns 400 -
test_sentry_tunnel_null_json— Test that null JSON envelope returns 400 -
test_sentry_tunnel_valid_envelope— Test that valid Sentry envelope is forwarded
-
2 tests
-
TestNotificationsRoutes (2 tests)
-
test_router_exists— Test that router is defined -
test_module_imports— Test that module imports successfully
-
2 tests
-
TestOptimizationMonitorRoutes (2 tests)
-
test_router_exists— Test that router is defined -
test_module_imports— Test that module imports successfully
-
2 tests
-
TestPingRoutes (2 tests)
-
test_router_exists— Test that router is defined -
test_module_imports— Test that module imports successfully
-
2 tests
-
TestPlansRoutes (2 tests)
-
test_router_exists— Test that router is defined -
test_module_imports— Test that module imports successfully
-
2 tests
-
TestRankingRoutes (2 tests)
-
test_router_exists— Test that router is defined -
test_module_imports— Test that module imports successfully
-
23 tests
-
TestReferralStats (3 tests)
-
test_get_referral_stats_success— Successfully get referral stats -
test_get_referral_stats_requires_auth— Referral stats requires authentication -
test_get_referral_stats_invalid_api_key— Invalid API key returns 401
-
-
TestReferralValidation (3 tests)
-
test_validate_referral_code_success— Successfully validate a referral code -
test_validate_invalid_referral_code— Invalid referral code returns error -
test_validate_referral_requires_code— Validate referral requires code parameter
-
-
TestReferralCodeGeneration (2 tests)
-
test_referral_code_format— Referral code should follow format -
test_referral_code_uniqueness— Referral codes should be unique
-
-
TestSelfReferralPrevention (1 tests)
-
test_cannot_use_own_referral_code— User cannot use their own referral code
-
-
TestReferralRewards (3 tests)
-
test_referrer_reward_calculation— Calculate referrer reward correctly -
test_first_purchase_bonus— Additional bonus on first purchase -
test_total_referral_earnings— Calculate total referral earnings
-
-
TestReferralLimits (3 tests)
-
test_referral_code_usage_limit— Referral code should have usage limit -
test_referral_code_exhausted— Exhausted referral code should be invalid -
test_user_can_only_use_one_code— User can only use one referral code
-
-
TestReferralAnalytics (1 tests)
-
test_referral_list_includes_details— Referral stats should include referral details
-
-
TestReferralEdgeCases (4 tests)
-
test_referral_code_case_insensitive— Referral codes should be case insensitive -
test_referral_code_with_spaces— Referral code with spaces should be trimmed -
test_empty_referral_code— Empty referral code should be rejected -
test_very_long_referral_code— Very long referral code should be rejected
-
-
TestInviteLink (1 tests)
-
test_invite_link_format— Invite link should have correct format
-
-
TestReferralSecurity (2 tests)
-
test_referral_code_sql_injection— SQL injection in referral code should be prevented -
test_referral_code_xss_prevention— XSS in referral code should be prevented
-
4 tests
-
test_chat_completions_endpoint— Test the legacy /v1/chat/completions endpoint -
test_responses_endpoint— Test the new /v1/responses endpoint -
test_responses_with_json_format— Test /v1/responses with JSON response format -
test_streaming_responses— Test /v1/responses with streaming
2 tests
-
TestRootRoutes (2 tests)
-
test_router_exists— Test that router is defined -
test_module_imports— Test that module imports successfully
-
16 tests
-
test_create_share_link_success— Test successfully creating a share link -
test_create_share_link_unauthenticated— Test creating share link without authentication -
test_create_share_link_rate_limited— Test creating share link when rate limited -
test_create_share_link_session_not_found— Test creating share link for non-existent session -
test_create_share_link_with_expiry— Test creating share link with expiration date -
test_get_my_share_links_success— Test getting user's share links -
test_get_my_share_links_empty— Test getting share links when none exist -
test_get_my_share_links_unauthenticated— Test getting share links without authentication -
test_get_shared_chat_success— Test getting shared chat by token (public endpoint) -
test_get_shared_chat_not_found— Test getting non-existent shared chat -
test_get_shared_chat_expired— Test getting expired shared chat -
test_delete_share_link_success— Test deleting a share link -
test_delete_share_link_not_found— Test deleting non-existent share link -
test_delete_share_link_unauthenticated— Test deleting share link without authentication -
test_create_share_link_missing_session_id— Test creating share link without session_id -
test_create_share_link_invalid_expiry_format— Test creating share link with invalid expiry format
10 files, 113 tests
2 tests
-
TestAdminSchemas (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module exports
-
2 tests
-
TestApiKeysSchemas (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module exports
-
2 tests
-
TestCommonSchemas (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module exports
-
2 tests
-
TestCouponsSchemas (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module exports
-
29 tests
-
TestErrorContext (10 tests)
-
test_minimal_context— Test creating minimal context with no fields. -
test_model_not_found_context— Test context for model not found error. -
test_insufficient_credits_context— Test context for insufficient credits error. -
test_rate_limit_context— Test context for rate limit error. -
test_parameter_validation_context— Test context for parameter validation error. -
test_provider_error_context— Test context for provider error. -
test_credit_context— Test context for credit-related error. -
test_key_prefix_context— Test context for API key error. -
test_serialization— Test context serialization to dict. -
test_allowed_values_list— Test that allowed_values accepts list.
-
-
TestErrorDetail (8 tests)
-
test_minimal_error_detail— Test creating minimal valid error detail. -
test_full_error_detail— Test fully populated error detail. -
test_missing_required_fields_raises_error— Test that missing required fields raises ValidationError. -
test_suggestions_is_list— Test that suggestions must be a list. -
test_status_is_integer— Test that status must be an integer. -
test_invalid_status_type_raises_error— Test that non-numeric status type raises ValidationError. -
test_serialization_excludes_none— Test that None values can be excluded from serialization. -
test_context_nested_serialization— Test that nested context is properly serialized.
-
-
TestErrorResponse (11 tests)
-
test_minimal_error_response— Test creating minimal valid error response. -
test_full_error_response— Test fully populated error response. -
test_missing_error_field_raises_error— Test that missing error field raises ValidationError. -
test_serialization_structure— Test that serialization has correct structure. -
test_json_serialization— Test that error response can be serialized to JSON. -
test_nested_context_in_response— Test that nested context is properly included. -
test_example_model_not_found_response— Test example model not found error response. -
test_example_insufficient_credits_response— Test example insufficient credits error response. -
test_example_rate_limit_response— Test example rate limit error response. -
test_timestamp_validation— Test that timestamp format is validated. -
test_urls_are_strings— Test that URL fields accept strings.
-
2 tests
-
TestNotificationSchemas (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module exports
-
11 tests
-
test_credit_value_minimum_100_percent— Test that credit value must be at least 100% of payment amount. -
test_credit_value_less_than_payment_rejected— Test that credit value less than payment amount is rejected. -
test_credit_value_bonus_packages_allowed— Test that bonus packages (credit > payment) are allowed. -
test_credit_value_exceeds_3x_rejected— Test that credit value exceeding 3x payment is rejected. -
test_credit_value_exactly_3x_allowed— Test that credit value exactly 3x payment is allowed. -
test_credit_value_none_allowed— Test that None credit_value is allowed (uses payment amount as credit). -
test_various_payment_amounts_with_valid_credits— Test various payment amounts with valid credit values. -
test_edge_case_just_below_minimum— Test edge case just below 100% credit value. -
test_edge_case_just_above_maximum— Test edge case just above 3x credit value. -
test_fractional_credit_values— Test that fractional credit values are handled correctly. -
test_promotional_packages_realistic_scenarios— Test realistic promotional package scenarios.
59 tests
-
TestMessageSchema (15 tests)
-
test_basic_message— Test basic message creation -
test_message_with_tool_calls— Test assistant message with tool_calls -
test_tool_response_message— Test tool response message -
test_function_message— Test function message with name -
test_multimodal_content— Test message with multimodal content array -
test_valid_roles— Test all valid message roles -
test_invalid_role— Test invalid message role raises error -
test_user_message_requires_content— Test that user messages must have content -
test_system_message_requires_content— Test that system messages must have content -
test_developer_message_requires_content— Test that developer messages must have content -
test_developer_message_basic— Test basic developer message creation (OpenAI developer role) -
test_tool_message_requires_content— Test that tool messages must have content (the response) -
test_function_message_requires_content— Test that function messages must have content -
test_assistant_message_allows_null_content_with_tool_calls— Test that assistant messages can have null content when tool_calls is present -
test_assistant_message_requires_content_or_tool_calls— Test that assistant messages need either content or tool_calls
-
-
TestProxyRequestOpenAIAlignment (25 tests)
-
test_minimal_request— Test minimal valid request -
test_all_sampling_parameters— Test all sampling parameters -
test_penalty_parameters— Test frequency and presence penalty parameters -
test_penalty_bounds— Test penalty parameter bounds (-2.0 to 2.0) -
test_temperature_bounds— Test temperature parameter bounds (0 to 2) -
test_streaming_parameters— Test streaming parameters -
test_tool_choice_string— Test tool_choice with string value -
test_tool_choice_object— Test tool_choice with object value (specific function) -
test_parallel_tool_calls— Test parallel_tool_calls parameter -
test_response_format_json_object— Test response_format with json_object type -
test_response_format_json_schema— Test response_format with json_schema type -
test_logprobs_parameters— Test logprobs and top_logprobs parameters -
test_top_logprobs_bounds— Test top_logprobs bounds (0 to 20) -
test_logit_bias— Test logit_bias parameter -
test_seed_parameter— Test seed parameter for deterministic sampling -
test_user_parameter— Test user parameter for end-user identification -
test_service_tier_parameter— Test service_tier parameter -
test_stop_string— Test stop parameter with single string -
test_stop_list— Test stop parameter with list of strings -
test_stop_max_sequences— Test stop parameter enforces max 4 sequences -
test_gateway_provider_parameter— Test gateway-specific provider parameter -
test_extra_fields_allowed— Test that extra fields are allowed for forward compatibility -
test_empty_messages_rejected— Test that empty messages list is rejected -
test_n_minimum_value— Test n parameter minimum value (1) -
test_complete_request— Test complete request with all parameters
-
-
TestStreamOptionsSchema (2 tests)
-
test_stream_options_include_usage— Test StreamOptions with include_usage -
test_stream_options_default— Test StreamOptions with default values
-
-
TestProxyRequestTools (4 tests)
-
test_proxy_request_without_tools— Test ProxyRequest without tools field -
test_proxy_request_with_tools— Test ProxyRequest with tools field -
test_proxy_request_with_empty_tools_list— Test ProxyRequest with empty tools list -
test_proxy_request_tools_extra_fields— Test ProxyRequest accepts tools via extra fields (backward compatibility)
-
-
TestResponseRequestTools (3 tests)
-
test_response_request_without_tools— Test ResponseRequest without tools field -
test_response_request_with_tools— Test ResponseRequest with tools field -
test_response_request_with_multiple_tools— Test ResponseRequest with multiple tools
-
-
TestMessageContentValidation (10 tests)
-
test_user_message_rejects_empty_string— Test that user messages reject empty string content -
test_user_message_rejects_whitespace_only— Test that user messages reject whitespace-only content -
test_system_message_rejects_empty_string— Test that system messages reject empty string content -
test_developer_message_rejects_empty_string— Test that developer messages reject empty string content -
test_developer_message_rejects_whitespace_only— Test that developer messages reject whitespace-only content -
test_tool_message_rejects_empty_string— Test that tool messages reject empty string content -
test_assistant_message_rejects_empty_without_tool_calls— Test that assistant messages reject empty content without tool_calls -
test_assistant_message_allows_null_with_tool_calls— Test that assistant messages allow null content with tool_calls -
test_user_message_allows_non_empty_string— Test that user messages accept valid non-empty content -
test_multimodal_content_empty_list_rejected— Test that empty list content is rejected for user messages
-
2 tests
-
TestTrialsSchemas (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module exports
-
2 tests
-
TestUsersSchemas (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module exports
-
6 files, 113 tests
3 tests
-
test_model_sync_router_has_auth_dependency— CRITICAL: model_sync.py must have require_admin at router level. -
test_no_admin_route_without_auth— Scan all route files for /admin paths and verify they have auth. -
test_bandit_false_positives_suppressed— Verify nosec comments are present on known false positives.
1 tests
-
test_admin_endpoints— Test that all admin endpoints require proper authentication
31 tests
-
TestCreateSecureAPIKey (6 tests)
-
test_create_secure_api_key_success— Test successful secure API key creation -
test_create_secure_api_key_with_expiration— Test API key creation with expiration -
test_create_secure_api_key_with_ip_allowlist— Test API key creation with IP allowlist -
test_create_secure_api_key_duplicate_name— Test API key creation with duplicate name fails -
test_create_secure_api_key_insert_fails— Test API key creation when insert fails -
test_create_secure_api_key_with_custom_permissions— Test API key creation with custom scope permissions
-
-
TestValidateSecureAPIKey (8 tests)
-
test_validate_secure_api_key_success— Test successful API key validation -
test_validate_secure_api_key_not_found— Test validation with non-existent key -
test_validate_secure_api_key_inactive— Test validation with inactive key -
test_validate_secure_api_key_expired— Test validation with expired key -
test_validate_secure_api_key_ip_not_allowed— Test validation with disallowed IP -
test_validate_secure_api_key_domain_not_allowed— Test validation with disallowed domain -
test_validate_secure_api_key_request_limit_exceeded— Test validation when request limit is exceeded -
test_validate_plain_text_key— Test validation of plain text (legacy) key
-
-
TestRotateAPIKey (3 tests)
-
test_rotate_api_key_success— Test successful API key rotation -
test_rotate_api_key_not_found— Test rotation with non-existent key -
test_rotate_api_key_with_new_name— Test API key rotation with new name
-
-
TestGetAuditLogs (6 tests)
-
test_get_audit_logs_all— Test getting all audit logs -
test_get_audit_logs_by_user— Test getting audit logs filtered by user -
test_get_audit_logs_by_action— Test getting audit logs filtered by action -
test_get_audit_logs_with_date_range— Test getting audit logs within date range -
test_get_audit_logs_empty— Test getting audit logs when none exist -
test_get_audit_logs_error_handling— Test audit logs error handling
-
-
TestBulkRotateUserKeys (4 tests)
-
test_bulk_rotate_user_keys_success— Test successful bulk rotation -
test_bulk_rotate_user_keys_no_keys— Test bulk rotation when user has no keys -
test_bulk_rotate_user_keys_with_environment— Test bulk rotation filtered by environment -
test_bulk_rotate_user_keys_partial_failure— Test bulk rotation when some keys fail
-
-
TestCheckKeyNameUniqueness (4 tests)
-
test_check_key_name_uniqueness_unique— Test that unique name returns True -
test_check_key_name_uniqueness_duplicate— Test that duplicate name returns False -
test_check_key_name_uniqueness_with_exclusion— Test uniqueness check excluding a specific key -
test_check_key_name_uniqueness_error_handling— Test that errors return False (safe default)
-
29 tests
test_get_api_key_missing_credentialstest_get_api_key_missing_tokentest_get_api_key_valid_logs_usagetest_get_api_key_valueerror_mappedtest_get_api_key_unexpected-
test_get_api_key_no_violation_log_when_disabled— Verify that log_security_violations=False prevents security violation logging. -
test_get_api_key_logs_violation_by_default— Verify that log_security_violations=True (default) logs security violations. test_get_current_user_happytest_get_current_user_404test_require_admin_via_flagtest_require_admin_via_roletest_require_admin_denied_logs_violationtest_get_optional_api_key_no_credentials_returns_nonetest_get_optional_api_key_invalid_returns_nonetest_get_optional_api_key_valid_returns_key-
test_get_optional_api_key_does_not_log_violations— Verify that get_optional_api_key does NOT log security violations. test_get_optional_user_no_credentials_returns_nonetest_get_optional_user_invalid_returns_nonetest_get_optional_user_valid_returns_user-
test_get_optional_user_does_not_log_violations— Verify that get_optional_user does NOT log security violations. test_require_active_subscription_oktest_require_active_subscription_forbiddentest_check_credits_oktest_check_credits_402test_get_user_idtest_verify_key_permissions_none_required_returns_keytest_verify_key_permissions_oktest_verify_key_permissions_user_missingtest_verify_key_permissions_forbidden
28 tests
-
TestSQLInjectionPrevention (5 tests)
-
test_sql_injection_in_username— SQL injection attempt in username parameter -
test_sql_injection_in_email— SQL injection attempt in email parameter -
test_sql_injection_in_search— SQL injection attempt in search parameters -
test_sql_injection_union_attack— SQL injection UNION attack attempt -
test_sql_injection_in_api_key_lookup— SQL injection in API key lookup
-
-
TestXSSPrevention (4 tests)
-
test_xss_in_username— XSS attempt in username -
test_xss_in_chat_message— XSS attempt in chat message -
test_xss_in_json_response— Verify JSON responses don't contain unescaped HTML -
test_xss_svg_attack— XSS via SVG payload
-
-
TestCommandInjection (3 tests)
-
test_command_injection_in_model_name— Command injection via model name -
test_command_injection_backticks— Command injection using backticks -
test_command_injection_pipe— Command injection using pipe operator
-
-
TestPathTraversal (3 tests)
-
test_path_traversal_in_filename— Path traversal attempt in filename parameter -
test_path_traversal_encoded— Path traversal with URL encoding -
test_path_traversal_windows_style— Path traversal with Windows path separators
-
-
TestLDAPInjection (2 tests)
-
test_ldap_injection_in_username— LDAP injection attempt -
test_ldap_wildcard_injection— LDAP wildcard injection
-
-
TestHeaderInjection (1 tests)
-
test_crlf_injection_in_header— CRLF injection attempt in custom header
-
-
TestJSONInjection (2 tests)
-
test_json_injection_nested_objects— Attempt to inject malicious JSON structures -
test_json_with_null_bytes— JSON with null bytes
-
-
TestInputValidation (3 tests)
-
test_oversized_input— Reject or handle oversized inputs -
test_special_unicode_characters— Handle special Unicode characters safely -
test_null_character_injection— Null character injection attempt
-
-
TestAPIKeyValidation (2 tests)
-
test_api_key_format_validation— Validate API key format -
test_api_key_length_validation— API key length should be validated
-
-
TestErrorMessagesSecurity (3 tests)
-
test_database_errors_not_exposed— Database errors should not expose internal details -
test_stack_traces_not_exposed— Stack traces should not be exposed to clients -
test_file_paths_not_exposed— File paths should not be exposed in errors
-
21 tests
-
TestAPIKeyHashing (2 tests)
-
test_hash_api_key_requires_salt— Hashing should require API_GATEWAY_SALT -
test_hash_api_key_rejects_short_salt— Hashing should reject salt shorter than 16 characters
-
-
TestAPIKeyGeneration (7 tests)
-
test_generate_api_key_success— Successfully generate an API key -
test_generate_api_key_unique— Generated API keys should be unique -
test_generate_api_key_test_environment— Generate test environment API key -
test_generate_api_key_staging_environment— Generate staging environment API key -
test_generate_api_key_development_environment— Generate development environment API key -
test_generate_api_key_custom_length— Generate API key with custom length -
test_generate_api_key_format— API key should follow expected format
-
-
TestIPAllowlist (1 tests)
-
test_validate_ip_mixed_formats— Validate IP with mixed exact and CIDR formats
-
-
TestSecurityConstants (2 tests)
-
test_api_key_prefix— API keys should use gw_ prefix -
test_salt_minimum_length— Salt should meet minimum length requirements
-
-
TestSecurityEdgeCases (3 tests)
-
test_hash_empty_string— Hash empty string should work or raise appropriate error -
test_validate_ip_invalid_ip— Validate with invalid IP format -
test_validate_domain_invalid_url— Validate with invalid URL format
-
-
TestAuditLoggerFormat (6 tests)
-
test_audit_logger_exists— AuditLogger should be available via get_audit_logger() -
test_audit_logger_has_handlers— AuditLogger should have configured handlers -
test_audit_logger_format_has_level_before_audit— Log format should have levelname before [AUDIT] for Railway compatibility -
test_audit_logger_log_methods_exist— AuditLogger should have all required logging methods -
test_audit_logger_uses_info_level_for_normal_events— Normal events should use INFO level -
test_audit_logger_uses_warning_level_for_security_violations— Security violations should use WARNING level
-
55 files, 1169 tests
4 tests
-
TestTrialAnalytics (4 tests)
-
test_get_trial_analytics_returns_dict— Test that get_trial_analytics returns a dictionary -
test_get_trial_analytics_has_required_keys— Test that result has all required keys -
test_get_trial_analytics_default_values— Test that default values are zero (TODO implementation) -
test_get_trial_analytics_value_types— Test that values have correct types
-
23 tests
-
TestAuthRateLimitConfig (2 tests)
-
test_default_config_values— Test default configuration values -
test_custom_config— Test custom configuration values
-
-
TestAuthRateLimiter (13 tests)
-
test_login_rate_limit_allows_under_limit— Test that requests under limit are allowed -
test_login_rate_limit_blocks_over_limit— Test that requests over limit are blocked -
test_register_rate_limit— Test registration rate limiting -
test_password_reset_rate_limit— Test password reset rate limiting -
test_api_key_create_rate_limit— Test API key creation rate limiting -
test_different_ips_have_separate_limits— Test that different IPs are rate limited independently -
test_different_limit_types_are_independent— Test that different rate limit types are tracked independently -
test_get_remaining— Test getting remaining attempts -
test_reset_clears_limit— Test that reset clears the rate limit -
test_mask_identifier_ipv4— Test IP address masking for IPv4 -
test_mask_identifier_short_string— Test identifier masking for short strings -
test_mask_identifier_long_string— Test identifier masking for long strings -
test_mask_identifier_empty— Test identifier masking for empty/None values
-
-
TestGetClientIP (6 tests)
-
test_get_ip_from_x_real_ip— Test extracting IP from X-Real-IP header (highest priority) -
test_get_ip_from_x_forwarded_for_rightmost— Test extracting rightmost IP from X-Forwarded-For header (proxy-added) -
test_get_ip_from_x_forwarded_for_single— Test extracting IP from X-Forwarded-For header with single IP -
test_get_ip_from_client_host— Test extracting IP from client.host when no X-Forwarded-For -
test_get_ip_unknown_when_no_client— Test returning 'unknown' when no client info available -
test_spoofed_x_forwarded_for_uses_proxy_added_ip— Test that spoofed X-Forwarded-For headers don't bypass rate limiting
-
-
TestGlobalRateLimiter (2 tests)
-
test_get_auth_rate_limiter_returns_singleton— Test that get_auth_rate_limiter returns the same instance -
test_check_auth_rate_limit_convenience_function— Test the convenience function for checking rate limits
-
26 tests
-
TestModelHealthMonitorFixes (3 tests)
-
test_latency_parsing_with_invalid_format— Test that invalid latency formats are handled gracefully without bare except. -
test_latency_parsing_with_none_value— Test that None latency values are handled without crashing. -
test_latency_parsing_with_valid_value— Test that valid latency values are parsed correctly.
-
-
TestAuthorizationHeaderParsingFixes (5 tests)
-
test_malformed_authorization_header_without_token— Test that authorization header with just 'Bearer' doesn't crash. -
test_malformed_authorization_header_empty_token— Test that authorization header with empty token is handled. -
test_valid_authorization_header— Test that valid authorization header is parsed correctly. -
test_authorization_header_with_extra_spaces— Test that authorization header with extra spaces is handled. -
test_unified_responses_auth_header_parsing— Test that unified_responses endpoint (chat.py:2780) handles malformed headers.
-
-
TestXForwardedForParsingFixes (7 tests)
-
test_empty_forwarded_for_header— Test that empty X-Forwarded-For header doesn't crash. -
test_single_ip_forwarded_for— Test that single IP in X-Forwarded-For is parsed correctly. -
test_multiple_ips_forwarded_for— Test that first IP from multiple IPs is extracted. -
test_forwarded_for_with_spaces— Test that X-Forwarded-For with extra spaces is handled. -
test_malformed_forwarded_for_ipv6— Test that IPv6 addresses in X-Forwarded-For are handled. -
test_middleware_forwarded_for_parsing— Test that middleware X-Forwarded-For parsing is defensive. -
test_middleware_empty_forwarded_for— Test middleware handles empty X-Forwarded-For gracefully.
-
-
TestUnsafeListAccessFixes (7 tests)
-
test_empty_choices_list_finish_reason— Test that empty choices list doesn't crash when accessing finish_reason. -
test_none_choices_finish_reason— Test that None choices value doesn't crash. -
test_valid_choices_finish_reason— Test that valid choices list works correctly. -
test_empty_choices_list_assistant_content— Test that empty choices list doesn't crash when extracting assistant content. -
test_none_choices_assistant_content— Test that None choices doesn't crash. -
test_valid_choices_assistant_content— Test that valid choices extracts content correctly. -
test_choices_with_empty_message— Test that choices with empty message dict doesn't crash.
-
-
TestSilentExceptionSwallowingFixes (2 tests)
-
test_url_parsing_exception_is_logged— Test that URL parsing exceptions are now logged instead of silently ignored. -
test_valid_url_parsing— Test that valid URLs are parsed correctly.
-
-
TestEndToEndErrorHandling (2 tests)
-
test_messages_endpoint_resilience— Test that messages endpoint handles edge cases without crashing. -
test_chat_endpoint_resilience— Test that chat endpoint handles edge cases without crashing.
-
11 tests
-
TestBackgroundTasks (11 tests)
-
test_log_activity_async_success— log_activity_async should execute database logging -
test_log_activity_async_error_handling— log_activity_async should handle errors gracefully -
test_log_activity_background_no_event_loop— log_activity_background should work without event loop -
test_log_activity_background_with_event_loop— log_activity_background should create task when event loop exists -
test_log_activity_background_error_handling— log_activity_background should handle errors gracefully -
test_get_pending_tasks_count— get_pending_tasks_count should return count of pending tasks -
test_log_activity_background_with_all_parameters— log_activity_background should handle all parameters -
test_log_activity_async_with_all_parameters— log_activity_async should handle all parameters -
test_log_activity_background_with_minimal_parameters— log_activity_background should work with minimal parameters -
test_log_activity_async_with_none_metadata— log_activity_async should handle None metadata -
test_log_activity_background_multiple_calls— log_activity_background should handle multiple calls
-
17 tests
-
TestBraintrustService (11 tests)
-
test_initialize_without_api_key— Test initialization fails gracefully without API key. -
test_initialize_with_invalid_api_key— Test initialization warns with invalid API key format. -
test_is_available_before_init— Test is_available returns False before initialization. -
test_create_span_returns_noop_when_unavailable— Test create_span returns NoopSpan when Braintrust is unavailable. -
test_noop_span_log_method— Test NoopSpan.log() doesn't raise exceptions. -
test_noop_span_end_method— Test NoopSpan.end() doesn't raise exceptions. -
test_noop_span_context_manager— Test NoopSpan works as a context manager. -
test_noop_span_set_attributes— Test NoopSpan.set_attributes() doesn't raise exceptions. -
test_flush_when_not_initialized— Test flush() doesn't raise when not initialized. -
test_get_logger_when_not_initialized— Test get_logger() returns None when not initialized. -
test_check_braintrust_available_alias— Test check_braintrust_available is alias for is_available.
-
-
TestBraintrustServiceWithMocking (4 tests)
-
test_initialize_calls_init_logger_with_correct_params— Test that initialize calls init_logger with correct parameters. -
test_create_span_uses_logger_start_span— Test that create_span uses logger.start_span() for proper project association. -
test_flush_calls_logger_flush— Test that flush() calls logger.flush(). -
test_create_span_returns_noop_on_exception— Test that create_span returns NoopSpan if an exception occurs.
-
-
TestBraintrustRealIntegration (2 tests)
-
test_real_initialization— Test real Braintrust initialization. -
test_real_span_creation_and_logging— Test real span creation and logging.
-
32 tests
-
TestBugFixGeneratorInitialization (5 tests)
-
test_init_without_api_key— Test that initialization fails without ANTHROPIC_API_KEY. -
test_init_with_api_key— Test successful initialization with API key. -
test_init_with_invalid_key_format— Test warning when API key doesn't start with sk-ant-. -
test_init_with_github_token— Test initialization with GitHub token. -
test_init_with_custom_model— Test initialization with custom ANTHROPIC_MODEL.
-
-
TestAPIKeyValidation (4 tests)
-
test_validate_api_key_success— Test successful API key validation. -
test_validate_api_key_401_unauthorized— Test validation fails with 401 Unauthorized. -
test_validate_api_key_400_bad_request— Test validation fails with 400 Bad Request. -
test_validate_api_key_timeout— Test validation handles timeout gracefully.
-
-
TestPromptSanitization (7 tests)
-
test_sanitize_text_short_text— Test sanitizing normal-length text. -
test_sanitize_text_long_text— Test sanitizing text exceeding max length. -
test_sanitize_text_with_null_bytes— Test removing null bytes from text. -
test_sanitize_text_empty— Test sanitizing empty text. -
test_sanitize_text_none— Test sanitizing None. -
test_prepare_prompt_normal_length— Test preparing normal-length prompt. -
test_prepare_prompt_exceeds_max— Test preparing prompt that exceeds max length.
-
-
TestErrorAnalysis (4 tests)
-
test_analyze_error_success— Test successful error analysis. -
test_analyze_error_no_content— Test error analysis with no content in response. -
test_analyze_error_400_bad_request— Test error analysis with 400 error. -
test_analyze_error_sanitizes_long_messages— Test that error analysis sanitizes long error messages.
-
-
TestFixGeneration (4 tests)
-
test_generate_fix_success— Test successful fix generation. -
test_generate_fix_analysis_fails— Test fix generation skips when analysis fails. -
test_generate_fix_invalid_json— Test fix generation handles invalid JSON response. -
test_generate_fix_no_changes— Test fix generation with empty changes array.
-
-
TestRetryLogic (3 tests)
-
test_retry_on_timeout— Test that requests are retried on timeout. -
test_retry_max_attempts— Test that retry stops after max attempts. -
test_no_retry_on_400— Test that 400 errors are not retried.
-
-
TestRequestLogging (2 tests)
-
test_request_logging_success— Test that successful requests are logged. -
test_request_logging_error— Test that errors are logged with details.
-
-
TestBugFixDataClass (1 tests)
-
test_bug_fix_to_dict— Test BugFix.to_dict() serialization.
-
-
TestEdgeCases (2 tests)
-
test_close_generator— Test closing the generator properly. -
test_multiple_fixes_tracking— Test that generated fixes are tracked.
-
17 tests
-
TestCanopywaveClient (17 tests)
-
test_get_canopywave_client_raises_without_api_key— Test that get_canopywave_client raises ValueError when API key is not configured -
test_get_canopywave_client_returns_pooled_client— Test that get_canopywave_client returns a pooled client when API key is configured -
test_fetch_models_from_canopywave_success— Test successful model fetching from Canopy Wave API -
test_fetch_models_from_canopywave_handles_embedding_models— Test that embedding models are properly handled -
test_fetch_models_from_canopywave_http_error— Test that HTTP errors are handled gracefully -
test_fetch_models_from_canopywave_network_error— Test that network errors are handled gracefully -
test_fetch_models_from_canopywave_skips_models_without_id— Test that models without an ID are skipped -
test_fetch_models_from_canopywave_handles_missing_pricing— Test that missing pricing information is handled with defaults -
test_fetch_models_from_canopywave_handles_context_in_capabilities— Test that context_length in capabilities is properly extracted -
test_make_canopywave_request_openai— Test making a request to Canopy Wave using OpenAI client -
test_make_canopywave_request_openai_stream— Test making a streaming request to Canopy Wave -
test_process_canopywave_response— Test processing a Canopy Wave response -
test_is_canopywave_model_returns_true_for_valid_model— Test that is_canopywave_model returns True for a valid model -
test_is_canopywave_model_returns_false_for_invalid_model— Test that is_canopywave_model returns False for an invalid model -
test_is_canopywave_model_handles_errors— Test that is_canopywave_model handles errors gracefully -
test_fetch_models_handles_function_calling_capability— Test that function_calling capability is mapped to tools feature -
test_fetch_models_handles_web_search_capability— Test that web_search capability is properly extracted
-
12 tests
-
TestCircuitBreakerHalfOpenBehavior (2 tests)
-
test_half_open_allows_multiple_failures_before_reopening— Test that HALF_OPEN state allows 2 failures before reopening -
test_half_open_closes_after_success— Test that HALF_OPEN transitions to CLOSED after success_threshold successes
-
-
TestConsecutiveOpensTracking (2 tests)
-
test_consecutive_opens_increments_on_failed_recovery— Test that consecutive_opens increments when recovery fails (circuit reopens from HALF_OPEN) -
test_consecutive_opens_resets_on_successful_recovery— Test that consecutive_opens resets to 0 after successful recovery
-
-
TestCircuitBreakerErrorHandling (2 tests)
-
test_circuit_breaker_error_raised_when_open— Test that CircuitBreakerError is raised when circuit is OPEN -
test_circuit_breaker_error_contains_retry_info— Test that CircuitBreakerError message contains retry information
-
-
TestDetailedErrorFactory (2 tests)
-
test_provider_unavailable_creates_503_error— Test that provider_unavailable returns 503 status -
test_provider_unavailable_contains_helpful_info— Test that error contains helpful information for users
-
-
TestOpenRouterCircuitConfig (1 tests)
-
test_openrouter_config_has_optimized_values— Test that OPENROUTER_CIRCUIT_CONFIG has the optimized parameters
-
-
TestRedisStatePersistence (2 tests)
-
test_consecutive_opens_persisted_to_redis— Test that consecutive_opens is saved to Redis -
test_consecutive_opens_loaded_from_redis— Test that consecutive_opens is loaded from Redis
-
-
TestCircuitBreakerIntegration (1 tests)
-
test_chat_handler_catches_circuit_breaker_error— Test that chat handler catches CircuitBreakerError and returns 503
-
26 tests
-
TestCodeTaskClassifier (18 tests)
-
test_classify_simple_code— Test classification of simple code tasks. -
test_classify_code_explanation— Test classification of code explanation tasks. -
test_classify_code_generation— Test classification of code generation tasks. -
test_classify_debugging— Test classification of debugging tasks. -
test_classify_refactoring— Test classification of refactoring tasks. -
test_classify_architecture— Test classification of architecture tasks. -
test_classify_agentic— Test classification of agentic coding tasks. -
test_high_confidence_classification— Test that clear prompts get high confidence. -
test_low_confidence_classification— Test that ambiguous prompts get lower confidence. -
test_default_category_for_ambiguous— Test that ambiguous prompts default to code_generation. -
test_classification_time_under_threshold— Test that classification completes within target time. -
test_context_multi_file— Test that multi-file context boosts architecture/agentic scores. -
test_context_error_trace— Test that error trace context boosts debugging score. -
test_context_long_conversation— Test that long conversation context boosts refactoring/architecture. -
test_is_code_related_positive— Test that code-related prompts are detected. -
test_is_code_related_negative— Test that non-code prompts are not detected as code-related. -
test_extract_context_from_messages— Test context extraction from conversation messages. -
test_extract_context_multi_part_messages— Test context extraction with multi-part messages.
-
-
TestModuleFunctions (3 tests)
-
test_get_classifier_singleton— Test that get_classifier returns the same instance. -
test_classify_code_task_function— Test the convenience classify_code_task function. -
test_is_code_related_function— Test the convenience is_code_related function.
-
-
TestEdgeCases (5 tests)
-
test_empty_prompt— Test classification of empty prompt. -
test_very_long_prompt— Test classification of very long prompt. -
test_unicode_prompt— Test classification with unicode characters. -
test_none_context— Test classification with None context. -
test_empty_context— Test classification with empty context.
-
39 tests
-
TestParseRouterModelString (8 tests)
-
test_parse_router_code_auto— Test parsing 'router:code' as auto mode. -
test_parse_router_code_price— Test parsing 'router:code:price' mode. -
test_parse_router_code_quality— Test parsing 'router:code:quality' mode. -
test_parse_router_code_agentic— Test parsing 'router:code:agentic' mode. -
test_parse_non_router_model— Test parsing regular model strings. -
test_parse_router_auto— Test parsing general 'router:' prefix (not code router). -
test_parse_case_insensitive— Test that parsing is case-insensitive. -
test_parse_unknown_mode— Test parsing unknown mode falls back to auto.
-
-
TestCodeRouter (16 tests)
-
test_route_simple_task— Test routing a simple code task. -
test_route_debugging_task— Test routing a debugging task. -
test_route_architecture_task— Test routing an architecture task. -
test_route_agentic_task— Test routing an agentic task. -
test_route_price_mode— Test routing in price optimization mode. -
test_route_quality_mode— Test routing in quality optimization mode. -
test_route_agentic_mode— Test routing in agentic mode. -
test_route_auto_mode— Test routing in auto mode (default). -
test_quality_gate_debugging— Test that debugging tasks respect quality gate. -
test_quality_gate_architecture— Test that architecture tasks respect quality gate. -
test_quality_gate_agentic_task— Test that agentic tasks respect quality gate. -
test_routing_result_structure— Test that routing result has expected structure. -
test_routing_latency— Test that routing completes within target time. -
test_savings_estimate_structure— Test savings estimate structure. -
test_route_with_context— Test routing with context. -
test_route_with_user_default_model— Test routing with user's default model for comparison.
-
-
TestModuleFunctions (6 tests)
-
test_get_router_singleton— Test that get_router returns the same instance. -
test_route_code_prompt_function— Test the convenience route_code_prompt function. -
test_get_routing_metadata— Test get_routing_metadata formats correctly. -
test_get_model_tiers— Test get_model_tiers returns valid data. -
test_get_fallback_model— Test get_fallback_model returns valid model. -
test_get_baselines— Test get_baselines returns baseline configs.
-
-
TestEdgeCases (5 tests)
-
test_empty_prompt— Test routing with empty prompt. -
test_very_long_prompt— Test routing with very long prompt. -
test_unicode_prompt— Test routing with unicode characters. -
test_none_context— Test routing with None context. -
test_invalid_mode_defaults_to_auto— Test that invalid mode is handled gracefully.
-
-
TestTierSelection (4 tests)
-
test_tier_1_for_architecture— Test that architecture always gets tier 1. -
test_tier_1_for_agentic_mode— Test that agentic mode always selects tier 1. -
test_tier_respected_in_price_mode— Test that quality gates are respected even in price mode. -
test_quality_mode_bumps_tier— Test that quality mode bumps up the tier.
-
6 tests
-
TestConnectionPool (6 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module exports -
test_reuses_client_when_api_key_unchanged— The same provider/base/api_key triple should reuse the cached client. -
test_rebuilds_client_when_api_key_changes— Rotating API keys should evict the old client and close it. -
test_get_groq_pooled_client— Test that Groq pooled client is configured correctly. -
test_get_groq_pooled_client_no_key— Test that Groq pooled client raises error without API key.
-
21 tests
-
TestRecordCreditMetrics (2 tests)
-
test_records_success_metrics— Test that success metrics are recorded correctly. -
test_records_retry_metrics— Test that retry metrics are recorded for attempt > 1.
-
-
TestRecordMissedDeduction (2 tests)
-
test_records_missed_deduction— Test that missed deduction is recorded. -
test_skips_zero_cost— Test that zero cost doesn't record metric.
-
-
TestRecordBackgroundTaskFailure (1 tests)
-
test_records_failure— Test that background task failure is recorded.
-
-
TestSendCriticalBillingAlert (2 tests)
-
test_sends_alert_for_significant_cost— Test that Sentry alert is sent for costs >= $0.01. -
test_skips_message_for_small_cost— Test that Sentry breadcrumb and alert are sent for all costs.
-
-
TestHandleCreditsAndUsage (8 tests)
-
test_trial_user_no_deduction— Test that trial users don't get credits deducted. -
test_paid_user_deduction_success— Test that paid users get credits deducted successfully. -
test_retry_on_transient_failure— Test that credit deduction retries on transient failure. -
test_no_retry_on_validation_error— Test that ValueError (insufficient credits) doesn't retry. -
test_all_retries_exhausted— Test behavior when all retries are exhausted. -
test_trial_override_for_paid_user_with_stale_flag— Test that paid users with stale is_trial flag still get charged. -
test_no_duplicate_deduction_when_usage_logging_fails— Test that deduct_credits is only called once even if record_usage fails. -
test_no_duplicate_deduction_when_rate_limit_update_fails— Test that deduct_credits is only called once even if rate limit update fails.
-
-
TestHandleCreditsAndUsageWithFallback (3 tests)
-
test_returns_success_on_normal_operation— Test successful operation returns (cost, True). -
test_returns_failure_and_logs_on_error— Test that failures return (cost, False) and log for reconciliation. -
test_uses_fallback_cost_if_pricing_fails— Test that fallback cost estimation is used if pricing lookup fails.
-
-
TestRetryConfiguration (3 tests)
-
test_max_retries_is_reasonable— Test that max retries is between 1 and 5. -
test_retry_delays_are_exponential— Test that retry delays increase. -
test_retry_delays_match_max_retries— Test that we have enough delay values for all retries.
-
9 tests
-
TestDeepInfraNormalization (9 tests)
-
test_normalize_text_to_image_model— Test normalizing an image generation model -
test_normalize_text_generation_model— Test normalizing a text generation model -
test_normalize_model_without_type— Test normalizing a model without explicit type (defaults to text->text) -
test_normalize_model_with_id_field— Test normalizing a model that uses 'id' instead of 'model_name' -
test_normalize_model_without_pricing— Test normalizing a model without pricing information -
test_normalize_deprecated_model_without_replacement— Test normalizing a deprecated model without a replacement -
test_normalize_model_with_multimodal_type— Test normalizing a multimodal model -
test_normalize_tts_model— Test normalizing a text-to-speech model -
test_normalize_stt_model— Test normalizing a speech-to-text model
-
30 tests
-
TestEmailVerificationResult (8 tests)
-
test_disposable_email_is_bot— Disposable emails should be marked as bot. -
test_risky_low_score_is_bot— Risky emails with low score should be marked as bot. -
test_risky_high_score_not_bot— Risky emails with high score should not be marked as bot. -
test_deliverable_email_not_bot— Deliverable emails should not be marked as bot. -
test_unknown_email_not_bot— Unknown emails should not be marked as bot (benefit of doubt). -
test_undeliverable_should_block— Undeliverable emails should be blocked. -
test_invalid_domain_should_block— Invalid domain emails should be blocked. -
test_deliverable_should_not_block— Deliverable emails should not be blocked.
-
-
TestEmailVerificationService (9 tests)
-
test_service_disabled_by_default— Service should be disabled by default. -
test_service_enabled_with_api_key— Service should be enabled when API key and enabled flag are set. -
test_service_disabled_without_api_key— Service should be disabled if enabled but no API key. -
test_verify_returns_unknown_when_disabled— When disabled, verify should return unknown result. -
test_verify_parses_deliverable_response— Service should correctly parse deliverable response. -
test_verify_parses_disposable_response— Service should correctly identify disposable emails. -
test_verify_handles_rate_limit— Service should handle rate limit gracefully. -
test_verify_handles_insufficient_credits— Service should handle insufficient credits gracefully. -
test_verify_handles_timeout— Service should handle timeout gracefully.
-
-
TestEmailVerificationEdgeCases (5 tests)
-
test_empty_email— Service should handle empty email gracefully. -
test_email_without_at_symbol— Service should handle malformed email gracefully. -
test_email_case_normalization— Service should normalize email to lowercase. -
test_email_whitespace_trimming— Service should trim whitespace from email. -
test_did_you_mean_suggestion— Result should include did_you_mean suggestion if provided.
-
-
TestEmailVerificationCaching (8 tests)
-
test_result_to_cache_dict— Result should correctly convert to cache dict. -
test_result_from_cache_dict— Result should correctly restore from cache dict. -
test_cache_roundtrip— Result should survive roundtrip through cache dict. -
test_verify_caches_successful_result— Successful verification should be cached. -
test_verify_returns_cached_result— Verification should return cached result if available. -
test_verify_does_not_cache_api_errors— API errors should not be cached. -
test_verify_does_not_cache_timeouts— Timeouts should not be cached. -
test_verify_works_when_redis_unavailable— Verification should work when Redis is unavailable.
-
6 tests
-
TestLokiErrorLogging (6 tests)
-
test_loki_empty_error_not_logged— Test that empty Loki errors are suppressed and not logged at ERROR level. -
test_loki_none_error_not_logged— Test that 'None' string errors from Loki are suppressed. -
test_loki_real_error_still_logged— Test that real Loki errors are still logged at ERROR level. -
test_loki_successful_fetch— Test that successful Loki fetches work correctly. -
test_loki_disabled_no_error— Test that disabled Loki doesn't trigger errors. -
test_loki_whitespace_error_suppressed— Test that whitespace-only errors are suppressed.
-
20 tests
-
test_route_general_prompt_convenience_function— Test the convenience function route_general_prompt. -
TestNormalizeModelString (5 tests)
-
test_normalize_general_router_hyphenated— Test normalizing gatewayz-general aliases. -
test_normalize_code_router_hyphenated— Test normalizing gatewayz-code aliases. -
test_normalize_already_normalized— Test that already normalized strings pass through unchanged. -
test_normalize_regular_model— Test that regular model IDs pass through unchanged. -
test_normalize_case_insensitive— Test case insensitivity.
-
-
TestParseRouterModelString (8 tests)
-
test_parse_router_general_balanced— Test parsing router:general (balanced mode). -
test_parse_router_general_quality— Test parsing router:general:quality. -
test_parse_router_general_cost— Test parsing router:general:cost. -
test_parse_router_general_latency— Test parsing router:general:latency. -
test_parse_invalid_mode— Test parsing invalid mode falls back to balanced. -
test_parse_non_router_string— Test parsing non-router strings. -
test_parse_code_router_string— Test that code router strings are not matched. -
test_parse_case_insensitive— Test case insensitivity.
-
-
TestGeneralRouterRoute (4 tests)
-
test_route_with_notdiamond_enabled— Test routing when NotDiamond is enabled and working. -
test_route_with_notdiamond_disabled— Test routing when NotDiamond is disabled. -
test_route_with_unavailable_model— Test routing when NotDiamond recommends unavailable model. -
test_route_with_notdiamond_exception— Test routing when NotDiamond throws exception.
-
-
TestRoutingMetadata (2 tests)
-
test_get_routing_metadata_success— Test metadata formatting for successful routing. -
test_get_routing_metadata_fallback— Test metadata formatting for fallback routing.
-
2 tests
-
TestGoogleModelsConfig (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module exports
-
17 tests
-
test_base64url_encode_simple— Test base64url encoding of simple strings -
test_base64url_encode_json— Test base64url encoding of JSON -
test_base64url_encode_decode_roundtrip— Test that base64url encoding can be decoded back -
test_build_jwt_assertion_structure— Test JWT assertion has correct structure -
test_build_jwt_assertion_with_custom_subject— Test JWT assertion with custom subject claim -
test_build_jwt_assertion_expiry— Test JWT assertion expiry calculation -
test_build_jwt_assertion_invalid_key— Test JWT assertion building with invalid private key -
test_exchange_jwt_for_access_token_success— Test successful JWT exchange for access token -
test_exchange_jwt_for_access_token_401_error— Test JWT exchange with 401 unauthorized error -
test_exchange_jwt_for_access_token_500_error— Test JWT exchange with 500 server error -
test_exchange_jwt_for_access_token_network_error— Test JWT exchange with network error -
test_get_access_token_from_service_account_success— Test getting access token from service account JSON -
test_get_access_token_from_service_account_invalid_json— Test with invalid service account JSON -
test_get_access_token_from_service_account_missing_email— Test with service account JSON missing client_email -
test_get_access_token_from_service_account_missing_key— Test with service account JSON missing private_key -
test_get_access_token_from_service_account_custom_scope— Test with custom OAuth2 scope -
test_full_oauth2_jwt_flow_integration— Test the complete OAuth2 JWT flow end-to-end
7 tests
-
TestIdTokenFallback (7 tests)
-
test_exchange_jwt_returns_access_token_when_present— Test normal flow: access_token is present in response -
test_exchange_jwt_falls_back_to_id_token— Test fallback: id_token is used when access_token is missing -
test_exchange_jwt_prefers_access_token_over_id_token— Test that access_token is preferred when both are present -
test_exchange_jwt_raises_when_no_token_present— Test that error is raised when neither token is present -
test_exchange_jwt_handles_http_error— Test that HTTP errors are properly handled -
test_exchange_jwt_sends_correct_request— Test that the correct request is sent to Google's token endpoint -
test_id_token_with_real_google_response_structure— Test with a realistic Google OAuth2 response containing id_token
-
6 tests
-
TestGoogleVertexMultiEndpoint (6 tests)
-
test_first_endpoint_success— Test successful fetch from first endpoint (regional with project) -
test_fallback_to_second_endpoint— Test fallback to second endpoint when first fails with 404 -
test_fallback_to_global_endpoint— Test fallback to global endpoint when regional endpoints fail -
test_all_endpoints_fail_returns_none— Test that None is returned when all endpoints fail -
test_exception_handling_falls_through— Test that exceptions during fetch are handled and fallback occurs -
test_correct_endpoint_urls— Test that the correct endpoint URLs are constructed
-
19 tests
-
TestOpenAIToVertexToolsTranslation (9 tests)
-
test_translate_single_tool— Test translating a single OpenAI tool to Vertex format -
test_translate_multiple_tools— Test translating multiple OpenAI tools to Vertex format -
test_translate_tool_without_description— Test translating a tool without description -
test_translate_tool_without_parameters— Test translating a tool without parameters -
test_translate_empty_tools_list— Test translating an empty tools list -
test_translate_none_tools— Test translating None tools -
test_skip_non_function_tools— Test that non-function tools are skipped with warning -
test_skip_tool_without_name— Test that tools without name are skipped -
test_skip_tool_without_function_definition— Test that tools without function definition are skipped
-
-
TestToolChoiceTranslation (8 tests)
-
test_translate_tool_choice_none— Test translating tool_choice='none' -
test_translate_tool_choice_auto— Test translating tool_choice='auto' -
test_translate_tool_choice_required— Test translating tool_choice='required' -
test_translate_tool_choice_specific_function— Test translating tool_choice with specific function -
test_translate_tool_choice_null— Test translating tool_choice=None -
test_translate_unknown_tool_choice_string— Test translating unknown tool_choice string defaults to AUTO -
test_translate_tool_choice_function_missing_name— Test translating tool_choice function without name -
test_translate_tool_choice_function_is_none— Test translating tool_choice when function value is None
-
-
TestGoogleVertexToolsSupport (2 tests)
-
test_tools_extracted_from_kwargs— Test that tools are extracted from kwargs -
test_tools_request_completes_successfully— Test that requests with tools complete successfully
-
2 tests
-
TestHuggingfaceModels (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module exports
-
7 tests
-
TestModelAvailability (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module exports
-
-
TestIsModelAvailable (5 tests)
-
test_unknown_model_returns_available— Test that unknown models (not in availability cache) return True. -
test_available_model_returns_available— Test that models with AVAILABLE status return True -
test_model_with_open_circuit_returns_unavailable— Test that models with OPEN circuit breaker return False -
test_model_in_maintenance_returns_unavailable— Test that models in maintenance mode return False -
test_unavailable_status_returns_unavailable— Test that models with UNAVAILABLE status return False
-
37 tests
-
TestCircuitBreakerStateTransitions (8 tests)
-
test_initial_state_is_closed— Test circuit breaker starts in CLOSED state -
test_can_execute_when_closed— Test requests can execute when CLOSED -
test_transitions_to_open_after_failures— Test CLOSED -> OPEN after failure threshold -
test_cannot_execute_when_open— Test requests blocked when OPEN -
test_transitions_to_half_open_after_recovery_timeout— Test OPEN -> HALF_OPEN after recovery timeout -
test_half_open_to_closed_after_successes— Test HALF_OPEN -> CLOSED after success threshold -
test_half_open_to_open_on_failure— Test HALF_OPEN -> OPEN on failure -
test_success_decrements_failure_count_when_closed— Test success reduces failure count in CLOSED state
-
-
TestAvailabilityConfig (2 tests)
-
test_default_config_values— Test default configuration values -
test_custom_config_values— Test custom configuration values
-
-
TestModelAvailabilityDataclass (1 tests)
-
test_create_model_availability— Test creating ModelAvailability instance
-
-
TestModelAvailabilityService (16 tests)
-
test_service_initialization— Test service initializes correctly -
test_fallback_mappings_loaded— Test fallback mappings are loaded correctly -
test_get_fallback_models— Test getting fallback models -
test_get_model_availability_not_found— Test getting availability for unknown model -
test_get_model_availability_with_gateway— Test getting availability with specific gateway -
test_get_available_models_empty— Test getting available models when cache is empty -
test_get_available_models_filtered— Test getting available models with filters -
test_is_model_available— Test model availability check -
test_is_model_available_with_open_circuit— Test availability check with open circuit breaker -
test_is_model_available_during_maintenance— Test availability check during maintenance -
test_get_best_available_model_preferred_available— Test best model selection when preferred is available -
test_get_best_available_model_with_fallback— Test best model selection falls back when preferred unavailable -
test_get_availability_summary_empty— Test availability summary with empty cache -
test_get_availability_summary— Test availability summary with data -
test_set_maintenance_mode— Test setting maintenance mode -
test_clear_maintenance_mode— Test clearing maintenance mode
-
-
TestModelAvailabilityServiceAsync (3 tests)
-
test_start_monitoring— Test starting availability monitoring -
test_start_monitoring_idempotent— Test starting monitoring multiple times is idempotent -
test_stop_monitoring_when_not_started— Test stopping monitoring when not started
-
-
TestAvailabilityStatus (5 tests)
-
test_available_status— Test AVAILABLE status -
test_unavailable_status— Test UNAVAILABLE status -
test_degraded_status— Test DEGRADED status -
test_maintenance_status— Test MAINTENANCE status -
test_unknown_status— Test UNKNOWN status
-
-
TestGlobalAvailabilityService (2 tests)
-
test_global_service_exists— Test global service is initialized -
test_global_service_has_fallback_mappings— Test global service has fallback mappings loaded
-
51 tests
-
TestModelHealthTracking (4 tests)
-
test_get_model_health_returns_none_for_unknown— Get health for unknown model returns None -
test_get_all_models_health_returns_list— Get all models health returns a list -
test_get_health_summary_returns_dict— Get health summary returns a dictionary -
test_get_system_health_initially_none— System health is None before monitoring starts
-
-
TestHealthStatusManagement (3 tests)
-
test_get_provider_health_returns_none_for_unknown— Get provider health for unknown provider returns None -
test_get_all_providers_health_returns_list— Get all providers health returns a list -
test_health_data_structure— Health data internal structure is initialized
-
-
TestHealthScoreCalculation (3 tests)
-
test_calculate_health_score_all_success— Calculate health score with all successful requests -
test_calculate_health_score_mixed— Calculate health score with mixed results -
test_calculate_health_score_all_failures— Calculate health score with all failures
-
-
TestHealthMetrics (2 tests)
-
test_model_health_metrics_dataclass— Test ModelHealthMetrics dataclass structure -
test_model_health_metrics_unhealthy— Test ModelHealthMetrics with unhealthy status
-
-
TestFailureDetection (3 tests)
-
test_detect_high_error_rate— Detect when error rate exceeds threshold -
test_detect_slow_response— Detect when latency exceeds threshold -
test_consecutive_failures— Detect consecutive failures
-
-
TestRecoveryDetection (2 tests)
-
test_health_status_enum_values— Test HealthStatus enum has expected values -
test_health_status_transitions— Test that health status can transition between states
-
-
TestHealthAlerts (2 tests)
-
test_alert_on_model_failure— Alert should trigger when model fails -
test_alert_cooldown— Alerts should have cooldown period
-
-
TestHealthMonitoringEdgeCases (3 tests)
-
test_get_model_health_with_none_model_id— Handle None model ID gracefully -
test_get_model_health_with_empty_string— Handle empty string model ID -
test_get_provider_health_with_none_values— Handle None provider/gateway gracefully
-
-
TestHealthMonitorPersistence (2 tests)
-
test_health_data_dict_initialized— Health data dictionary is initialized on monitor creation -
test_model_health_metrics_has_timestamp— ModelHealthMetrics includes last_checked timestamp
-
-
TestHealthMonitorIntegration (2 tests)
-
test_unhealthy_models_excluded_from_routing— Unhealthy models should be excluded from routing -
test_health_check_integration— Health monitor should integrate with health check endpoint
-
-
TestPerformanceMetrics (3 tests)
-
test_calculate_success_rate— Calculate success rate correctly -
test_calculate_average_latency— Calculate average latency -
test_calculate_error_rate— Calculate error rate
-
-
TestSentryErrorCapture (3 tests)
-
test_sentry_capture_on_model_failure— Test that Sentry captures errors when models fail health checks -
test_sentry_capture_on_exception— Test that Sentry captures exceptions during health checks -
test_sentry_not_captured_on_success— Test that Sentry does not capture errors when models are healthy
-
-
TestApiKeyForGateway (2 tests)
-
test_get_api_key_for_known_gateway— Test that API key is returned for known gateways -
test_get_api_key_for_unknown_gateway— Test that None is returned for unknown gateways
-
-
TestPerformModelRequestAuthentication (2 tests)
-
test_returns_error_when_no_api_key_configured— Test that request fails when no API key is configured for gateway -
test_returns_error_for_unknown_gateway— Test that request fails for unknown gateway (no URL configured)
-
-
TestShouldCaptureError (15 tests)
-
test_should_capture_unknown_errors— Test that unknown errors (no status code) are captured -
test_should_not_capture_rate_limits— Test that rate limit errors (429) are NOT captured -
test_should_not_capture_data_policy_errors— Test that data policy restriction errors (404) are NOT captured -
test_should_capture_other_404_errors— Test that other 404 errors (not data policy) ARE captured -
test_should_not_capture_service_unavailable— Test that service unavailable errors (503) are NOT captured -
test_should_capture_other_503_errors— Test that other 503 errors ARE captured -
test_should_not_capture_max_output_tokens_validation— Test that max_output_tokens validation errors (400) are NOT captured -
test_should_not_capture_audio_modality_errors— Test that audio modality requirement errors (400) are NOT captured -
test_should_capture_other_400_errors— Test that other 400 errors ARE captured -
test_should_not_capture_auth_key_errors— Test that authentication key errors (403) are NOT captured -
test_should_capture_other_403_errors— Test that other 403 errors ARE captured -
test_should_capture_server_errors— Test that server errors (500, 502, etc.) ARE captured -
test_should_capture_client_errors— Test that most client errors ARE captured -
test_error_filtering_in_check_model_health_rate_limit— Test that rate limit errors are not sent to Sentry during health checks -
test_error_filtering_in_check_model_health_server_error— Test that server errors ARE sent to Sentry during health checks
-
104 tests
-
TestModelAliasResolution (10 tests)
-
test_gpt_5_1_variants— Test GPT-5.1 alias variants -
test_xai_deprecated— Test XAI deprecated model aliases test_case_insensitivetest_no_match_passthroughtest_none_inputtest_empty_string-
test_bare_openai_model_names— Bare OpenAI model names alias to canonical openai/ prefix. -
test_bare_anthropic_model_names— Bare Anthropic model names alias to canonical anthropic/ prefix. -
test_z_ai_glm_47_alias— Non-existent z-ai/glm-4.7 maps to z-ai/glm-4-flash -
test_aliased_models_canonical_routing— Aliased models (gpt-4, claude-3-opus) now have canonical prefixes.
-
-
TestProviderDetection (16 tests)
test_openai_modelstest_anthropic_modelstest_bare_openai_models_detect_as_nativetest_bare_anthropic_models_detect_as_nativetest_fal_ai_modelstest_fal_related_orgstest_groq_modelstest_google_vertex_modelstest_at_prefix_models_route_to_openroutertest_z_ai_prefix_modelstest_z_ai_glm_with_exacto_suffixtest_openrouter_colon_suffix_variantstest_gpt51_alias_without_orgtest_onerouter_prefixed_modelstest_onerouter_versioned_modelstest_meta_llama_has_no_specific_provider
-
TestFireworksTransformations (16 tests)
test_deepseek_v3test_deepseek_v3_alt_orgtest_deepseek_v3_1test_deepseek_r1test_llama_3_3_70btest_llama_3_1_70btest_qwen_modelstest_already_in_fireworks_formattest_unknown_model_passes_throughtest_unknown_model_does_not_construct_invalid_idtest_unknown_model_without_slash_passthroughtest_nonexistent_variant_passthroughtest_fuzzy_match_still_workstest_version_variationstest_mixed_casetest_instruct_suffix
-
TestOpenRouterTransformations (9 tests)
test_prefix_strippedtest_auto_preservedtest_bodybuilder_preservedtest_meta_models_preservedtest_gpt51_hyphen_aliastest_claude_sonnet_variantstest_cerebras_to_openroutertest_z_ai_glm_passthroughtest_normalizes_to_lowercase
-
TestOpenRouterAutoFallbacks (6 tests)
test_fallback_to_cerebrastest_fallback_to_huggingfacetest_fallback_to_google_vertextest_fallback_to_alibabatest_fallback_providers_definedtest_fallback_models_valid
-
TestGroqTransformations (2 tests)
test_prefix_strippedtest_without_prefix_passthrough
-
TestGoogleVertexTransformations (5 tests)
test_gemini_2_5_flashtest_with_google_prefixtest_with_at_prefixtest_gemini_1_5_protest_gemini_2_0_flash
-
TestHuggingFaceTransformations (5 tests)
test_llama_modelstest_deepseek_modelstest_qwen_modelstest_mistral_modelstest_hug_alias_same_as_huggingface
-
TestOneRouterTransformations (5 tests)
test_strips_prefixtest_passthrough_versionedtest_simple_names_get_version_suffixtest_unknown_model_passthroughtest_model_id_mapping_exists
-
TestOtherProviderTransformations (3 tests)
test_near_prefix_strippedtest_aimo_prefix_strippedtest_morpheus_prefix_stripped
-
TestModelIdNormalization (3 tests)
test_empty_stringtest_none_inputtest_preserves_special_characters
-
TestNormalizeModelName (2 tests)
test_normalize_basictest_normalize_handles_version_separators
-
TestModelProviderOverrides (2 tests)
test_katanemo_overridetest_zai_override
-
TestGetModelIdMapping (7 tests)
test_fireworks_mappingtest_openrouter_mappingtest_groq_mappingtest_google_vertex_mappingtest_cloudflare_mappingtest_unknown_provider_mappingtest_return_value_matches_direct_lookup
-
TestModelIdMappingsTopLevel (4 tests)
test_mappings_is_dicttest_mappings_is_non_emptytest_expected_provider_counttest_all_known_providers_present
-
TestPerProviderMappingType (1 tests)
test_provider_mapping_is_dict
-
TestMappingKeyValueTypes (2 tests)
test_all_keys_are_non_empty_stringstest_all_values_are_non_empty_strings
-
TestNoSelfMappings (1 tests)
test_no_self_mapping_entries
-
TestGetModelIdMappingAPI (5 tests)
test_returns_dict_for_known_providertest_returns_non_empty_for_known_providerstest_returns_empty_for_unknowntest_result_keys_are_stringstest_result_values_are_strings
2 tests
-
TestMultiProviderRegistry (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module exports
-
29 tests
-
TestNosanaClient (7 tests)
-
test_get_nosana_client— Test getting Nosana client -
test_get_nosana_client_no_key— Test getting Nosana client without API key -
test_make_nosana_request_openai— Test making request to Nosana -
test_make_nosana_request_openai_stream— Test making streaming request to Nosana -
test_process_nosana_response— Test processing Nosana response -
test_process_nosana_response_no_usage— Test processing Nosana response without usage data -
test_make_nosana_request_with_kwargs— Test making request to Nosana with additional parameters
-
-
TestNosanaJobDefinitionBuilders (8 tests)
-
test_build_container_job_definition_basic— Test building a basic container job definition -
test_build_container_job_definition_with_all_options— Test building a container job definition with all options -
test_build_llm_inference_job_definition_vllm— Test building vLLM inference job definition -
test_build_llm_inference_job_definition_ollama— Test building Ollama inference job definition -
test_build_llm_inference_job_definition_lmdeploy— Test building LMDeploy inference job definition -
test_build_llm_inference_job_definition_invalid_framework— Test building LLM inference with invalid framework -
test_build_stable_diffusion_job_definition— Test building Stable Diffusion job definition -
test_build_whisper_job_definition— Test building Whisper job definition
-
-
TestNosanaDeploymentAPI (6 tests)
-
test_get_credits_balance— Test getting credit balance -
test_list_deployments— Test listing deployments -
test_create_deployment— Test creating a deployment -
test_create_deployment_invalid_strategy— Test creating deployment with invalid strategy -
test_create_deployment_invalid_timeout— Test creating deployment with invalid timeout -
test_create_deployment_invalid_replicas— Test creating deployment with invalid replicas
-
-
TestNosanaJobsAPI (3 tests)
-
test_create_job— Test creating a job -
test_create_job_invalid_timeout— Test creating job with invalid timeout -
test_extend_job_invalid_timeout— Test extending job with invalid timeout
-
-
TestNosanaMarketsAPI (3 tests)
-
test_list_markets— Test listing markets -
test_list_markets_with_filter— Test listing markets with type filter -
test_list_markets_invalid_type— Test listing markets with invalid type
-
-
TestNosanaConstants (2 tests)
-
test_deployment_strategies— Test deployment strategies are defined -
test_deployment_statuses— Test deployment statuses are defined
-
29 tests
-
TestUserPreferences (8 tests)
-
test_get_user_preferences_exists— Test getting existing user preferences -
test_get_user_preferences_not_found— Test getting preferences for user without preferences -
test_get_user_preferences_error_handling— Test error handling when getting preferences -
test_create_user_preferences_success— Test creating default preferences -
test_create_user_preferences_error— Test error handling when creating preferences -
test_update_user_preferences_success— Test updating user preferences -
test_update_user_preferences_not_found— Test updating non-existent preferences -
test_update_user_preferences_error— Test error handling when updating preferences
-
-
TestLowBalanceAlerts (6 tests)
-
test_check_low_balance_alert_triggered— Test low balance alert is triggered when credits < $5 -
test_check_low_balance_alert_not_triggered— Test low balance alert not triggered when credits > $5 -
test_check_low_balance_alert_trial_user— Test low balance alert for trial user includes trial info -
test_check_low_balance_alert_user_not_found— Test low balance alert when user not found -
test_check_low_balance_alert_notifications_disabled— Test low balance alert when notifications are disabled -
test_check_low_balance_alert_recent_notification— Test low balance alert skipped if recent notification sent
-
-
TestTrialExpiryAlerts (3 tests)
-
test_check_trial_expiry_alert_triggered— Test trial expiry alert triggered 1 day before expiry -
test_check_trial_expiry_alert_not_trial_user— Test no alert for non-trial users -
test_check_trial_expiry_alert_too_early— Test no alert when trial has >1 day remaining
-
-
TestRecentNotificationTracking (3 tests)
-
test_has_recent_notification_found— Test detecting recent notification -
test_has_recent_notification_not_found— Test no recent notification -
test_has_recent_notification_error— Test error handling in recent notification check
-
-
TestNotificationServiceInit (2 tests)
-
test_init_with_environment_variables— Test initialization with environment variables -
test_init_with_defaults— Test initialization with default values
-
-
TestNotificationIntegration (1 tests)
-
test_low_balance_alert_with_plan_info— Test low balance alert includes plan information for paid users
-
-
TestEmailValidation (6 tests)
-
test_valid_email_addresses— Test that valid email addresses pass validation -
test_privy_placeholder_emails_rejected— Test that Privy placeholder emails are rejected -
test_did_prefix_emails_rejected— Test that DID-prefixed emails are rejected -
test_malformed_emails_rejected— Test that malformed emails are rejected -
test_send_email_skips_invalid_addresses— Test that send_email_notification skips invalid email addresses -
test_send_email_proceeds_for_valid_addresses— Test that send_email_notification proceeds for valid email addresses
-
19 tests
test_get_openrouter_client_successtest_get_openrouter_client_missing_key_raisestest_make_openrouter_request_openai_forwards_argstest_process_openrouter_response_happytest_process_openrouter_response_no_usage-
test_make_openrouter_request_normalizes_developer_role— Verify that make_openrouter_request_openai normalizes developer role to system. -
test_make_openrouter_request_stream_normalizes_developer_role— Verify that make_openrouter_request_openai_stream normalizes developer role to system. -
test_make_openrouter_request_stream_async_normalizes_developer_role— Verify that make_openrouter_request_openai_stream_async normalizes developer role to system. -
TestMergeExtraBody (5 tests)
-
test_merge_empty_kwargs— Empty kwargs should get extra_body with provider settings. -
test_merge_preserves_other_kwargs— Other kwargs like temperature should be preserved. -
test_merge_preserves_existing_extra_body— Existing extra_body values should be preserved. -
test_merge_preserves_existing_provider_settings— Existing provider settings should be preserved and merged. -
test_user_can_override_data_collection— User-provided data_collection should override the default.
-
-
TestNormalizeMessageRoles (6 tests)
-
test_normalize_empty_messages— Empty messages list should return empty list. -
test_normalize_preserves_standard_roles— Standard roles (user, assistant, system, tool) should be preserved. -
test_normalize_transforms_developer_to_system— Developer role should be transformed to system role. -
test_normalize_preserves_other_message_fields— Other message fields should be preserved when transforming developer role. -
test_normalize_multiple_developer_messages— Multiple developer messages should all be transformed. -
test_normalize_handles_non_dict_messages— Non-dict messages should be passed through unchanged.
-
17 tests
-
TestPartnerTrialService (17 tests)
-
test_get_partner_config_valid_partner— Test fetching valid partner configuration -
test_get_partner_config_case_insensitive— Test that partner code lookup is case insensitive -
test_get_partner_config_not_found— Test fetching non-existent partner -
test_get_partner_config_caching— Test that partner configs are cached -
test_is_partner_code_true— Test is_partner_code returns True for valid partner -
test_is_partner_code_false— Test is_partner_code returns False for invalid partner -
test_is_partner_code_empty— Test is_partner_code returns False for empty string -
test_start_partner_trial_success— Test starting a partner trial successfully -
test_start_partner_trial_invalid_partner— Test starting trial with invalid partner code raises error -
test_get_user_daily_limit_partner_user— Test getting daily limit for partner trial user -
test_get_user_daily_limit_standard_user— Test getting daily limit for standard trial user -
test_get_user_daily_limit_paid_subscriber— Test getting daily limit for paid subscriber (unlimited) -
test_get_partner_trial_status— Test getting partner trial status -
test_get_partner_trial_status_no_trial— Test getting status when user has no partner trial -
test_get_partner_analytics— Test getting partner analytics -
test_cache_invalidation— Test cache invalidation -
test_cache_invalidation_all— Test invalidating entire cache
-
6 tests
-
TestPaymentFailureDowngrade (6 tests)
-
test_invoice_payment_failed_downgrades_tier— Test that invoice payment failure downgrades user to basic tier -
test_invoice_payment_failed_for_max_tier— Test that MAX tier is also downgraded on payment failure -
test_invoice_payment_failed_non_subscription— Test that non-subscription invoices are skipped -
test_payment_failure_updates_both_tables— Test that payment failure updates both users and api_keys_new tables -
test_payment_failure_logs_warning— Test that payment failure logs appropriate warning -
test_payment_failure_handles_database_error— Test that database errors during payment failure are handled
-
34 tests
-
TestStripeServiceInitialization (2 tests)
-
test_init_success— Test successful initialization -
test_init_missing_api_key— Test initialization fails without API key
-
-
TestCheckoutSession (7 tests)
-
test_create_checkout_session_success— Test successful checkout session creation -
test_create_checkout_session_with_discounted_credit_value— Test checkout session with discounted credit_value (e.g., $9 for $10 credits) -
test_create_checkout_session_large_discounted_package— Test checkout session with larger discounted package ($75 for $100 credits) -
test_create_checkout_session_persists_payment_intent— Ensure checkout session stores payment_intent when provided by Stripe. -
test_create_checkout_session_user_not_found— Test checkout session fails for non-existent user -
test_create_checkout_session_stripe_error— Test checkout session handles Stripe errors -
test_create_checkout_session_with_privy_did— Test checkout session handles Privy DID emails
-
-
TestPaymentIntents (2 tests)
-
test_create_payment_intent_success— Test successful payment intent creation -
test_create_payment_intent_with_specific_payment_methods— Test payment intent with specific payment methods
-
-
TestWebhooks (11 tests)
-
test_handle_checkout_completed_webhook— Test checkout.session.completed webhook -
test_handle_webhook_invalid_signature— Test webhook with invalid signature -
test_checkout_completed_adds_credits— Test checkout completed webhook adds credits to user -
test_checkout_completed_refetches_metadata_when_missing— Ensure checkout handler refetches the session when metadata is missing -
test_checkout_completed_recovers_metadata_from_payment_intent— Verify fallback metadata retrieval pulls from the related payment intent. -
test_checkout_completed_hydrates_metadata_from_payment_intent— Ensure metadata can be recovered from the PaymentIntent when absent on the session. -
test_checkout_completed_raises_when_metadata_and_id_missing— Ensure handler fails fast when both metadata and session id are missing -
test_checkout_completed_recovers_missing_metadata— Ensure webhook handler falls back to Supabase when metadata is absent. -
test_checkout_completed_recovers_via_session_id_when_intent_lookup_fails— Ensure fallback lookup retries with the checkout session ID. -
test_payment_intent_succeeded_webhook— Test payment_intent.succeeded webhook -
test_payment_intent_failed_webhook— Test payment_intent.payment_failed webhook
-
-
TestCreditPackages (1 tests)
-
test_get_credit_packages— Test get credit packages
-
-
TestRefunds (2 tests)
-
test_create_refund_success— Test successful refund creation -
test_create_refund_stripe_error— Test refund handles Stripe errors
-
-
TestSessionRetrieval (2 tests)
-
test_retrieve_checkout_session— Test retrieve checkout session -
test_retrieve_payment_intent— Test retrieve payment intent
-
-
TestPaymentIntegration (4 tests)
-
test_complete_payment_flow— Test complete payment flow: create session → webhook → credits added -
test_checkout_completed_missing_credits_uses_amount_total— Ensure handler falls back to session amount when credits metadata is missing -
test_checkout_completed_missing_ids_uses_payment_lookup— Ensure handler can recover user/payment IDs from Supabase when metadata is incomplete -
test_checkout_completed_creates_fallback_payment_when_missing_metadata— Ensure handler creates a fallback payment record when payment_id cannot be recovered.
-
-
TestCheckoutCompletedSubscriptionStatus (3 tests)
-
test_checkout_completed_sets_inactive_status_for_trial_user— Test that checkout completed sets subscription_status to 'inactive' for trial users. -
test_checkout_completed_preserves_active_subscription_status— Test that checkout completed does NOT change subscription_status for users with active subscriptions. -
test_checkout_completed_sets_inactive_for_expired_trial_user— Test that checkout completed sets subscription_status to 'inactive' for expired trial users.
-
6 tests
-
test_decimal_credit_calculation— Test that Decimal provides precise credit calculations. -
test_decimal_precision_edge_cases— Test edge cases where floating-point precision matters. -
test_decimal_preserves_precision— Test that Decimal preserves precision better than float. -
test_credit_value_conversion_matches_schema— Test that credit value conversion matches expected schema behavior. -
test_large_credit_values— Test that large credit values are handled correctly. -
test_fractional_cents_handled— Test that fractional cents are handled correctly.
6 tests
-
TestPosthogService (6 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module exports -
test_initialize_with_exception_autocapture— Test that PostHog initializes with exception autocapture enabled -
test_capture_exception_success— Test successful exception capture -
test_capture_exception_default_distinct_id— Test exception capture with default distinct_id -
test_capture_exception_when_not_initialized— Test that capture_exception handles uninitialized client gracefully
-
2 tests
-
TestProfessionalEmailTemplates (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module exports
-
37 tests
-
TestPrometheusProtobuf (7 tests)
-
test_label_serialization— Test Label message serialization -
test_label_empty_values— Test Label with empty values -
test_sample_serialization— Test Sample message serialization -
test_sample_zero_value— Test Sample with zero value but non-zero timestamp -
test_timeseries_serialization— Test TimeSeries message serialization -
test_write_request_serialization— Test WriteRequest message serialization -
test_write_request_multiple_timeseries— Test WriteRequest with multiple timeseries
-
-
TestPrometheusRemoteWrite (24 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module exports -
test_prometheus_remote_writer_initialization— Test PrometheusRemoteWriter initialization -
test_push_metrics_when_disabled— Test push_metrics returns False when disabled -
test_push_metrics_when_no_client— Test push_metrics returns False when client is None -
test_push_metrics_success— Test successful metrics push with protobuf -
test_push_metrics_http_error— Test metrics push with HTTP error -
test_get_stats— Test get_stats returns correct statistics -
test_get_stats_no_pushes— Test get_stats with no pushes returns 0 success rate -
test_circuit_breaker_initial_state— Test circuit breaker is initially closed -
test_circuit_breaker_opens_after_threshold— Test circuit breaker opens after consecutive failures -
test_circuit_breaker_resets_on_success— Test circuit breaker resets after successful push -
test_circuit_breaker_closes_after_timeout— Test circuit breaker allows retry after timeout -
test_push_metrics_skipped_when_circuit_open— Test push_metrics is skipped when circuit is open -
test_circuit_breaker_opens_on_connection_errors— Test circuit breaker opens after repeated connection errors -
test_circuit_breaker_opens_on_timeout_errors— Test circuit breaker opens after repeated timeout errors -
test_init_prometheus_remote_write_disabled— Test init_prometheus_remote_write when Prometheus is disabled -
test_init_prometheus_remote_write_enabled— Test init_prometheus_remote_write creates and starts writer -
test_shutdown_prometheus_remote_write_with_writer— Test shutdown_prometheus_remote_write with active writer -
test_shutdown_prometheus_remote_write_no_writer— Test shutdown_prometheus_remote_write with no writer -
test_get_prometheus_writer— Test get_prometheus_writer returns the global instance -
test_serialize_metrics_success— Test successful metrics serialization with new protobuf implementation -
test_serialize_metrics_empty_registry— Test serialization with empty registry -
test_get_instance_labels— Test _get_instance_labels returns expected labels
-
-
TestVarintEncoding (4 tests)
-
test_encode_small_value— Test encoding small values (< 128) -
test_encode_medium_value— Test encoding medium values (128-16383) -
test_encode_large_value— Test encoding large values (timestamps) -
test_encode_negative_value_raises— Test that encoding negative values raises ValueError
-
-
TestLabelSorting (2 tests)
-
test_labels_are_sorted— Test that labels in TimeSeries are sorted by name -
test_serialize_metrics_sorts_labels— Test that _serialize_metrics_to_protobuf sorts labels correctly
-
14 tests
-
test_provider_module_imports— Every provider module must import without errors. -
TestGetClientMissingKey (1 tests)
test_raises_value_error
-
TestMakeRequest (2 tests)
test_forwards_to_createtest_propagates_error
-
TestMakeRequestStream (2 tests)
test_stream_flagtest_stream_propagates_error
-
TestProcessResponse (2 tests)
test_extracts_fieldstest_no_usage
-
TestSanitizeMessagesForFeatherless (6 tests)
test_removes_null_tool_calls_from_dicttest_preserves_valid_tool_callstest_preserves_messages_without_tool_callstest_does_not_mutate_original_messagestest_removes_invalid_tool_calls_typetest_handles_empty_list
99 tests
-
TestBuildProviderFailoverChain (10 tests)
-
test_chain_with_huggingface_first— Test chain starting with huggingface -
test_chain_with_openrouter_first— Test chain starting with openrouter -
test_chain_with_featherless_first— Test chain starting with featherless -
test_chain_with_none_provider— Test chain with None provider defaults to onerouter -
test_chain_with_empty_string— Test chain with empty string defaults to onerouter -
test_chain_with_unknown_provider— Test chain with unknown provider (not in fallback list) -
test_chain_with_removed_provider— Test chain with removed provider (not eligible for fallback) -
test_chain_case_insensitive— Test chain building is case insensitive -
test_chain_no_duplicates— Test chain has no duplicate providers -
test_fallback_provider_priority_constants— Test fallback provider constants are defined correctly
-
-
TestEnforceModelFailoverRules (17 tests)
test_openrouter_prefix_lockedtest_openrouter_suffix_locked-
test_openai_prefix_routes_to_native_then_openrouter— Test that openai/* models route to native OpenAI first, then OpenRouter fallback. -
test_openai_prefix_without_native_falls_back_to_openrouter— Test that openai/* models fall back to OpenRouter if native OpenAI not in chain. -
test_anthropic_prefix_routes_to_native_then_openrouter— Test that anthropic/* models route to native Anthropic first, then OpenRouter fallback. -
test_anthropic_prefix_without_native_falls_back_to_openrouter— Test that anthropic/* models fall back to OpenRouter if native Anthropic not in chain. test_non_locked_model_noop-
test_payment_failover_does_not_bypass_anthropic_restriction— Test that allow_payment_failover=True does NOT bypass anthropic/ restriction. -
test_payment_failover_does_not_bypass_openai_restriction— Test that allow_payment_failover=True does NOT bypass openai/ restriction. -
test_payment_failover_does_not_bypass_suffix_lock— Test that allow_payment_failover=True does NOT bypass suffix-based provider lock. -
test_payment_failover_no_effect_on_unlocked_models— Test that allow_payment_failover has no effect on models without provider lock -
test_bare_openai_model_names_route_to_native_first— Test that bare OpenAI model names route to native OpenAI first, then OpenRouter. -
test_bare_openai_model_names_fallback_to_openrouter— Test that bare OpenAI model names fall back to OpenRouter if native not in chain. -
test_bare_openai_model_names_keep_restriction_with_payment_failover— Test that bare OpenAI model names keep their restriction even with payment_failover=True. -
test_bare_anthropic_model_names_route_to_native_first— Test that bare Anthropic/Claude model names route to native Anthropic first, then OpenRouter. -
test_bare_anthropic_model_names_fallback_to_openrouter— Test that bare Anthropic model names fall back to OpenRouter if native not in chain. -
test_bare_anthropic_model_names_keep_restriction_with_payment_failover— Test that bare Anthropic model names keep restriction with payment_failover=True.
-
TestShouldFailover (12 tests)
-
test_should_failover_401— Test 401 Unauthorized triggers failover -
test_should_failover_403— Test 403 Forbidden triggers failover -
test_should_failover_404— Test 404 Not Found triggers failover -
test_should_failover_429— Test 429 Rate Limit does NOT trigger failover - client should retry -
test_should_failover_502— Test 502 Bad Gateway triggers failover -
test_should_failover_503— Test 503 Service Unavailable triggers failover -
test_should_failover_504— Test 504 Gateway Timeout triggers failover -
test_should_not_failover_200— Test 200 OK does not trigger failover -
test_should_not_failover_400— Test 400 Bad Request does not trigger failover -
test_should_not_failover_500— Test 500 Internal Server Error does not trigger failover -
test_failover_status_codes_constant— Test FAILOVER_STATUS_CODES contains expected codes -
test_should_failover_402— Test 402 Payment Required triggers failover (e.g., provider credits exhausted)
-
-
TestMapProviderErrorHTTPException (2 tests)
-
test_map_http_exception_passthrough— Test HTTPException is passed through unchanged -
test_map_value_error— Test ValueError is mapped to 400
-
-
TestMapProviderErrorHTTPX (9 tests)
-
test_map_httpx_timeout_exception— Test httpx.TimeoutException maps to 504 -
test_map_asyncio_timeout_error— Test asyncio.TimeoutError maps to 504 -
test_map_httpx_request_error— Test httpx.RequestError maps to 503 -
test_map_httpx_status_error_429_with_retry_after— Test httpx 429 error preserves Retry-After header -
test_map_httpx_status_error_429_without_retry_after— Test httpx 429 error without Retry-After header -
test_map_httpx_status_error_401— Test httpx 401 error maps to 500 (internal auth issue) -
test_map_httpx_status_error_404— Test httpx 404 error indicates model not found -
test_map_httpx_status_error_4xx— Test httpx 4xx errors map to 400 -
test_map_httpx_status_error_5xx— Test httpx 5xx errors map to 502
-
-
TestMapProviderErrorOpenAI (13 tests)
-
test_map_api_connection_error— Test APIConnectionError maps to 503 -
test_map_api_timeout_error— Test APITimeoutError maps to 504 -
test_map_rate_limit_error_with_retry_after_header— Test RateLimitError with Retry-After in response headers -
test_map_rate_limit_error_with_retry_after_body— Test RateLimitError with retry_after in body -
test_map_authentication_error— Test AuthenticationError maps to 401 -
test_map_permission_denied_error— Test PermissionDeniedError maps to 401 -
test_map_not_found_error— Test NotFoundError indicates model not available -
test_map_bad_request_error— Test BadRequestError maps to 400 -
test_map_generic_openai_error— Test generic OpenAIError maps to 502 -
test_map_api_status_error_with_custom_status— Test APIStatusError with custom status code -
test_map_api_status_error_invalid_status— Test APIStatusError with invalid status code defaults to 500 -
test_map_api_status_error_404_generic— Test generic APIStatusError with 404 status provides proper error message -
test_map_api_status_error_403_maps_to_401— Test generic APIStatusError with 403 maps to 401 for consistency
-
-
TestMapProviderErrorCerebras (12 tests)
-
test_map_cerebras_api_connection_error— Test Cerebras APIConnectionError maps to 503 -
test_map_cerebras_rate_limit_error_with_retry_after_header— Test Cerebras RateLimitError with Retry-After in response headers -
test_map_cerebras_rate_limit_error_with_retry_after_body— Test Cerebras RateLimitError with retry_after in body -
test_map_cerebras_authentication_error— Test Cerebras AuthenticationError maps to 401 -
test_map_cerebras_permission_denied_error— Test Cerebras PermissionDeniedError maps to 401 -
test_map_cerebras_not_found_error— Test Cerebras NotFoundError indicates model not available -
test_map_cerebras_bad_request_error— Test Cerebras BadRequestError maps to 400 -
test_map_cerebras_api_status_error_with_custom_status— Test Cerebras APIStatusError with custom status code -
test_map_cerebras_api_status_error_invalid_status— Test Cerebras APIStatusError with invalid status code defaults to 500 -
test_map_cerebras_api_status_error_5xx— Test Cerebras APIStatusError with 5xx status maps to service error -
test_map_cerebras_api_status_error_403_generic— Test generic Cerebras APIStatusError with 403 maps to 401 -
test_map_cerebras_api_status_error_404_generic— Test generic Cerebras APIStatusError with 404 provides proper error message
-
-
TestMapProviderErrorCerebras (12 tests)
-
test_map_cerebras_api_connection_error— Test Cerebras APIConnectionError maps to 503 -
test_map_cerebras_rate_limit_error_with_retry_after_header— Test Cerebras RateLimitError with Retry-After in response headers -
test_map_cerebras_rate_limit_error_with_retry_after_body— Test Cerebras RateLimitError with retry_after in body -
test_map_cerebras_authentication_error— Test Cerebras AuthenticationError maps to 401 -
test_map_cerebras_permission_denied_error— Test Cerebras PermissionDeniedError maps to 401 -
test_map_cerebras_not_found_error— Test Cerebras NotFoundError indicates model not available -
test_map_cerebras_bad_request_error— Test Cerebras BadRequestError maps to 400 -
test_map_cerebras_api_status_error_with_custom_status— Test Cerebras APIStatusError with custom status code -
test_map_cerebras_api_status_error_invalid_status— Test Cerebras APIStatusError with invalid status code defaults to 500 -
test_map_cerebras_api_status_error_5xx— Test Cerebras APIStatusError with 5xx status maps to service error -
test_map_cerebras_api_status_error_403_generic— Test generic Cerebras APIStatusError with 403 maps to 401 -
test_map_cerebras_api_status_error_404_generic— Test generic Cerebras APIStatusError with 404 provides proper error message
-
-
TestMapProviderErrorGeneric (3 tests)
-
test_map_generic_exception— Test generic Exception maps to 502 -
test_map_runtime_error— Test RuntimeError maps to 502 -
test_map_key_error— Test KeyError maps to 502
-
-
TestProviderFailoverIntegration (3 tests)
-
test_complete_failover_chain_all_providers— Test complete failover chain with all providers -
test_failover_decision_matrix— Test failover decisions for various error scenarios -
test_error_mapping_preserves_provider_context— Test error messages include provider and model context
-
-
TestMapProviderErrorNoCandidates (6 tests)
-
test_no_candidates_error_triggers_failover— Test 'no candidates' ValueError maps to 503 for failover -
test_block_reason_error_triggers_failover— Test that block reason errors map to 503 -
test_prompt_feedback_error_triggers_failover— Test that promptFeedback errors map to 503 -
test_regular_value_error_does_not_trigger_failover— Test that regular ValueErrors map to 400 (no failover) -
test_503_is_in_failover_status_codes— Verify that 503 is in the set of status codes that trigger failover -
test_no_candidates_from_other_provider— Test 'no candidates' detection works for any provider, not just google-vertex
-
2 tests
-
TestProviderSelector (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module exports
-
2 tests
-
TestProviders (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module exports
-
18 tests
test_check_rate_limit_happy_path_local-
test_concurrency_limit_exceeded— Test concurrency limit - currently disabled in source code (see rate_limiting.py lines 94-104) test_burst_limit_localtest_minute_request_limit_localtest_minute_token_limit_localtest_manager_get_key_config_from_dbtest_manager_get_key_config_default_on_errortest_manager_update_key_config_calls_dbtest_get_rate_limiter_singletontest_get_rate_limit_manager_singletontest_concurrency_increment_decrement_helpers-
test_severe_rate_limit_configs_exist— Test that SEVERE_RATE_LIMIT_CONFIG and BLOCKED_ACCOUNT_CONFIG exist and have correct values -
test_severe_rate_limit_for_temporary_email— Test that temporary email domains get SEVERE rate limiting -
test_blocked_rate_limit_for_blocked_email_domain— Test that blocked email domains get BLOCKED rate limiting (most restrictive) -
test_no_severe_rate_limit_for_normal_user— Test that normal users don't get severe rate limiting -
test_severe_rate_limit_graceful_on_missing_user— Test that severe rate limit check handles missing user gracefully -
test_severe_rate_limit_graceful_on_exception— Test that severe rate limit check handles exceptions gracefully -
test_blocked_email_domain_check_priority— Test that blocked domains take priority over temporary domains
10 tests
-
TestRebuildFullCatalogFromProviders (8 tests)
-
test_assembles_all_providers— All provider models are merged into a single catalog. -
test_caches_result_in_redis_and_local— Assembled catalog is cached in both Redis and local memory. -
test_partial_provider_failure— If some providers fail, others still contribute to the catalog. -
test_all_providers_empty_returns_empty— If every provider returns empty, result is empty and nothing is cached. -
test_empty_provider_list_returns_empty— If no provider slugs are discovered, return empty immediately. -
test_db_discovery_failure_falls_back_to_registry— If DB slug query fails, falls back to GATEWAY_REGISTRY keys. -
test_providers_with_zero_models_handled_gracefully— Providers returning 0 models don't break the assembly. -
test_does_not_use_provider_slugs_with_overrides— Fallback uses GATEWAY_REGISTRY.keys() not PROVIDER_SLUGS
-
-
TestRebuildIntegrationWithGetCachedFullCatalog (2 tests)
-
test_cache_hit_does_not_trigger_rebuild— Redis cache hit returns immediately without rebuilding. -
test_cache_miss_triggers_rebuild— Cache miss triggers rebuild_full_catalog_from_providers.
-
20 tests
-
TestRecordRequest (4 tests)
-
test_record_successful_request— Test recording a successful request -
test_record_failed_request— Test recording a failed request with error -
test_record_request_disabled— Test recording when Redis is disabled -
test_record_request_exception_handling— Test exception handling during recording
-
-
TestProviderHealth (3 tests)
-
test_get_provider_health— Test getting provider health score -
test_get_provider_health_no_data— Test getting health score when no data exists -
test_get_all_provider_health— Test getting all provider health scores
-
-
TestRecentErrors (2 tests)
-
test_get_recent_errors— Test getting recent errors -
test_get_recent_errors_disabled— Test getting errors when Redis is disabled
-
-
TestHourlyStats (2 tests)
-
test_get_hourly_stats— Test getting hourly statistics -
test_get_hourly_stats_disabled— Test getting stats when Redis is disabled returns fallback data
-
-
TestLatencyPercentiles (3 tests)
-
test_get_latency_percentiles— Test calculating latency percentiles -
test_get_latency_percentiles_no_data— Test percentiles when no data exists -
test_get_latency_percentiles_disabled— Test percentiles when Redis is disabled returns fallback data
-
-
TestCircuitBreaker (2 tests)
-
test_update_circuit_breaker— Test updating circuit breaker state -
test_update_circuit_breaker_disabled— Test updating circuit breaker when Redis is disabled
-
-
TestCleanup (2 tests)
-
test_cleanup_old_data— Test cleaning up old Redis data -
test_cleanup_old_data_disabled— Test cleanup when Redis is disabled
-
-
TestRequestMetricsDataclass (2 tests)
-
test_request_metrics_creation— Test creating RequestMetrics instance -
test_request_metrics_with_error— Test creating RequestMetrics with error
-
23 tests
-
TestRequestPrioritization (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module exports
-
-
TestLowLatencyModels (7 tests)
-
test_ultra_low_latency_models_defined— Test that ultra-low-latency models are defined -
test_low_latency_models_defined— Test that low-latency models are defined -
test_ultra_low_latency_subset_of_low_latency— Test that ultra-low-latency models are included in low-latency set -
test_is_low_latency_model— Test is_low_latency_model function -
test_is_ultra_low_latency_model— Test is_ultra_low_latency_model function -
test_get_low_latency_models— Test get_low_latency_models returns sorted list -
test_get_ultra_low_latency_models— Test get_ultra_low_latency_models returns sorted list
-
-
TestProviderLatencyTiers (6 tests)
-
test_provider_latency_tiers_defined— Test that provider latency tiers are defined -
test_groq_is_tier_1— Test that Groq is classified as tier 1 (fastest) -
test_cerebras_is_tier_1— Test that Cerebras is classified as tier 1 (fastest) -
test_fireworks_is_tier_2— Test that Fireworks is classified as tier 2 -
test_get_provider_latency_tier— Test get_provider_latency_tier function -
test_get_fastest_providers— Test get_fastest_providers returns sorted list
-
-
TestLowLatencyAlternatives (4 tests)
-
test_suggest_low_latency_alternative_for_claude— Test suggesting alternatives for Claude models -
test_suggest_low_latency_alternative_for_gpt— Test suggesting alternatives for GPT models -
test_suggest_low_latency_alternative_for_reasoning_model— Test suggesting alternatives for reasoning models -
test_suggest_low_latency_alternative_for_unknown— Test suggesting alternatives for unknown models
-
-
TestProviderSelection (4 tests)
-
test_high_priority_gets_fastest_first— Test that high priority requests get fastest providers first -
test_low_priority_gets_slower_first— Test that low priority requests get slower providers first -
test_all_providers_included— Test that all available providers are included in result -
test_empty_providers_list— Test handling of empty providers list
-
29 tests
-
TestCacheKeyGeneration (4 tests)
-
test_generate_cache_key_from_request— Generate cache key from request parameters -
test_same_request_same_key— Same request should generate same cache key -
test_different_request_different_key— Different requests should generate different keys -
test_cache_key_ignores_irrelevant_params— Cache key should ignore irrelevant parameters
-
-
TestCacheOperations (3 tests)
-
test_cache_miss— Cache miss returns None -
test_cache_hit— Cache hit returns cached response -
test_cache_set_and_get— Set and get cache entry
-
-
TestCacheTTL (3 tests)
-
test_cache_expires_after_ttl— Cache entry should expire after TTL -
test_cache_valid_within_ttl— Cache entry should be valid within TTL -
test_custom_ttl— Support custom TTL values
-
-
TestCacheInvalidation (2 tests)
-
test_invalidate_single_entry— Invalidate single cache entry -
test_clear_all_cache— Clear all cache entries
-
-
TestCachingStrategies (5 tests)
-
test_streaming_responses_not_cached— Streaming responses should not be cached -
test_error_responses_not_cached— Error responses should not be cached -
test_successful_responses_cached— Successful responses should be cached -
test_cache_respects_max_tokens— Different max_tokens should create different cache keys -
test_cache_respects_temperature— Different temperature should create different cache keys
-
-
TestCachePerformance (3 tests)
-
test_cache_reduces_latency— Cache hit should be faster than API call -
test_cache_size_limited— Cache size should be limited to prevent memory issues -
test_cache_eviction_lru— Least Recently Used (LRU) eviction strategy
-
-
TestCacheMonitoring (3 tests)
-
test_cache_hit_ratio_calculation— Calculate cache hit ratio -
test_cache_memory_usage— Track cache memory usage -
test_cache_metrics_exposed— Cache metrics should be exposed via API
-
-
TestCacheEdgeCases (3 tests)
-
test_cache_null_response— Cache should handle null responses -
test_cache_large_response— Cache should handle large responses -
test_cache_key_collision_handling— Handle potential cache key collisions
-
-
TestCacheConfiguration (3 tests)
-
test_default_ttl_configuration— Default TTL should be configurable -
test_max_cache_size_configuration— Max cache size should be configurable -
test_cache_enabled_configuration— Cache should be enable/disable via configuration
-
23 tests
-
TestRequireRole (11 tests)
-
test_require_role_admin_success— Test admin accessing admin resource -
test_require_role_developer_success— Test developer accessing developer resource -
test_require_role_user_success— Test user accessing user resource -
test_require_role_hierarchy_admin_to_dev— Test admin can access developer resources -
test_require_role_hierarchy_admin_to_user— Test admin can access user resources -
test_require_role_hierarchy_dev_to_user— Test developer can access user resources -
test_require_role_user_cannot_access_dev— Test user cannot access developer resources -
test_require_role_user_cannot_access_admin— Test user cannot access admin resources -
test_require_role_dev_cannot_access_admin— Test developer cannot access admin resources -
test_require_role_default_to_user— Test missing role defaults to user level -
test_require_role_unknown_role— Test unknown role is rejected
-
-
TestRequireAdmin (3 tests)
-
test_require_admin_success— Test admin can access admin-only resource -
test_require_admin_developer_rejected— Test developer cannot access admin-only resource -
test_require_admin_user_rejected— Test user cannot access admin-only resource
-
-
TestRequireDeveloper (3 tests)
-
test_require_developer_success— Test developer can access developer resource -
test_require_developer_admin_success— Test admin can access developer resource -
test_require_developer_user_rejected— Test user cannot access developer resource
-
-
TestRequirePermission (3 tests)
-
test_require_permission_granted— Test permission granted -
test_require_permission_denied— Test permission denied -
test_require_permission_different_resources— Test permission checking for different resources
-
-
TestCreatePermissionChecker (3 tests)
-
test_create_permission_checker_success— Test permission checker factory -
test_create_permission_checker_denied— Test permission checker factory with denied permission -
test_create_permission_checker_multiple_resources— Test creating multiple permission checkers
-
15 tests
-
TestStatsigService (3 tests)
-
test_log_event_returns_true_in_fallback_mode— Test log_event returns True in fallback mode (no server key) -
test_flush_returns_true_when_not_enabled— Test flush returns True when service is not enabled -
test_get_feature_flag_returns_default_when_not_enabled— Test get_feature_flag returns default value when not enabled
-
-
TestStatsigServiceInitialization (2 tests)
-
test_initialize_without_server_key— Test initialization gracefully handles missing server key -
test_initialize_with_missing_sdk— Test initialization handles missing statsig_python_core package
-
-
TestStatsigServiceShutdown (2 tests)
-
test_shutdown_when_not_enabled— Test shutdown works when service is not enabled -
test_shutdown_calls_wait— Test shutdown calls .wait() on the statsig SDK
-
-
TestStatsigServiceFlush (3 tests)
-
test_flush_when_not_enabled— Test flush returns True when service is not enabled -
test_flush_calls_wait_when_flush_exists— Test flush calls .wait() on the SDK flush method -
test_flush_handles_exception_gracefully— Test flush returns False when exception occurs
-
-
TestStatsigServiceBatchingConfig (1 tests)
-
test_initialization_sets_batching_options— Test that initialization configures event batching options
-
-
TestStatsigServiceSessionTracking (4 tests)
-
test_log_session_start_in_fallback_mode— Test log_session_start returns True in fallback mode -
test_log_session_start_includes_platform— Test log_session_start includes platform in metadata -
test_log_session_end_in_fallback_mode— Test log_session_end returns True in fallback mode -
test_log_session_end_includes_duration— Test log_session_end includes duration in metadata
-
20 tests
-
TestStreamNormalizer (20 tests)
test_initializationtest_openai_formattest_gemini_formattest_anthropic_formattest_reasoning_extraction-
test_reasoning_details_array_extraction— Test Grok 4.1 reasoning_details array format -
test_reasoning_details_string_array_extraction— Test reasoning_details as array of strings -
test_reasoning_details_text_field— Test reasoning_details with 'text' field instead of 'content' -
test_anthropic_thinking_delta— Test Anthropic extended thinking delta events (Claude Sonnet 4, etc.) -
test_anthropic_signature_delta— Test Anthropic signature delta events for extended thinking verification -
test_anthropic_content_block_start_thinking— Test Anthropic content_block_start event with thinking type -
test_anthropic_content_block_start_text— Test Anthropic content_block_start event with text type -
test_anthropic_message_stop— Test Anthropic message_stop event -
test_anthropic_tool_input_delta— Test Anthropic input_json_delta for tool use streaming -
test_anthropic_ping_ignored— Test that Anthropic ping events are ignored -
test_anthropic_message_start_ignored— Test that Anthropic message_start events are ignored -
test_anthropic_content_block_stop_ignored— Test that Anthropic content_block_stop events are ignored -
test_anthropic_full_extended_thinking_flow— Test a complete extended thinking flow with multiple events test_finish_reason_normalizationtest_object_chunk
25 tests
-
TestGetCurrentSubscription (3 tests)
-
test_get_subscription_with_active_subscription— Test getting subscription for user with active subscription -
test_get_subscription_without_subscription— Test getting subscription for user without subscription -
test_get_subscription_user_not_found— Test getting subscription for non-existent user
-
-
TestUpgradeSubscription (7 tests)
-
test_upgrade_invalid_product_id_returns_basic— Test upgrade fails when product ID resolves to basic tier -
test_upgrade_invalid_product_id_returns_none— Test upgrade fails when product ID resolves to None -
test_upgrade_allowance_reset_failure— Test upgrade fails when allowance reset fails -
test_upgrade_logs_credit_transaction— Test that upgrade logs audit trail via credit transaction -
test_upgrade_pro_to_max— Test upgrading from Pro to Max tier -
test_upgrade_without_subscription— Test upgrading when user has no subscription -
test_upgrade_inactive_subscription— Test upgrading when subscription is not active
-
-
TestDowngradeSubscription (6 tests)
-
test_downgrade_invalid_product_id_returns_basic— Test downgrade fails when product ID resolves to basic tier -
test_downgrade_invalid_product_id_returns_none— Test downgrade fails when product ID resolves to None -
test_downgrade_allowance_reset_failure— Test downgrade fails when allowance reset fails -
test_downgrade_logs_credit_transaction— Test that downgrade logs audit trail via credit transaction -
test_downgrade_max_to_pro— Test downgrading from Max to Pro tier -
test_downgrade_without_subscription— Test downgrading when user has no subscription
-
-
TestCancelSubscription (4 tests)
-
test_cancel_at_period_end— Test canceling subscription at end of billing period -
test_cancel_immediately— Test canceling subscription immediately -
test_cancel_without_subscription— Test canceling when user has no subscription -
test_cancel_already_canceled_subscription— Test canceling already canceled subscription
-
-
TestTransactionTypes (2 tests)
-
test_subscription_upgrade_transaction_type_exists— Test that SUBSCRIPTION_UPGRADE transaction type exists -
test_subscription_downgrade_transaction_type_exists— Test that SUBSCRIPTION_DOWNGRADE transaction type exists
-
-
TestSubscriptionManagementSchemas (3 tests)
-
test_upgrade_request_validation— Test UpgradeSubscriptionRequest validation -
test_downgrade_request_validation— Test DowngradeSubscriptionRequest validation -
test_cancel_request_defaults— Test CancelSubscriptionRequest defaults
-
56 tests
-
TestToolResult (3 tests)
-
test_success_result— Test creating a successful result. -
test_error_result— Test creating an error result. -
test_to_dict— Test converting result to dictionary.
-
-
TestBaseTool (4 tests)
-
test_cannot_instantiate_directly— Test that BaseTool cannot be instantiated directly. -
test_concrete_implementation— Test implementing a concrete tool. -
test_success_helper— Test the _success helper method. -
test_error_helper— Test the _error helper method.
-
-
TestToolRegistry (5 tests)
-
test_get_tool_definitions— Test getting all tool definitions. -
test_get_tool_by_name_exists— Test getting an existing tool by name. -
test_get_tool_by_name_not_exists— Test getting a non-existent tool. -
test_execute_tool_success— Test executing a tool by name with parameter validation. -
test_execute_tool_not_found— Test executing a non-existent tool raises ValueError.
-
-
TestChatterboxModels (9 tests)
-
test_turbo_model_english_only— Test that turbo model supports only English. -
test_multilingual_supports_many_languages— Test that multilingual model supports 22+ languages. -
test_get_chatterbox_models— Test getting formatted model list. -
test_validate_chatterbox_model_valid— Test validating valid model IDs. -
test_validate_chatterbox_model_invalid— Test validating invalid model IDs. -
test_validate_language_valid— Test validating valid language codes. -
test_validate_language_invalid_language— Test validating invalid language codes. -
test_validate_language_wrong_model— Test validating language for wrong model. -
test_validate_language_invalid_model— Test validating language for non-existent model.
-
-
TestLanguageNames (1 tests)
-
test_common_languages_present— Test that common languages are present.
-
-
TestSSRFProtection (6 tests)
-
test_safe_public_urls— Test that public URLs are allowed. -
test_blocks_localhost— Test that localhost URLs are blocked. -
test_blocks_private_ips— Test that private IP ranges are blocked. -
test_blocks_cloud_metadata— Test that cloud metadata URLs are blocked. -
test_blocks_non_http_schemes— Test that non-HTTP schemes are blocked. -
test_blocks_empty_or_invalid— Test that empty or invalid URLs are blocked.
-
-
TestTextToSpeechTool (4 tests)
-
test_execute_success— Test successful TTS execution. -
test_execute_validation_error— Test TTS execution with validation error. -
test_execute_runtime_error— Test TTS execution with runtime error. -
test_execute_with_all_options— Test TTS execution with all options and parameter validation.
-
-
TestGenerateSpeech (7 tests)
-
test_empty_text_raises_error— Test that empty text raises ValueError. -
test_whitespace_text_raises_error— Test that whitespace-only text raises ValueError. -
test_text_too_long_raises_error— Test that text over 5000 chars raises ValueError. -
test_invalid_model_raises_error— Test that invalid model raises ValueError. -
test_invalid_language_for_model_raises_error— Test that invalid language for model raises ValueError. -
test_ssrf_url_raises_error— Test that SSRF URLs are rejected. -
test_localhost_url_raises_error— Test that localhost URLs are rejected.
-
-
TestToolsRoute (7 tests)
-
test_list_tools— Test listing all tools. -
test_get_definitions— Test getting tool definitions. -
test_get_tool_info_exists— Test getting info for existing tool. -
test_get_tool_info_not_exists— Test getting info for non-existent tool. -
test_execute_tool_success— Test executing a tool successfully with auth. -
test_execute_tool_not_found— Test executing a non-existent tool. -
test_execute_tool_validation_error— Test executing a tool with validation error.
-
-
TestToolIntegration (1 tests)
-
test_all_tools_have_valid_definitions— Test that all registered tools have valid definitions.
-
-
TestSearchAugmentRoute (9 tests)
-
test_search_augment_success— Test successful search augmentation. -
test_search_augment_with_parameters— Test search augmentation passes correct parameters. -
test_search_augment_no_results— Test search augmentation with no results. -
test_search_augment_tool_failure— Test search augmentation when tool execution fails. -
test_search_augment_validation_empty_query— Test search augmentation with empty query. -
test_search_augment_validation_invalid_max_results— Test search augmentation with invalid max_results. -
test_search_augment_truncates_long_content— Test that search augmentation truncates long content. -
test_search_augment_multiple_results— Test search augmentation formats multiple results correctly. -
test_search_augment_exception_handling— Test search augmentation handles exceptions gracefully.
-
34 tests
-
TestTrialServiceInit (3 tests)
-
test_init_success— Test successful initialization -
test_init_missing_url— Test initialization fails without SUPABASE_URL -
test_init_missing_key— Test initialization fails without SUPABASE_KEY
-
-
TestStartTrial (5 tests)
-
test_start_trial_success— Test successful trial start -
test_start_trial_api_key_not_found— Test trial start with invalid API key -
test_start_trial_already_started— Test trial start when trial already active -
test_start_trial_database_error— Test trial start with database error -
test_start_trial_exception— Test trial start with exception
-
-
TestGetTrialStatus (4 tests)
-
test_get_trial_status_success— Test successful trial status retrieval -
test_get_trial_status_api_key_not_found— Test trial status with invalid API key -
test_get_trial_status_database_error— Test trial status with database error -
test_get_trial_status_exception— Test trial status with exception in _get_api_key_id
-
-
TestConvertTrial (4 tests)
-
test_convert_trial_success— Test successful trial conversion -
test_convert_trial_api_key_not_found— Test conversion with invalid API key -
test_convert_trial_database_error— Test conversion with database error -
test_convert_trial_exception— Test conversion with exception in _get_api_key_id
-
-
TestTrackTrialUsage (3 tests)
-
test_track_usage_success— Test successful usage tracking -
test_track_usage_api_key_not_found— Test usage tracking with invalid API key -
test_track_usage_exception— Test usage tracking with exception
-
-
TestGetSubscriptionPlans (3 tests)
-
test_get_plans_success— Test successful plans retrieval -
test_get_plans_empty— Test plans retrieval with no plans -
test_get_plans_exception— Test plans retrieval with exception
-
-
TestValidateTrialAccess (8 tests)
-
test_validate_access_success— Test successful access validation -
test_validate_access_status_check_failed— Test validation when status check fails -
test_validate_access_not_trial— Test validation for non-trial account -
test_validate_access_expired— Test validation for expired trial -
test_validate_access_insufficient_tokens— Test validation with insufficient tokens -
test_validate_access_insufficient_requests— Test validation with insufficient requests -
test_validate_access_insufficient_credits— Test validation with insufficient credits -
test_validate_access_exception— Test validation with exception
-
-
TestHelperMethods (3 tests)
-
test_get_api_key_id_success— Test successful API key ID retrieval -
test_get_api_key_id_not_found— Test API key ID not found -
test_get_api_key_id_exception— Test API key ID with exception
-
-
TestGlobalServiceInstance (1 tests)
-
test_get_trial_service_singleton— Test that get_trial_service returns singleton
-
10 tests
-
TestUserLookupCache (10 tests)
-
test_cache_get_user_first_call_hits_database— First call to get_user should hit the database -
test_cache_get_user_second_call_uses_cache— Second call with same API key should use cache (not hit database) -
test_cache_get_user_different_keys_separate_cache_entries— Different API keys should have separate cache entries -
test_cache_returns_none_when_user_not_found— Cache should handle None returns from database (None is NOT cached) -
test_clear_cache_all— clear_cache() with no arguments should clear entire cache -
test_clear_cache_specific_key— clear_cache(api_key) should clear only that key -
test_invalidate_user— invalidate_user should clear cache for specific user -
test_get_cache_stats— get_cache_stats should return cache statistics -
test_set_cache_ttl— set_cache_ttl should update cache TTL -
test_cache_statistics_empty— get_cache_stats should work on empty cache
-
18 tests
-
TestWebSearchToolDefinition (4 tests)
-
test_tool_registered— Test that web_search tool is registered. -
test_get_definition— Test tool definition format. -
test_search_depth_enum— Test that search_depth has correct enum values. -
test_max_results_bounds— Test that max_results has correct bounds.
-
-
TestWebSearchToolExecution (11 tests)
-
test_execute_success— Test successful search execution. -
test_execute_without_query— Test execution without query parameter. -
test_execute_with_empty_query— Test execution with empty query. -
test_execute_without_api_key— Test execution without API key configured. -
test_execute_with_invalid_api_key— Test execution with invalid API key. -
test_execute_rate_limit— Test execution with rate limit error. -
test_execute_timeout— Test execution timeout handling. -
test_execute_connection_error— Test execution connection error handling. -
test_execute_with_all_options— Test execution with all optional parameters. -
test_execute_max_results_clamped— Test that max_results is clamped to valid range. -
test_execute_no_results— Test execution with no search results.
-
-
TestWebSearchToolIntegration (3 tests)
-
test_get_tool_by_name— Test getting WebSearchTool by name. -
test_execute_via_registry— Test executing web_search via execute_tool function. -
test_tool_definition_in_all_definitions— Test that web_search is included in get_tool_definitions.
-
13 tests
-
TestXaiReasoningDetection (4 tests)
-
test_is_reasoning_model_grok_4— Test that Grok 4 models are detected as reasoning models -
test_is_reasoning_model_grok_3_mini— Test that Grok 3 mini models are detected as reasoning models -
test_non_reasoning_models— Test that non-reasoning models are correctly identified -
test_case_insensitivity— Test that model detection is case-insensitive
-
-
TestXaiReasoningParams (5 tests)
-
test_reasoning_params_for_reasoning_model— Test reasoning params are generated for reasoning models -
test_reasoning_params_for_non_reasoning_model— Test no reasoning params for non-reasoning models -
test_explicit_enable_reasoning— Test explicitly enabling reasoning -
test_explicit_disable_reasoning— Test explicitly disabling reasoning -
test_explicit_enable_on_non_reasoning_model— Test that explicit enable on non-reasoning model returns empty
-
-
TestXaiRequestWithReasoning (4 tests)
-
test_make_request_adds_reasoning_params— Test that reasoning params are added to requests for reasoning models -
test_make_request_no_reasoning_for_old_models— Test that reasoning params are NOT added for non-reasoning models -
test_make_stream_request_adds_reasoning_params— Test that streaming requests also get reasoning params -
test_explicit_reasoning_override— Test that explicit enable_reasoning parameter works
-
1 files, 20 tests
20 tests
-
TestApplicationHealth (3 tests)
-
test_app_is_running— Test that the application responds -
test_health_endpoint_structure— Test health endpoint returns proper structure -
test_root_endpoint_responds— Test root endpoint responds
-
-
TestCriticalEndpointsExist (5 tests)
-
test_chat_completions_endpoint_exists— Test /v1/chat/completions endpoint exists -
test_messages_endpoint_exists— Test /v1/messages endpoint exists (Anthropic/Claude API) -
test_images_endpoint_exists— Test /v1/images/generations endpoint exists -
test_catalog_models_endpoint_exists— Test /catalog/models endpoint exists -
test_catalog_providers_endpoint_exists— Test /catalog/providers endpoint exists
-
-
TestAuthenticationSystem (2 tests)
-
test_endpoints_require_authentication— Test that protected endpoints reject unauthenticated requests -
test_invalid_api_key_rejected— Test that invalid API keys are rejected
-
-
TestAuthenticatedRequests (2 tests)
-
test_can_check_user_balance— Test that authenticated user can check balance -
test_can_make_chat_completion_request— Test that authenticated user can make chat completion request
-
-
TestDatabaseConnectivity (1 tests)
-
test_database_connection_via_health— Test database connection through health endpoint
-
-
TestExternalServices (1 tests)
-
test_can_reach_openrouter— Test that OpenRouter is reachable (if configured)
-
-
TestResponseTimes (2 tests)
-
test_health_check_responds_quickly— Test health check responds within acceptable time -
test_catalog_endpoints_respond_quickly— Test catalog endpoints respond within acceptable time
-
-
TestErrorHandling (3 tests)
-
test_invalid_endpoint_returns_404— Test that invalid endpoints return 404 -
test_malformed_json_returns_400— Test that malformed JSON returns 400 -
test_missing_required_fields_returns_422— Test that missing required fields returns validation error
-
-
TestCORSConfiguration (1 tests)
-
test_cors_headers_present— Test that CORS headers are present in responses
-
1 files, 17 tests
17 tests
-
TestQueryTimeout (4 tests)
-
test_execute_with_timeout_success— Test successful execution within timeout. -
test_execute_with_timeout_exceeds_limit— Test that operation exceeding timeout raises error. -
test_safe_query_with_timeout_fallback— Test that fallback value is returned on timeout. -
test_safe_query_with_timeout_exception_fallback— Test that fallback value is returned on exception.
-
-
TestAuthCache (6 tests)
-
test_cache_user_by_privy_id— Test caching user by Privy ID. -
test_get_cached_user_by_privy_id_hit— Test retrieving cached user by Privy ID (cache hit). -
test_get_cached_user_by_privy_id_miss— Test retrieving cached user by Privy ID (cache miss). -
test_cache_user_by_username— Test caching user by username. -
test_invalidate_user_cache— Test invalidating cached user data. -
test_cache_redis_unavailable— Test cache operations when Redis is unavailable.
-
-
TestConnectionPoolMonitor (5 tests)
-
test_connection_pool_stats_initialization— Test ConnectionPoolStats initialization. -
test_connection_pool_stats_to_dict— Test ConnectionPoolStats to_dict conversion. -
test_connection_pool_stats_is_healthy— Test pool health check. -
test_connection_pool_stats_health_status— Test pool health status strings. -
test_get_supabase_pool_stats_unavailable— Test getting pool stats when unavailable.
-
-
TestTimeoutConstants (2 tests)
-
test_timeout_constants_exist— Test that timeout constants are defined. -
test_timeout_values_reasonable— Test that timeout values are in reasonable range.
-
1 files, 19 tests
19 tests
-
TestBotFilterSpanProcessorDrops (11 tests)
test_drop_scanner_route_envtest_drop_scanner_route_gittest_drop_scanner_route_wp_logintest_drop_scanner_route_actuatortest_drop_scanner_route_phpmyadmintest_drop_bot_user_agent_sqlmaptest_drop_bot_user_agent_nucleitest_drop_bot_user_agent_zgrabtest_drop_unauth_401_floodtest_drop_unauth_403_floodtest_drop_unauth_429_spam
-
TestBotFilterSpanProcessorAllows (6 tests)
test_allow_legit_chat_completionstest_allow_authenticated_429test_allow_authenticated_401test_allow_health_checktest_allow_models_endpointtest_allow_span_with_no_attributes
-
TestBotFilterSpanProcessorCounter (2 tests)
test_dropped_count_increments_on_droptest_dropped_count_unchanged_for_legit_span
1 files, 21 tests
21 tests
-
test_alert_creation— Test Alert dataclass creation -
test_alert_type_enum— Test AlertType enum values -
test_alert_severity_enum— Test AlertSeverity enum values -
test_alert_channel_enum— Test AlertChannel enum values -
test_alerting_service_initialization— Test alerting service initializes correctly -
test_should_send_alert_first_time— Test alert should be sent on first occurrence -
test_should_send_alert_cooldown— Test alert is suppressed during cooldown period -
test_should_send_alert_after_cooldown— Test alert is sent after cooldown period expires -
test_record_alert— Test recording alert in history -
test_record_alert_cleanup_old— Test old alerts are cleaned up from history -
test_get_severity_color— Test severity color mapping for HTML -
test_get_severity_color_slack— Test severity color mapping for Slack -
test_get_severity_color_discord— Test severity color mapping for Discord -
test_format_metrics_html— Test metrics formatting for HTML -
test_format_metrics_html_empty— Test metrics formatting with no metrics -
test_send_email_alert— Test sending email alert -
test_alert_provider_down— Test convenience method for provider down alert -
test_alert_critical_model_down— Test convenience method for critical model down alert -
test_alert_high_error_rate— Test convenience method for high error rate alert -
test_alert_slow_response— Test convenience method for slow response alert -
test_send_alert_with_deduplication— Test sending alert respects de-duplication
1 files, 3 tests
3 tests
-
TestJWTIdTokenFallback (3 tests)
-
test_id_token_fallback_scenario— Test the exact scenario from the bug report -
test_comparison_before_and_after_fix— Document the behavior change from the fix -
test_fallback_order— Test that access_token is preferred over id_token
-
1 files, 34 tests
34 tests
-
test_app— Create a test FastAPI app with observability middleware. -
TestPathNormalization (8 tests)
-
test_simple_path_unchanged— Simple paths should remain unchanged. -
test_root_path— Root path should return /. -
test_numeric_id_replaced— Numeric IDs should be replaced with {id}. -
test_uuid_replaced— UUIDs should be replaced with {id}. -
test_hex_string_replaced— Hex strings should be replaced with {id}. -
test_model_name_preserved— Model names with hyphens should be preserved. -
test_deep_path_limited— Deep paths should be limited to first 6 segments. -
test_mixed_path_normalization— Mixed paths should normalize ids but keep structure.
-
-
TestHTTPMetrics (5 tests)
-
test_successful_request_tracked— Successful requests should be tracked in metrics. -
test_different_methods_tracked_separately— Different HTTP methods should be tracked separately. -
test_status_code_tracked— Status codes should be tracked in metrics. -
test_error_status_tracked— Error status codes should be tracked. -
test_endpoint_label— Endpoints should be labeled with normalized paths.
-
-
TestInProgressGauge (3 tests)
-
test_in_progress_incremented— In-progress requests should be incremented. -
test_in_progress_decremented_on_success— In-progress gauge should be decremented after request succeeds. -
test_in_progress_decremented_on_error— In-progress gauge should be decremented even on error.
-
-
TestRequestResponseSize (4 tests)
-
test_request_size_tracked— Request body size should be tracked. -
test_response_size_tracked— Response body size should be tracked. -
test_size_histogram_buckets— Size metrics should use appropriate histogram buckets. -
test_zero_size_for_get— GET requests without body should record small size.
-
-
TestDurationTracking (2 tests)
-
test_duration_histogram_present— Duration should be recorded in histogram. -
test_duration_buckets— Duration histogram should have proper buckets.
-
-
TestIntegration (4 tests)
-
test_multiple_requests_tracked— Multiple requests should all be tracked. -
test_metrics_endpoint_itself_tracked— The /metrics endpoint requests should be tracked. -
test_different_endpoints_separate_labels— Different endpoints should have separate label combinations. -
test_error_handling_doesnt_crash_middleware— Errors in handlers shouldn't crash the middleware.
-
-
TestEdgeCases (5 tests)
-
test_empty_path_normalized— Empty path should be normalized to /. -
test_trailing_slash_preserved— Paths with trailing slashes should be handled. -
test_query_parameters_excluded— Query parameters should not affect endpoint label. -
test_double_slash_normalized— Double slashes should be handled gracefully. -
test_special_characters_in_path— Paths with special characters should be handled.
-
-
TestPerformance (2 tests)
-
test_middleware_doesnt_block_response— Middleware shouldn't block responses. -
test_many_unique_endpoints_manageable— Many unique endpoints shouldn't cause issues.
-
1 files, 23 tests
23 tests
-
TestMetricsEndpoint (9 tests)
-
test_metrics_endpoint_exists— Test that /metrics endpoint is accessible. -
test_metrics_content_type— Test that /metrics returns Prometheus text format. -
test_metrics_format_validity— Test that /metrics returns valid Prometheus format. -
test_metrics_contains_http_metrics— Test that HTTP metrics are present. -
test_metrics_contains_model_metrics— Test that model inference metrics are present. -
test_metrics_contains_cache_metrics— Test that cache metrics are present. -
test_metrics_contains_rate_limit_metrics— Test that rate limiting metrics are present. -
test_metrics_contains_provider_metrics— Test that provider health metrics are present. -
test_metrics_contains_database_metrics— Test that database metrics are present.
-
-
TestMetricsRecording (7 tests)
-
test_record_http_response— Test recording HTTP response metrics. -
test_record_tokens_used— Test recording token usage metrics. -
test_record_credits_used— Test recording credit usage metrics. -
test_record_cache_operations— Test recording cache hit/miss metrics. -
test_set_provider_availability— Test setting provider availability metrics. -
test_set_provider_error_rate— Test setting provider error rate metrics. -
test_record_free_model_usage— Test recording free model usage metrics.
-
-
TestFreeModelMetrics (2 tests)
-
test_free_model_usage_metric_exists— Test that free_model_usage_total metric exists in metrics output. -
test_free_model_usage_labels— Test that free model usage has correct labels.
-
-
TestContextManagers (3 tests)
-
test_track_http_request_context— Test HTTP request tracking context manager. -
test_track_model_inference_context— Test model inference tracking context manager. -
test_track_database_query_context— Test database query tracking context manager.
-
-
TestMetricsIntegration (2 tests)
-
test_metrics_after_health_check— Test that metrics are recorded after health check request. -
test_metrics_cardinality— Test that metric cardinality is reasonable.
-
1 files, 19 tests
19 tests
-
test_get_overall_status— Test GET /v1/status/ endpoint -
test_get_providers_status— Test GET /v1/status/providers endpoint -
test_get_models_status— Test GET /v1/status/models endpoint -
test_get_models_status_with_filters— Test GET /v1/status/models with filters -
test_get_model_status— Test GET /v1/status/models/{provider}/{model_id} endpoint -
test_get_model_status_not_found— Test GET /v1/status/models/{provider}/{model_id} when model doesn't exist -
test_get_incidents— Test GET /v1/status/incidents endpoint -
test_get_incidents_with_filters— Test GET /v1/status/incidents with filters -
test_search_models— Test GET /v1/status/search endpoint -
test_search_models_requires_query— Test GET /v1/status/search requires query parameter -
test_get_stats— Test GET /v1/status/stats endpoint -
test_format_duration_seconds— Test duration formatting helper -
test_get_uptime_history— Test GET /v1/status/uptime/{provider}/{model_id} endpoint -
test_get_uptime_history_invalid_period— Test GET /v1/status/uptime with invalid period -
test_healthy_models_never_exceeds_total— Test that healthy_models is constrained to never exceed total_models. -
test_gateway_health_metrics_calculated— Test that gateway health metrics are properly calculated. -
test_empty_providers_returns_zero_gateways— Test that empty provider data returns zero gateway metrics. -
test_no_healthy_models_shows_zero_uptime— Test that when all models are unhealthy, uptime shows 0%. -
test_providers_endpoint_caps_healthy_models— Test that the /providers endpoint also applies the data consistency check.
1 files, 17 tests
17 tests
-
TestModelIdMappingsTopLevel (4 tests)
test_mappings_is_dicttest_mappings_is_non_emptytest_expected_provider_counttest_all_known_providers_present
-
TestPerProviderMappingType (1 tests)
test_provider_mapping_is_dict
-
TestMappingKeyValueTypes (2 tests)
test_all_keys_are_non_empty_stringstest_all_values_are_non_empty_strings
-
TestNoSelfMappings (1 tests)
-
test_no_self_mapping_entries— For providers that only do real transformations, every entry must
-
-
TestGetModelIdMapping (9 tests)
test_returns_dict_for_known_providertest_returns_non_empty_dict_for_fireworkstest_returns_non_empty_dict_for_openroutertest_returns_non_empty_dict_for_google_vertextest_returns_non_empty_dict_for_cloudflaretest_returns_empty_dict_for_unknown_providertest_return_value_matches_direct_lookuptest_result_keys_are_stringstest_result_values_are_strings
16 files, 244 tests
11 tests
-
TestGetApiKeyIdWithRetry (7 tests)
-
test_returns_none_for_empty_key— Test that empty API key returns None. -
test_returns_none_for_special_keys— Test that special keys like local-dev-bypass-key return None. -
test_returns_api_key_id_on_success— Test successful API key lookup. -
test_returns_none_when_key_not_found— Test that None is returned when key is not found. -
test_returns_none_when_record_missing_id— Test that None is returned when record exists but has no id. -
test_retries_on_transient_error— Test that function retries on transient errors. -
test_returns_none_after_max_retries_exhausted— Test that None is returned after all retries are exhausted.
-
-
TestMaskApiKeyForLogging (4 tests)
-
test_returns_none_string_for_none— Test that None input returns 'None' string. -
test_returns_none_string_for_empty— Test that empty string returns 'None' string. -
test_returns_stars_for_short_key— Test that short keys are fully masked. -
test_masks_long_key_properly— Test that long keys show first and last 4 chars.
-
29 tests
-
TestAutoCaptureSentryDecorator (6 tests)
-
test_async_function_capture— Test decorator captures errors from async functions -
test_sync_function_capture— Test decorator captures errors from sync functions -
test_decorator_when_sentry_unavailable— Test decorator works when Sentry is unavailable -
test_explicit_context_type— Test explicit context type in decorator -
test_reraise_false— Test decorator with reraise=False -
test_database_context_detection— Test automatic database context detection
-
-
TestContextDetection (6 tests)
-
test_detect_provider_context— Test provider context detection -
test_detect_database_context— Test database context detection -
test_detect_payment_context— Test payment context detection -
test_detect_auth_context— Test auth context detection -
test_detect_cache_context— Test cache context detection -
test_detect_general_context— Test fallback to general context
-
-
TestContextExtraction (6 tests)
-
test_extract_provider_context— Test provider context extraction -
test_extract_provider_from_module— Test provider extraction from module name -
test_extract_database_context— Test database context extraction -
test_extract_payment_context— Test payment context extraction -
test_extract_auth_context— Test auth context extraction -
test_extract_cache_context— Test cache context extraction
-
-
TestOperationInference (4 tests)
-
test_infer_db_operation— Test database operation inference -
test_infer_payment_operation— Test payment operation inference -
test_infer_auth_operation— Test auth operation inference -
test_infer_cache_operation— Test cache operation inference
-
-
TestSensitiveDataDetection (2 tests)
-
test_contains_sensitive_data_true— Test detection of sensitive data -
test_contains_sensitive_data_false— Test safe data is not flagged
-
-
TestAutoCaptureSentryIntegration (5 tests)
-
test_provider_error_capture_full_flow— Test full flow of provider error capture -
test_database_error_capture_full_flow— Test full flow of database error capture -
test_payment_error_capture_full_flow— Test full flow of payment error capture -
test_successful_execution_no_capture— Test that successful execution doesn't trigger capture -
test_fallback_to_generic_capture— Test fallback to generic capture for unknown context
-
2 tests
-
TestBraintrustTracing (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module has expected public API
-
2 tests
-
TestCrypto (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module has expected public API
-
47 tests
-
TestSafeGetFirst (8 tests)
-
test_safe_get_first_success— Test successful extraction of first item. -
test_safe_get_first_with_key_validation— Test extraction with key validation. -
test_safe_get_first_empty_data— Test error when data is empty. -
test_safe_get_first_none_data— Test error when data is None. -
test_safe_get_first_missing_key— Test error when required key is missing. -
test_safe_get_first_invalid_result_object— Test error when result object doesn't have data attribute. -
test_safe_get_first_non_dict_item— Test error when item is not a dictionary. -
test_safe_get_first_custom_error_message— Test custom error message.
-
-
TestSafeGetValue (8 tests)
-
test_safe_get_value_existing_key— Test getting existing key. -
test_safe_get_value_missing_key_with_default— Test getting missing key returns default. -
test_safe_get_value_none_value_allowed— Test None value when allowed. -
test_safe_get_value_none_value_not_allowed— Test None value uses default when not allowed. -
test_safe_get_value_type_validation_success— Test type validation with correct type. -
test_safe_get_value_type_conversion— Test automatic type conversion. -
test_safe_get_value_type_conversion_float— Test float conversion. -
test_safe_get_value_type_conversion_failure— Test type conversion failure raises TypeError.
-
-
TestSafeExecuteQuery (3 tests)
-
test_safe_execute_query_success— Test successful query execution. -
test_safe_execute_query_with_error_raise— Test error with raise_on_error=True. -
test_safe_execute_query_with_error_fallback— Test error with fallback value.
-
-
TestSafeGetList (4 tests)
-
test_safe_get_list_success— Test successful list extraction. -
test_safe_get_list_min_items— Test minimum items validation. -
test_safe_get_list_max_items— Test maximum items validation. -
test_safe_get_list_empty_allowed— Test empty list allowed with min_items=0.
-
-
TestSafeUpdateCredits (9 tests)
-
test_safe_update_credits_add— Test adding credits. -
test_safe_update_credits_subtract— Test subtracting credits. -
test_safe_update_credits_string_conversion— Test automatic string to float conversion. -
test_safe_update_credits_insufficient_balance— Test error when balance would go negative. -
test_safe_update_credits_custom_minimum— Test custom minimum balance. -
test_safe_update_credits_invalid_current— Test error with invalid current credits. -
test_safe_update_credits_invalid_delta— Test error with invalid delta. -
test_safe_update_credits_floating_point_precision— Test floating point precision handling. -
test_safe_update_credits_none_current— Test None current credits defaults to 0.
-
-
TestValidateDictStructure (5 tests)
-
test_validate_dict_structure_success— Test successful validation. -
test_validate_dict_structure_all_keys— Test validation with all required keys. -
test_validate_dict_structure_missing_keys— Test error with missing keys. -
test_validate_dict_structure_not_dict— Test error when data is not a dict. -
test_validate_dict_structure_none_data— Test error when data is None.
-
-
TestSafeIntConvert (5 tests)
-
test_safe_int_convert_string— Test converting string to int. -
test_safe_int_convert_float— Test converting float to int. -
test_safe_int_convert_none— Test None returns default. -
test_safe_int_convert_invalid— Test invalid value returns default. -
test_safe_int_convert_custom_default— Test custom default value.
-
-
TestSafeFloatConvert (5 tests)
-
test_safe_float_convert_string— Test converting string to float. -
test_safe_float_convert_int— Test converting int to float. -
test_safe_float_convert_none— Test None returns default. -
test_safe_float_convert_invalid— Test invalid value returns default. -
test_safe_float_convert_custom_default— Test custom default value.
-
2 tests
-
TestDependencyUtils (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module has expected public API
-
25 tests
-
TestValidateModelName (10 tests)
-
test_valid_clean_name— Test that clean model names are validated as valid. -
test_valid_with_numbers— Test that names with numbers are valid. -
test_valid_with_hyphens— Test that names with hyphens are valid. -
test_invalid_with_colon— Test that names with colons are invalid. -
test_invalid_with_parentheses_size— Test that names with size in parentheses are invalid. -
test_invalid_with_parentheses_type— Test that names with type in parentheses are invalid. -
test_invalid_with_free_marker— Test that names with (free) marker are invalid. -
test_invalid_empty_name— Test that empty names are invalid. -
test_invalid_whitespace_only— Test that whitespace-only names are invalid. -
test_invalid_too_long— Test that names over 100 characters are invalid.
-
-
TestCleanModelName (8 tests)
-
test_remove_company_prefix_with_colon— Test that company prefix with colon is removed. -
test_remove_parentheses_at_end— Test that parenthetical info at end is removed. -
test_remove_parentheses_in_middle— Test that parenthetical info in middle is removed with proper spacing. -
test_remove_both_colon_and_parentheses— Test that both colon and parentheses are removed. -
test_clean_already_clean_name— Test that already clean names are unchanged. -
test_normalize_whitespace— Test that whitespace is normalized. -
test_truncate_long_name— Test that names over 100 characters are truncated. -
test_empty_name— Test that empty names return empty string.
-
-
TestValidateAndCleanModelName (5 tests)
-
test_valid_name_unchanged— Test that valid names are returned unchanged. -
test_malformed_name_auto_cleaned— Test that malformed names are automatically cleaned. -
test_malformed_name_with_parentheses_auto_cleaned— Test that names with parentheses are automatically cleaned. -
test_malformed_name_no_auto_clean_raises_error— Test that malformed names raise error when auto_clean=False. -
test_valid_name_no_auto_clean— Test that valid names work with auto_clean=False.
-
-
TestRealWorldExamples (2 tests)
-
test_clean_real_world_examples— Test cleaning of real-world malformed model names. -
test_validate_clean_names— Test that clean names from production are validated as valid.
-
2 tests
-
TestPerformanceTracker (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module has expected public API
-
7 tests
-
TestGetRateLimitHeaders (7 tests)
test_returns_empty_dict_for_nonetest_returns_ietf_headerstest_returns_legacy_headers-
test_reset_is_delta_not_timestamp— RateLimit-Reset must be seconds-until-reset per IETF draft, not a Unix ts. -
test_legacy_reset_is_unix_timestamp— X-RateLimit-Reset-Requests should be a Unix timestamp (absolute). test_burst_window_included-
test_skips_zero_limits— Headers with 0 limits should not be emitted.
2 tests
-
TestResetWelcomeEmails (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module has expected public API
-
16 tests
-
TestResilientSpanProcessor (15 tests)
-
test_initialization— Test that processor initializes with correct state. -
test_successful_flush— Test that successful flushes work normally. -
test_single_connection_error_does_not_open_circuit— Test that a single connection error is logged but circuit stays closed. -
test_multiple_failures_open_circuit— Test that circuit opens after threshold failures. -
test_circuit_open_blocks_requests_during_cooldown— Test that open circuit blocks requests during cooldown period. -
test_circuit_attempts_recovery_after_cooldown— Test that circuit attempts recovery after cooldown period. -
test_circuit_closes_after_successful_recoveries— Test that circuit closes after SUCCESS_THRESHOLD successful flushes. -
test_timeout_error_handled_gracefully— Test that timeout errors are handled like connection errors. -
test_os_error_handled_gracefully— Test that OSError (connection reset) is handled gracefully. -
test_unexpected_error_logged_but_not_crash— Test that unexpected errors are logged but don't crash. -
test_on_start_error_does_not_crash— Test that errors in on_start are silently ignored. -
test_on_end_error_does_not_crash— Test that errors in on_end are silently ignored. -
test_shutdown_logs_statistics— Test that shutdown logs export statistics. -
test_success_resets_failure_count— Test that a successful flush resets the failure count. -
test_failure_resets_success_count— Test that a failure resets the success count.
-
-
TestResilientSpanProcessorThreadSafety (1 tests)
-
test_concurrent_flushes_are_thread_safe— Test that concurrent force_flush calls don't cause race conditions.
-
27 tests
-
TestWithRetry (13 tests)
-
test_successful_function_no_retry_needed— Test that successful function executes without retries -
test_retries_on_retryable_connection_error— Test that function retries on connection errors -
test_respects_max_attempts— Test that function fails after max_attempts -
test_exponential_backoff_calculation— Test that delay increases exponentially -
test_max_delay_cap— Test that delay is capped at max_delay -
test_non_retryable_error_raises_immediately— Test that non-retryable errors are not retried -
test_retryable_error_keywords— Test that errors with retryable keywords are retried -
test_case_insensitive_error_matching— Test that error matching is case insensitive -
test_specific_exception_types— Test retry only on specific exception types -
test_preserves_function_metadata— Test that decorator preserves function metadata -
test_logging_on_retry— Test that retry attempts are logged -
test_logging_on_max_attempts_reached— Test that max attempts failure is logged -
test_logging_non_retryable_error— Test that non-retryable errors are logged
-
-
TestWithAsyncRetry (10 tests)
-
test_successful_async_function_no_retry— Test that successful async function executes without retries -
test_async_retries_on_connection_error— Test that async function retries on connection errors -
test_async_respects_max_attempts— Test that async function fails after max_attempts -
test_async_exponential_backoff— Test that async delay increases exponentially -
test_async_max_delay_cap— Test that async delay is capped at max_delay -
test_async_non_retryable_error_raises_immediately— Test that async non-retryable errors are not retried -
test_async_retryable_error_keywords— Test that async errors with retryable keywords are retried -
test_async_preserves_function_metadata— Test that async decorator preserves function metadata -
test_async_logging_on_retry— Test that async retry attempts are logged -
test_async_specific_exception_types— Test async retry only on specific exception types
-
-
TestRetryIntegration (4 tests)
-
test_sync_retry_with_real_timing— Test sync retry with actual sleep delays (integration test) -
test_async_retry_with_real_timing— Test async retry with actual sleep delays (integration test) -
test_default_parameters— Test retry with default parameters -
test_async_default_parameters— Test async retry with default parameters
-
35 tests
-
TestSetErrorContext (3 tests)
-
test_set_error_context_success— Test setting error context successfully -
test_set_error_context_sentry_unavailable— Test set_error_context when Sentry is unavailable -
test_set_error_context_handles_exception— Test that exceptions are handled gracefully
-
-
TestSetErrorTag (5 tests)
-
test_set_error_tag_with_string— Test setting error tag with string value -
test_set_error_tag_with_int— Test setting error tag with int value -
test_set_error_tag_with_bool— Test setting error tag with bool value -
test_set_error_tag_sentry_unavailable— Test set_error_tag when Sentry is unavailable -
test_set_error_tag_handles_exception— Test that exceptions are handled gracefully
-
-
TestCaptureError (4 tests)
-
test_capture_error_with_full_context— Test capturing error with all context parameters -
test_capture_error_minimal— Test capturing error with minimal parameters -
test_capture_error_sentry_unavailable— Test capture_error when Sentry is unavailable -
test_capture_error_handles_exception— Test that exceptions during capture are handled
-
-
TestWithSentryContextDecorator (7 tests)
-
test_decorator_async_function_success— Test decorator on async function that succeeds -
test_decorator_async_function_with_exception— Test decorator on async function that raises exception -
test_decorator_async_with_context_fn— Test decorator on async function with context function -
test_decorator_sync_function_success— Test decorator on sync function that succeeds -
test_decorator_sync_function_with_exception— Test decorator on sync function that raises exception -
test_decorator_sync_with_context_fn— Test decorator on sync function with context function -
test_decorator_handles_context_fn_exception— Test decorator handles exceptions in context_fn
-
-
TestCaptureProviderError (2 tests)
-
test_capture_provider_error_full_params— Test capturing provider error with all parameters -
test_capture_provider_error_minimal— Test capturing provider error with minimal parameters
-
-
TestCaptureDatabaseError (2 tests)
-
test_capture_database_error_full_params— Test capturing database error with all parameters -
test_capture_database_error_minimal— Test capturing database error with minimal parameters
-
-
TestCapturePaymentError (2 tests)
-
test_capture_payment_error_full_params— Test capturing payment error with all parameters -
test_capture_payment_error_minimal— Test capturing payment error with minimal parameters
-
-
TestCaptureAuthError (2 tests)
-
test_capture_auth_error_full_params— Test capturing auth error with all parameters -
test_capture_auth_error_minimal— Test capturing auth error with minimal parameters
-
-
TestCaptureCacheError (2 tests)
-
test_capture_cache_error_full_params— Test capturing cache error with all parameters -
test_capture_cache_error_minimal— Test capturing cache error with minimal parameters
-
-
TestCaptureModelHealthError (3 tests)
-
test_capture_model_health_error_full_params— Test capturing model health error with all parameters -
test_capture_model_health_error_minimal— Test capturing model health error with minimal parameters -
test_capture_model_health_error_with_zero_response_time— Test capturing model health error with zero response time
-
-
TestSentryAvailability (1 tests)
-
test_sentry_availability_flag— Test that SENTRY_AVAILABLE flag is set correctly
-
-
TestDecoratorPreservesMetadata (2 tests)
-
test_async_decorator_preserves_name_and_docstring— Test async decorator preserves name and doc -
test_sync_decorator_preserves_name_and_docstring— Test sync decorator preserves name and doc
-
21 tests
-
TestDatabaseQueryInsights (4 tests)
-
test_trace_database_query_creates_span— Test that trace_database_query creates a Sentry span with correct attributes. -
test_trace_database_query_sets_required_attributes— Test that db.system attribute is set for Sentry Queries Insights. -
test_trace_supabase_query_convenience_wrapper— Test that trace_supabase_query correctly wraps trace_database_query. -
test_trace_database_query_yields_none_when_sentry_unavailable— Test graceful degradation when Sentry is not available.
-
-
TestCacheInsights (7 tests)
-
test_trace_cache_operation_get_hit— Test cache.get span with cache hit. -
test_trace_cache_operation_get_miss— Test cache.get span with cache miss. -
test_trace_cache_operation_put_with_ttl— Test cache.put span with TTL. -
test_trace_cache_operation_normalizes_op— Test that operation names are normalized to cache.* format. -
test_trace_cache_operation_multiple_keys— Test cache operation with multiple keys. -
test_cache_span_tracker_get— Test CacheSpanTracker.get() with automatic hit detection. -
test_cache_span_tracker_get_miss— Test CacheSpanTracker.get() with cache miss.
-
-
TestQueueMonitoring (5 tests)
-
test_trace_queue_publish_creates_span— Test that trace_queue_publish creates a producer span. -
test_trace_queue_process_creates_span— Test that trace_queue_process creates a consumer span. -
test_trace_queue_process_with_trace_headers— Test that trace_queue_process continues trace from producer. -
test_queue_tracker_publish— Test QueueTracker.publish() convenience method. -
test_queue_tracker_process— Test QueueTracker.process() convenience method.
-
-
TestGracefulDegradation (2 tests)
-
test_all_functions_work_without_sentry— Test that all instrumentation functions work when Sentry is not available. -
test_sentry_not_initialized— Test graceful handling when Sentry SDK is installed but not initialized.
-
-
TestDecorators (3 tests)
-
test_instrument_db_operation_decorator— Test @instrument_db_operation decorator. -
test_instrument_db_operation_async_decorator— Test @instrument_db_operation decorator with async function. -
test_instrument_cache_operation_decorator— Test @instrument_cache_operation decorator.
-
14 tests
-
TestTrialUtils (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module has expected public API
-
-
TestValidateTrialExpiration (12 tests)
-
test_non_trial_user_passes— Test that non-trial users are not affected -
test_trial_user_without_expiry_passes— Test that trial users without expiry date pass -
test_trial_user_with_future_expiry_passes— Test that trial users with future expiry date pass -
test_trial_user_with_past_expiry_raises_402— Test that expired trial users get 402 error -
test_trial_expiry_with_z_suffix— Test handling of ISO format with Z suffix -
test_trial_expiry_with_timezone— Test handling of ISO format with timezone -
test_trial_expiry_as_datetime_object— Test handling of datetime object -
test_trial_expiry_naive_datetime— Test handling of naive datetime (without timezone) -
test_invalid_date_format_logs_warning— Test that invalid date formats are logged and request proceeds -
test_empty_subscription_status— Test handling of empty subscription status -
test_missing_subscription_status— Test handling of missing subscription_status key -
test_edge_case_exactly_at_expiry— Test behavior when current time is exactly at expiry
-
2 tests
-
TestValidators (2 tests)
-
test_module_imports— Test that module imports successfully -
test_module_has_expected_attributes— Test module has expected public API
-
Reading Path (start here, in order)
- Conceptual Model
- Stability Definition
- Conceptual Model Features
- Features
- Delta Report
- Features-Acceptance-Criteria
Testing
Security & Access
Billing
Monitoring
Features
Providers
Operations
Data References