import pytest from pydantic import ValidationError from url_shortener.api.schemas import ShortenRequestBody from url_shortener.config import Settings class TestShortenRequestBody: def test_shorten_request_body_success_with_path(self, settings: Settings) -> None: request_body = ShortenRequestBody( url="test", path="path-test", domain=settings.allowed_domains[0] ) assert request_body.url == "test" assert request_body.path == "path-test" assert request_body.path_prefix is None def test_shorten_request_body_success_with_path_prefix( self, settings: Settings ) -> None: request_body = ShortenRequestBody( url="test", path_prefix="path-prefix-test", domain=settings.allowed_domains[0], ) assert request_body.url == "test" assert request_body.path is None assert request_body.path_prefix == "path-prefix-test" def test_shorten_request_body_path_contains_not_allowed_symbols( self, settings: Settings ) -> None: with pytest.raises(ValueError): ShortenRequestBody( url="test", path="/path-test", domain=settings.allowed_domains[0] ) def test_shorten_request_body_path_prefix_contains_not_allowed_symbols( self, settings: Settings ) -> None: with pytest.raises(ValueError): ShortenRequestBody( url="test", path_prefix="/path-prefix-test", domain=settings.allowed_domains[0], ) def test_shorten_request_body_path_min_length(self, settings: Settings) -> None: with pytest.raises(ValidationError): ShortenRequestBody( url="test", path="test", domain=settings.allowed_domains[0] ) def test_shorten_request_body_path_prefix_min_length( self, settings: Settings ) -> None: with pytest.raises(ValidationError): ShortenRequestBody( url="test", path_prefix="test", domain=settings.allowed_domains[0] )