Reformat files

This commit is contained in:
Santiago Lo Coco 2023-10-25 09:33:05 -03:00
parent d7760eefc9
commit 927d8b39c7
9 changed files with 35 additions and 37 deletions

View File

@ -13,4 +13,4 @@ repos:
rev: 5.12.0 rev: 5.12.0
hooks: hooks:
- id: isort - id: isort
args: ['--src-path', 'flights-domain/flights-information/src', 'auth-domain/user-manager/src'] args: ['--src-path', 'flights-domain/flights-information/src', 'auth-domain/user-manager/src', 'gateway/src']

View File

@ -1,21 +1,22 @@
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
import src.api.cruds.flight
import src.api.cruds.flight
from src.api.main import app from src.api.main import app
client = TestClient(app) client = TestClient(app)
mocked_flight = { mocked_flight = {
"id": 1, "id": 1,
"flight_code": "ABC125", "flight_code": "ABC125",
"status": "En ruta", "status": "En ruta",
"origin": "Ciudad B", "origin": "Ciudad B",
"destination": "Ciudad A", "destination": "Ciudad A",
"departure_time": "2023-10-10 10:00 AM", "departure_time": "2023-10-10 10:00 AM",
"arrival_time": "2023-10-10 12:00 PM", "arrival_time": "2023-10-10 12:00 PM",
"gate": "A2", "gate": "A2",
} }
class AttrDict(dict): class AttrDict(dict):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -23,25 +24,22 @@ class AttrDict(dict):
self.__dict__ = self self.__dict__ = self
def test_not_found_flight(monkeypatch): def test_not_found_flight(monkeypatch):
def mock_get_flight_by_id(db, id):
def mock_get_flight_by_id(db,id): return None
return None
monkeypatch.setattr(src.api.cruds.flight, "get_flight_by_id", mock_get_flight_by_id) monkeypatch.setattr(src.api.cruds.flight, "get_flight_by_id", mock_get_flight_by_id)
resp = client.get("/flights/1") resp = client.get("/flights/1")
assert resp.status_code == 404 assert resp.status_code == 404
def test_successful_get_flight(monkeypatch):
def mock_get_flight_by_id(db,id): def test_successful_get_flight(monkeypatch):
return mocked_flight def mock_get_flight_by_id(db, id):
return mocked_flight
monkeypatch.setattr(src.api.cruds.flight, "get_flight_by_id", mock_get_flight_by_id) monkeypatch.setattr(src.api.cruds.flight, "get_flight_by_id", mock_get_flight_by_id)
response = client.get("/flights/1") response = client.get("/flights/1")
assert response.status_code == 200 assert response.status_code == 200
assert response.json() == mocked_flight assert response.json() == mocked_flight

View File

@ -1,7 +1,7 @@
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from src.api.routes import flights, health, auth, users from src.api.routes import auth, flights, health, users
app = FastAPI(title="Flights Information API") app = FastAPI(title="Flights Information API")
app.include_router(flights.router, prefix="/flights") app.include_router(flights.router, prefix="/flights")

View File

@ -1,11 +1,10 @@
from typing import Optional from typing import Annotated, Optional
from fastapi import APIRouter, Depends, HTTPException, status, Request, Header
from typing import Annotated from fastapi import APIRouter, Depends, Header, HTTPException, Request, status
from src.api.config import API_AUTH from src.api.config import API_AUTH
from src.api.schemas.auth import Token, RefreshToken from src.api.schemas.auth import RefreshToken, Token
from src.api.schemas.user import User, UserLogin, UserRegister, UserMin from src.api.schemas.user import User, UserLogin, UserMin, UserRegister
from src.api.utils.network import make_request, request from src.api.utils.network import make_request, request
router = APIRouter() router = APIRouter()

View File

@ -1,15 +1,13 @@
from typing import Optional
from fastapi import APIRouter, Depends, HTTPException, status, Request, Header
import aiohttp
import asyncio import asyncio
from typing import Annotated from typing import Annotated, Optional
from src.api.routes.auth import status as checkAuth import aiohttp
from fastapi import APIRouter, Depends, Header, HTTPException, Request, status
from src.api.utils.network import make_request, request
from src.api.config import API_FLIGHTS from src.api.config import API_FLIGHTS
from src.api.routes.auth import status as checkAuth
from src.api.schemas.flight import Flight, FlightCreate, FlightStatusUpdate from src.api.schemas.flight import Flight, FlightCreate, FlightStatusUpdate
from src.api.utils.network import make_request, request
router = APIRouter() router = APIRouter()

View File

@ -1,8 +1,8 @@
from typing import Optional from typing import Optional
from fastapi import APIRouter, Depends, HTTPException, status, Request, Header
from fastapi import APIRouter, Depends, Header, HTTPException, Request, status
from src.api.config import API_USERS from src.api.config import API_USERS
from src.api.schemas.user import User, UserLogin, UserRegister from src.api.schemas.user import User, UserLogin, UserRegister
from src.api.utils.network import make_request, request from src.api.utils.network import make_request, request

View File

@ -3,6 +3,7 @@ from typing import Optional
from pydantic import BaseModel, validator from pydantic import BaseModel, validator
class Token(BaseModel): class Token(BaseModel):
access_token: str access_token: str
refresh_token: str refresh_token: str

View File

@ -2,6 +2,7 @@ from datetime import datetime
from pydantic import BaseModel, validator from pydantic import BaseModel, validator
class User(BaseModel): class User(BaseModel):
id: int id: int
username: str username: str

View File

@ -1,7 +1,8 @@
from typing import Optional, Union
import aiohttp import aiohttp
import async_timeout import async_timeout
from typing import Optional, Union from aiohttp import ClientConnectorError, ContentTypeError, JsonPayload
from aiohttp import JsonPayload, ContentTypeError, ClientConnectorError
from fastapi import HTTPException from fastapi import HTTPException