Files
baiyue-logistics-chat/tests/staff_fixture.py
T
2026-11-02 17:51:10 +08:00

19 lines
825 B
Python

"""Authenticate test clients through the production login and CSRF contracts."""
from logistics_chat import db
def login_staff(app, client, username='staff-test-fixture', password='fixture-password', seed=True):
if seed:
with app.app_context():
connection = db.connect()
connection.execute('INSERT INTO agents(username,password,name) VALUES(?,?,?)',
(username, password, 'Fixture Staff'))
connection.commit()
response = client.post('/admin/login', json={'username':username, 'password':password})
assert response.status_code == 200, response.status_code
session = client.get('/api/admin/session')
assert session.status_code == 200, session.status_code
client.environ_base['HTTP_X_CSRF_TOKEN'] = session.json['csrf_token']