44import pytest
55import pytest_asyncio
66from fastapi import status
7- from httpx import AsyncClient
7+ from httpx import AsyncClient , Response
88from sqlmodel import select
99from sqlmodel .ext .asyncio .session import AsyncSession
1010
@@ -101,8 +101,8 @@ async def test_post_news_endpoint(
101101 "category" : "test_category" ,
102102 "source_url" : "https://example.com/test-news" ,
103103 }
104- response = await async_client .post (
105- "/api/news" , headers = valid_auth_headers , json = news_data
104+ response : Response = await async_client .post (
105+ url = "/api/news" , headers = valid_auth_headers , json = news_data
106106 )
107107 assert response .status_code == status .HTTP_200_OK
108108 assert response .json () == {"status" : "News Criada" }
@@ -310,26 +310,23 @@ async def test_put_news_endpoint(
310310 "title" : "updated title" ,
311311 "content" : "updated content" ,
312312 "category" : "updated_category" ,
313- "user_email" : "updated_email@test.com" ,
314313 "source_url" : "https://updated_url.com" ,
315314 "tags" : "test_tag_updated" ,
316315 "social_media_url" : "https://updated_social_media_url.com" ,
317316 }
318317
319- response = await async_client .put (
320- "/api/news" ,
321- params = {
322- "id" : stored_news . id ,
318+ response : Response = await async_client .put (
319+ url = f "/api/news/ { stored_news . id } " ,
320+ headers = valid_auth_headers ,
321+ json = {
323322 "title" : data ["title" ],
324323 "content" : data ["content" ],
325324 "category" : data ["category" ],
326- "user_email" : data ["user_email" ],
327325 "source_url" : data ["source_url" ],
328326 "tags" : data ["tags" ],
329327 "social_media_url" : data ["social_media_url" ],
328+ "publish" : True ,
330329 },
331- headers = valid_auth_headers ,
332- json = {"publish" : True },
333330 )
334331 assert response .status_code == status .HTTP_200_OK
335332
@@ -339,7 +336,7 @@ async def test_put_news_endpoint(
339336 assert stored_news is not None
340337 assert stored_news .content == data ["content" ]
341338 assert stored_news .category == data ["category" ]
342- assert stored_news .user_email == data [ "user_email " ]
339+ assert stored_news .user_email == valid_auth_headers [ "user-email " ]
343340 assert stored_news .source_url == data ["source_url" ]
344341 assert stored_news .tags == data ["tags" ]
345342 assert stored_news .social_media_url == data ["social_media_url" ]
@@ -361,8 +358,8 @@ async def test_news_likes_endpoint(
361358 "source_url" : "https://example.com/test-news" ,
362359 "social_media_url" : "https://test.com/test_news" ,
363360 }
364- response = await async_client .post (
365- "/api/news" , json = news_data , headers = valid_auth_headers
361+ response : Response = await async_client .post (
362+ url = "/api/news" , json = news_data , headers = valid_auth_headers
366363 )
367364 assert response .status_code == status .HTTP_200_OK
368365 statement = select (News ).where (News .title == news_data ["title" ])
@@ -374,8 +371,8 @@ async def test_news_likes_endpoint(
374371 emails = ["like@test.com" , "like2@test.com" ]
375372
376373 # Add likes
377- response = await async_client .post (
378- f"/api/news/{ stored_news .id } /like" ,
374+ response : Response = await async_client .post (
375+ url = f"/api/news/{ stored_news .id } /like" ,
379376 json = {"email" : emails [0 ]},
380377 headers = {** valid_auth_headers , "user-email" : emails [0 ]},
381378 )
@@ -387,8 +384,8 @@ async def test_news_likes_endpoint(
387384 assert stored_news .likes == 1
388385 assert stored_news .user_email_list == f"['{ encode_email (emails [0 ])} ']"
389386
390- response = await async_client .post (
391- f"/api/news/{ stored_news .id } /like" ,
387+ response : Response = await async_client .post (
388+ url = f"/api/news/{ stored_news .id } /like" ,
392389 headers = {** valid_auth_headers , "user-email" : emails [1 ]},
393390 )
394391 assert response .status_code == status .HTTP_200_OK
@@ -403,8 +400,8 @@ async def test_news_likes_endpoint(
403400 )
404401
405402 # Remove likes
406- response = await async_client .delete (
407- f"/api/news/{ stored_news .id } /like" ,
403+ response : Response = await async_client .delete (
404+ url = f"/api/news/{ stored_news .id } /like" ,
408405 headers = {** valid_auth_headers , "user-email" : emails [0 ]},
409406 )
410407 assert response .status_code == status .HTTP_200_OK
@@ -415,8 +412,8 @@ async def test_news_likes_endpoint(
415412 assert stored_news .likes == 1
416413 assert stored_news .user_email_list == f"['{ encode_email (emails [1 ])} ']"
417414
418- response = await async_client .delete (
419- f"/api/news/{ stored_news .id } /like" ,
415+ response : Response = await async_client .delete (
416+ url = f"/api/news/{ stored_news .id } /like" ,
420417 headers = {** valid_auth_headers , "user-email" : emails [1 ]},
421418 )
422419 assert response .status_code == status .HTTP_200_OK
0 commit comments