From a5eff3b78e6713ed77f0bff0193effa3ea49aba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Wed, 11 May 2022 19:46:56 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Remove=20un-used=20old=20pending?= =?UTF-8?q?=20tests,=20already=20covered=20in=20other=20places=20(#4891)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pending_tests/main.py | 118 ------------------------------------------ 1 file changed, 118 deletions(-) delete mode 100644 pending_tests/main.py diff --git a/pending_tests/main.py b/pending_tests/main.py deleted file mode 100644 index 5e919f1bc..000000000 --- a/pending_tests/main.py +++ /dev/null @@ -1,118 +0,0 @@ -from fastapi import ( - Body, - Cookie, - Depends, - FastAPI, - File, - Form, - Header, - Path, - Query, - Security, -) -from fastapi.security import ( - HTTPBasic, - OAuth2, - OAuth2PasswordBearer, - OAuth2PasswordRequestForm, -) -from pydantic import BaseModel -from starlette.responses import HTMLResponse, JSONResponse, PlainTextResponse -from starlette.status import HTTP_202_ACCEPTED - -app = FastAPI() - - -@app.get("/security") -def get_security(sec=Security(HTTPBasic())): - return sec - - -reusable_oauth2 = OAuth2( - flows={ - "password": { - "tokenUrl": "token", - "scopes": {"read:user": "Read a User", "write:user": "Create a user"}, - } - } -) - - -@app.get("/security/oauth2") -def get_security_oauth2(sec=Security(reusable_oauth2, scopes=["read:user"])): - return sec - - -@app.post("/token") -def post_token(request_data: OAuth2PasswordRequestForm = Form(...)): - data = request_data.parse() - access_token = data.username + ":" + data.password - return {"access_token": access_token} - - -class Item(BaseModel): - name: str - price: float - is_offer: bool - - -class FakeDB: - def __init__(self): - self.data = { - "johndoe": { - "username": "johndoe", - "password": "shouldbehashed", - "first_name": "John", - "last_name": "Doe", - } - } - - -class DBConnectionManager: - def __init__(self): - self.db = FakeDB() - - def __call__(self): - return self.db - - -connection_manager = DBConnectionManager() - - -class TokenUserData(BaseModel): - username: str - password: str - - -class UserInDB(BaseModel): - username: str - password: str - first_name: str - last_name: str - - -def require_token( - token: str = Security(reusable_oauth2, scopes=["read:user", "write:user"]) -): - raw_token = token.replace("Bearer ", "") - # Never do this plaintext password usage in production - username, password = raw_token.split(":") - return TokenUserData(username=username, password=password) - - -def require_user( - db: FakeDB = Depends(connection_manager), - user_data: TokenUserData = Depends(require_token), -): - return db.data[user_data.username] - - -class UserOut(BaseModel): - username: str - first_name: str - last_name: str - - -@app.get("/dependency", response_model=UserOut) -def get_dependency(user: UserInDB = Depends(require_user)): - return user