File tree Expand file tree Collapse file tree 4 files changed +52
-0
lines changed Expand file tree Collapse file tree 4 files changed +52
-0
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 1
1
from fastapi import APIRouter
2
2
3
3
from app .routers .healthcheck .routes import setup as healthcheck_router_setup
4
+ from app .routers .news .routes import setup as news_router_setup
4
5
5
6
6
7
def setup_router () -> APIRouter :
7
8
router = APIRouter ()
8
9
router .include_router (healthcheck_router_setup (), prefix = "" )
10
+ router .include_router (news_router_setup (), prefix = "" )
9
11
return router
Original file line number Diff line number Diff line change
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" }
You can’t perform that action at this time.
0 commit comments