Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api #15

Open
Erickkkh8 opened this issue Jul 9, 2024 · 1 comment
Open

api #15

Erickkkh8 opened this issue Jul 9, 2024 · 1 comment

Comments

@Erickkkh8
Copy link

Erickkkh8 commented Jul 9, 2024

pip install fastapi uvicorn pymongo motor pytest

#Configuração do MongoDB

from pydantic import BaseModel
from typing import Optional

class Atleta(BaseModel):
nome: str
cpf: str
centro_treinamento: Optional[str] = None
categoria: Optional[str] = None
#Configuração da Aplicação FastAPI

from fastapi import FastAPI
from app.routes import router

app = FastAPI()

app.include_router(router)
#Configuração do Pytest

from fastapi.testclient import TestClient
from app.main import app

client = TestClient(app)

def test_create_atleta():
response = client.post("/atletas", json={
"nome": "João Silva",
"cpf": "12345678901",
"centro_treinamento": "Centro A",
"categoria": "Categoria 1"
})
assert response.status_code == 200
assert response.json() == {
"nome": "João Silva",
"cpf": "12345678901",
"centro_treinamento": "Centro A",
"categoria": "Categoria 1"
}

def test_get_atletas():
response = client.get("/atletas")
assert response.status_code == 200
assert len(response.json()) > 0

@Erickkkh8
Copy link
Author

api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant