app/tests/utils.py

44 lines
847 B
Python
Raw Normal View History

2020-11-16 02:34:13 +08:00
import json
from flask import url_for
from app.models import User
def login(flask_client) -> User:
# create user, user is activated
user = User.create(
2020-12-31 20:59:03 +08:00
email="a@b.c",
password="password",
name="Test User",
activated=True,
commit=True,
)
r = flask_client.post(
url_for("auth.login"),
data={"email": "a@b.c", "password": "password"},
follow_redirects=True,
)
assert r.status_code == 200
assert b"/auth/logout" in r.data
return user
2020-11-16 02:34:13 +08:00
def create_user(flask_client) -> User:
# create user, user is activated
return User.create(
email="a@b.c",
password="password",
name="Test User",
activated=True,
commit=True,
)
2020-11-16 02:34:13 +08:00
def pretty(d):
"""pretty print as json"""
print(json.dumps(d, indent=2))