Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /aspuru-guzik-group_molar /tests /backend /endpoints /test_login.py
| # std | |
| import os | |
| # external | |
| from fastapi.testclient import TestClient | |
| # molar | |
| from molar.backend.main import app | |
| def login(client, username=None, password=None, database="molar_main"): | |
| if username is None: | |
| username = os.getenv("MOLAR_SUPERUSER") or "test@molar.tooth" | |
| if password is None: | |
| password = os.getenv("MOLAR_PASSWORD") or "tooth" | |
| out = client.post( | |
| f"/api/v1/login/access-token?database_name={database}", | |
| data={ | |
| "username": username, | |
| "password": password, | |
| }, | |
| ) | |
| return out | |
| def test_login_access_token(client): | |
| # Valid crediential | |
| out = login(client) | |
| assert out.status_code == 200 | |
| # Invalid credential | |
| out = login(client, "asdf", "asdf") | |
| assert out.status_code == 400 | |
| # Invalid database | |
| out = login(client, database="idonotexist") | |
| assert out.status_code == 400 | |
| def test_token(client, molar_main_headers): | |
| # Legit token | |
| out = client.post("/api/v1/login/test-token", headers=molar_main_headers) | |
| assert out.status_code == 200 | |
| # Fake token | |
| headers = {"Authorization": "Bearer asdfasdfasdfasdfd"} | |
| out = client.post("/api/v1/login/test-token", headers=headers) | |
| assert out.status_code == 403 | |
| def test_unauthorized_access(client, new_database_headers): | |
| out = client.get( | |
| "/api/v1/database/information", | |
| params={"database_name": "main"}, | |
| headers=new_database_headers, | |
| ) | |
| assert out.status_code == 403 | |
Xet Storage Details
- Size:
- 1.49 kB
- Xet hash:
- 6a6ef22188d78384df5524585ba020a7e818507a0efa1750b4d86e8c841ee726
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.