browsertrix/backend/test/test_login.py
Ilya Kreymer e3f268a2e8
CI setup for new swarm mode (#248)
- build backend and frontend with cacheing using GHA cache)
- streamline frontend image to reduce layers
- setup local swarm with test/setup.sh script, wait for containers to init
- copy sample config files as default (add storages.sample.yaml)
- add initial backend test for logging in with default superadmin credentials via 127.0.0.1:9871
- must use 127.0.0.1 instead of localhost for accessing frontend container within action
2022-06-06 09:34:02 -07:00

24 lines
761 B
Python

import requests
api_prefix = "http://127.0.0.1:9871/api"
def test_login_invalid():
username = "admin@example.com"
password = "invalid"
r = requests.post(f"{api_prefix}/auth/jwt/login", data={"username": username, "password": password, "grant_type": "password"})
data = r.json()
assert r.status_code == 400
assert data["detail"] == "LOGIN_BAD_CREDENTIALS"
def test_login():
username = "admin@example.com"
password = "PASSW0RD0"
r = requests.post(f"{api_prefix}/auth/jwt/login", data={"username": username, "password": password, "grant_type": "password"})
data = r.json()
assert r.status_code == 200
assert data["token_type"] == "bearer"
assert data["access_token"]
access_token = data["access_token"]