Reworked pytest client fixture to support new session mgmt

main
Ben Busby 2020-06-05 16:09:04 -06:00
parent 32e837a5e0
commit 6ec65f8754
3 changed files with 13 additions and 12 deletions

View File

@ -15,7 +15,6 @@ app.config['STATIC_FOLDER'] = os.getenv('STATIC_FOLDER', os.path.join(app.config
app.config['CONFIG_PATH'] = os.getenv('CONFIG_VOLUME', os.path.join(app.config['STATIC_FOLDER'], 'config'))
app.config['DEFAULT_CONFIG'] = os.path.join(app.config['CONFIG_PATH'], 'config.json')
app.config['SESSION_FILE_DIR'] = os.path.join(app.config['CONFIG_PATH'], 'session')
app.config['SESSION_COOKIE_SAMESITE'] = 'Strict'
if not os.path.exists(app.config['CONFIG_PATH']):
os.makedirs(app.config['CONFIG_PATH'])

View File

@ -1,8 +1,13 @@
from app import app
from app.utils.misc import generate_user_keys
import pytest
@pytest.fixture
def client():
client = app.test_client()
with app.test_client() as client:
with client.session_transaction() as session:
session['uuid'] = 'test'
session['fernet_keys'] = generate_user_keys()
session['config'] = {}
yield client

View File

@ -9,26 +9,23 @@ def test_generate_user_keys():
def test_valid_session(client):
assert not valid_user_session({'fernet_keys': '', 'config': {}})
with client.session_transaction() as session:
assert not valid_user_session(session)
session['uuid'] = 'test'
session['fernet_keys'] = generate_user_keys()
session['config'] = {}
assert valid_user_session(session)
def test_request_key_generation(client):
text_key = ''
rv = client.get('/search?q=test+1')
rv = client.get('/')
cookie = rv.headers['Set-Cookie']
rv = client.get('/search?q=test+1', headers={'Cookie': cookie})
assert rv._status_code == 200
with client.session_transaction() as session:
assert valid_user_session(session)
text_key = session['fernet_keys']['text_key']
rv = client.get('/search?q=test+2')
rv = client.get('/search?q=test+2', headers={'Cookie': cookie})
assert rv._status_code == 200
with client.session_transaction() as session: