open-law/tests/utils.py

25 lines
651 B
Python
Raw Normal View History

2023-04-20 13:10:16 +00:00
from app.models import User
TEST_ADMIN_NAME = "bob"
TEST_ADMIN_EMAIL = "bob@test.com"
TEST_ADMIN_PASSWORD = "password"
def create(username=TEST_ADMIN_NAME, password=TEST_ADMIN_PASSWORD):
user = User(username=username)
2023-04-20 13:10:16 +00:00
user.password = password
user.save()
return user.id
def login(client, username=TEST_ADMIN_NAME, password=TEST_ADMIN_PASSWORD):
2023-04-24 08:29:05 +00:00
user = User.query.filter_by(username=username).first()
response = client.post(
2023-04-20 13:10:16 +00:00
"/login", data=dict(user_id=username, password=password), follow_redirects=True
)
2023-04-24 08:29:05 +00:00
return response, user
2023-04-20 13:10:16 +00:00
def logout(client):
return client.get("/logout", follow_redirects=True)