Skip to content

Commit 9bb04c4

Browse files
committed
Merge remote-tracking branch 'origin' into feature/#11
2 parents aaf24b8 + a8bd51b commit 9bb04c4

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

app/routers/news/__init__.py

Whitespace-only changes.

app/routers/news/routes.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from fastapi import APIRouter, status
2+
from pydantic import BaseModel
3+
4+
5+
class NewsPostResponse(BaseModel):
6+
status: str = "News Criada"
7+
8+
9+
def setup():
10+
router = APIRouter(prefix="/news", tags=["news"])
11+
12+
@router.post(
13+
"",
14+
response_model=NewsPostResponse,
15+
status_code=status.HTTP_200_OK,
16+
summary="News endpoint",
17+
description="Creates news and returns a confirmation message",
18+
)
19+
async def news():
20+
"""
21+
News endpoint that creates news and returns a confirmation message.
22+
"""
23+
return NewsPostResponse()
24+
25+
return router

app/routers/router.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from fastapi import APIRouter
22

33
from app.routers.healthcheck.routes import setup as healthcheck_router_setup
4+
from app.routers.news.routes import setup as news_router_setup
45

56

67
def setup_router() -> APIRouter:
78
router = APIRouter()
89
router.include_router(healthcheck_router_setup(), prefix="")
10+
router.include_router(news_router_setup(), prefix="")
911
return router

tests/test_news.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,28 @@ async def test_insert_libraries(session: AsyncSession, community: Community):
5555

5656

5757
# ADD like test case for News model
58+
from typing import Mapping
59+
60+
import pytest
61+
from fastapi import status
62+
from httpx import AsyncClient
63+
64+
65+
@pytest.mark.asyncio
66+
async def test_news_endpoint(
67+
async_client: AsyncClient, mock_headers: Mapping[str, str]
68+
):
69+
"""Test the news endpoint returns correct status and version."""
70+
response = await async_client.post("/api/news", headers=mock_headers)
71+
72+
assert response.status_code == status.HTTP_200_OK
73+
assert response.json() == {"status": "News Criada"}
74+
75+
76+
@pytest.mark.asyncio
77+
async def test_news_endpoint_without_auth(async_client: AsyncClient):
78+
"""Test the news endpoint without authentication headers."""
79+
response = await async_client.post("/api/news")
80+
81+
assert response.status_code == status.HTTP_200_OK
82+
assert response.json() == {"status": "News Criada"}

0 commit comments

Comments
 (0)