def test_drop(): db = mongoset.connect(MONGO_DB_LOCAL_SERVER, "test_db") table = db["test_table"] assert table.insert({"test": True}) assert table.find_one(test=True) db.drop() db = mongoset.connect(MONGO_DB_LOCAL_SERVER, "test_db") table = db["test_table"] assert not table.find_one(test=True)
## Credit: some auth code is from the authlib docs config = Config('.env') # read config from .env file oauth = OAuth(config) oauth.register(name='google', server_metadata_url= 'https://accounts.google.com/.well-known/openid-configuration', client_kwargs={'scope': 'openid email profile'}) ## API creation app = FastAPI() backend = FastAPI() ## Adding middleware and database app.add_middleware(SessionMiddleware, secret_key=secrets.token_hex(16)) db = mongoset.connect(db_name="reportr")["reportr"] with open("admin.yaml") as f: admins = yaml.load(f).get("admins") @app.route("/") async def index(request: Request): user = request.session.get('user') if email := await authenticate_user(user): return RedirectResponse(url="/report.html") return RedirectResponse(url="/index.html") @backend.route('/login') async def login(request: Request): # absolute url for callback
from typing import Optional import discord import mongoset import env from mongoset.model import DocumentModel, Immutable, ModelTable from bot.msgs import templates import yaml import validators from pydantic import validator if not env.DATABASE: db = mongoset.connect(db_name=env.DATABASE_COLLECTION) else: db = mongoset.connect(env.DATABASE, db_name=env.DATABASE_COLLECTION) with open("admin.yaml") as f: admins = yaml.safe_load(f) class DBUser(DocumentModel): discord_id: int = Immutable() registered: bool registration_step: int first_name: Optional[str] last_name: Optional[str] choate_email: Optional[str] opt_out_email: Optional[bool] attendance: Optional[list] ctf_problem_solves: Optional[list]
def test_raise_value_error(): with pytest.raises(Exception) as e_info: db = connect(MONGO_DB_LOCAL_SERVER, "test_db") table = db["test_table"] table.delete()
def test_connect(): # Usually fails because mongodb local server isn't running db = connect(MONGO_DB_LOCAL_SERVER, "test_db") db.client.server_info() assert isinstance(db, Database) assert db.db_name == "test_db"
def setup(): db = mongoset.connect(MONGO_DB_SERVER, "test_db") table = db["test_table"] table.deindex_all() return table
async def root(): db = mongoset.connect(uri=settings.db_uri, db_name=settings.db_name)["queuebot"] return db.find(status=True)