"""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']