46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from app.models.homepage import HomepageConfig
|
|
from app.schemas.homepage import HomepageConfigIn
|
|
|
|
|
|
def test_get_homepage_config_returns_200(client, db):
|
|
"""GET /api/v1/homepage-config returns 200 with required fields when config exists."""
|
|
config = HomepageConfig(
|
|
hero_headline="Teste Headline",
|
|
hero_subheadline="Subtítulo de teste",
|
|
hero_cta_label="Ver Imóveis",
|
|
hero_cta_url="/imoveis",
|
|
featured_properties_limit=6,
|
|
)
|
|
db.session.add(config)
|
|
db.session.commit()
|
|
|
|
response = client.get("/api/v1/homepage-config")
|
|
assert response.status_code == 200
|
|
|
|
data = response.get_json()
|
|
assert data["hero_headline"] == "Teste Headline"
|
|
assert data["hero_subheadline"] == "Subtítulo de teste"
|
|
assert data["hero_cta_label"] == "Ver Imóveis"
|
|
assert data["hero_cta_url"] == "/imoveis"
|
|
assert data["featured_properties_limit"] == 6
|
|
|
|
|
|
def test_get_homepage_config_returns_404_when_empty(client, db):
|
|
"""GET /api/v1/homepage-config returns 404 when no config record exists."""
|
|
response = client.get("/api/v1/homepage-config")
|
|
assert response.status_code == 404
|
|
|
|
data = response.get_json()
|
|
assert "error" in data
|
|
|
|
|
|
def test_homepage_config_in_rejects_empty_headline():
|
|
"""HomepageConfigIn raises ValidationError when hero_headline is empty."""
|
|
with pytest.raises(ValidationError) as exc_info:
|
|
HomepageConfigIn(hero_headline="")
|
|
|
|
errors = exc_info.value.errors()
|
|
assert any("hero_headline" in str(e) for e in errors)
|