Coverage for src / default / default_router.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-03-18 14:29 -0300

1"""Rotas HTTP do modulo padrao da aplicacao.""" 

2 

3from fastapi import APIRouter, HTTPException, status 

4 

5from src.default.schemas import DefaultMessageSchema 

6from src.default.services import ( 

7 get_aviso_not_found_error_detail, 

8 get_internal_error_detail, 

9 get_root_response, 

10 get_tarefa_not_found_error_detail, 

11 get_tarefa_visibility_error_detail, 

12 get_validation_error_detail, 

13) 

14 

15router = APIRouter() 

16 

17 

18@router.get("/", response_model=DefaultMessageSchema) 

19async def read_root() -> DefaultMessageSchema: 

20 """Retorna a mensagem principal da aplicacao.""" 

21 return get_root_response() 

22 

23 

24@router.get("/erro_interno") 

25async def read_erro_interno(): 

26 """Simula um erro interno para testes de tratamento de falhas.""" 

27 error_payload = get_internal_error_detail() 

28 raise HTTPException( 

29 status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, 

30 detail=error_payload.detail, 

31 ) 

32 

33 

34@router.get("/erros/avisos/nao_encontrado") 

35async def read_aviso_not_found_error(): 

36 """Simula erro 404 do modulo de avisos.""" 

37 error_payload = get_aviso_not_found_error_detail() 

38 raise HTTPException( 

39 status_code=status.HTTP_404_NOT_FOUND, 

40 detail=error_payload.detail, 

41 ) 

42 

43 

44@router.get("/erros/tarefas/nao_encontrada") 

45async def read_tarefa_not_found_error(): 

46 """Simula erro 404 do modulo de tarefas.""" 

47 error_payload = get_tarefa_not_found_error_detail() 

48 raise HTTPException( 

49 status_code=status.HTTP_404_NOT_FOUND, 

50 detail=error_payload.detail, 

51 ) 

52 

53 

54@router.get("/erros/tarefas/visibilidade_invalida") 

55async def read_tarefa_visibility_error(): 

56 """Simula erro 422 de regra de negocio do modulo de tarefas.""" 

57 error_payload = get_tarefa_visibility_error_detail() 

58 raise HTTPException( 

59 status_code=status.HTTP_422_UNPROCESSABLE_CONTENT, 

60 detail=error_payload.detail, 

61 ) 

62 

63 

64@router.get("/erros/validacao/payload_invalido") 

65async def read_payload_validation_error(): 

66 """Simula erro 422 de validacao de payload dos modulos.""" 

67 raise HTTPException( 

68 status_code=status.HTTP_422_UNPROCESSABLE_CONTENT, 

69 detail=get_validation_error_detail(), 

70 )