async def test_user_with_wrong_creds_doesnt_receive_token( self, app: FastAPI, client: AsyncClient, test_user: UserInDB, credential: str, wrong_value: str, status_code: int, ) -> None: client.headers["content-type"] = "application/x-www-form-urlencoded" user_data = test_user.dict() # insert user's plaintext password user_data["password"] = "******" user_data[credential] = wrong_value login_data = { "username": user_data["email"], # insert password from parameters "password": user_data["password"], } res = await client.post( app.url_path_for("users:login-email-and-password"), data=login_data) assert res.status_code == status_code assert "access_token" not in res.json()
async def create_user(conn: AsyncIOMotorClient, user: UserInCreate) -> UserInDB: dbuser = UserInDB(**user.dict()) dbuser.change_password(user.password) row = await conn[database_name][user_collection_name].insert_one(dbuser.dict()) # dbuser.created_at = ObjectId(dbuser.id ).generation_time # dbuser.updated_at = ObjectId(dbuser.id ).generation_time # await conn[database_name][user_collection_name]\ # .update_one({"username": dbuser.username}, {'$set': dbuser.dict()}) return dbuser
async def create_user(conn: AsyncIOMotorClient, user: UserInRegister) -> UserInDB: dbuser = UserInDB(**user.dict()) dbuser.change_password(user.password) dbuser.created_at = datetime.now() dbuser.updated_at = datetime.now() inserted_row = await conn[database_name][users_collection_name].insert_one( dbuser.dict()) dbuser.id = str(inserted_row.inserted_id) return dbuser