import pytest from pydantic import ValidationError as PydanticValidationError from src.models.list_metrics import ListMetricsRequest class TestListMetricsRequest: def test_match_accepts_series_selector(self): req = ListMetricsRequest.model_validate( { "cluster_id": "123", "env": "prod", "deploy_type": "premium", "match": '{__name__=~"topsql_.*"}', } ) assert req.match == '{__name__=~"topsql_.*"}' def test_match_allows_non_regex_string(self): req = ListMetricsRequest.model_validate( { "cluster_id": "123", "env": "prod", "deploy_type": "premium", "match": "not-a-regex[", } ) assert req.match == "not-a-regex[" def test_limit_bounds(self): with pytest.raises(PydanticValidationError): ListMetricsRequest.model_validate( { "cluster_id": "123", "env": "prod", "deploy_type": "premium", "limit": 0, } ) def test_accepts_start_end(self): req = ListMetricsRequest.model_validate( { "cluster_id": "123", "env": "prod", "deploy_type": "premium", "start": "2024-01-01T00:00:00Z", "end": "2024-01-01T01:00:00Z", } ) assert req.start == "2024-01-01T00:00:00Z" assert req.end == "2024-01-01T01:00:00Z" def test_rejects_invalid_start(self): with pytest.raises(PydanticValidationError): ListMetricsRequest.model_validate( { "cluster_id": "123", "env": "prod", "deploy_type": "premium", "start": "bad-time", } ) with pytest.raises(PydanticValidationError): ListMetricsRequest.model_validate( { "cluster_id": "123", "env": "prod", "deploy_type": "premium", "limit": 501, } )