Skip to content

Commit a8bd51b

Browse files
authored
Merge pull request #25 from PythonFloripa/15-criação-endpoint-news---post
Feature/#15
2 parents 909784e + 7974eef commit a8bd51b

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
@@ -0,0 +1,25 @@
1+
from typing import Mapping
2+
3+
import pytest
4+
from fastapi import status
5+
from httpx import AsyncClient
6+
7+
8+
@pytest.mark.asyncio
9+
async def test_news_endpoint(
10+
async_client: AsyncClient, mock_headers: Mapping[str, str]
11+
):
12+
"""Test the news endpoint returns correct status and version."""
13+
response = await async_client.post("/api/news", headers=mock_headers)
14+
15+
assert response.status_code == status.HTTP_200_OK
16+
assert response.json() == {"status": "News Criada"}
17+
18+
19+
@pytest.mark.asyncio
20+
async def test_news_endpoint_without_auth(async_client: AsyncClient):
21+
"""Test the news endpoint without authentication headers."""
22+
response = await async_client.post("/api/news")
23+
24+
assert response.status_code == status.HTTP_200_OK
25+
assert response.json() == {"status": "News Criada"}

0 commit comments

Comments
 (0)