Reworked pytest client fixture to support new session mgmt
parent
32e837a5e0
commit
6ec65f8754
|
@ -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['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['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_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']):
|
if not os.path.exists(app.config['CONFIG_PATH']):
|
||||||
os.makedirs(app.config['CONFIG_PATH'])
|
os.makedirs(app.config['CONFIG_PATH'])
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
from app import app
|
from app import app
|
||||||
|
from app.utils.misc import generate_user_keys
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def client():
|
def client():
|
||||||
client = app.test_client()
|
with app.test_client() as client:
|
||||||
yield client
|
with client.session_transaction() as session:
|
||||||
|
session['uuid'] = 'test'
|
||||||
|
session['fernet_keys'] = generate_user_keys()
|
||||||
|
session['config'] = {}
|
||||||
|
yield client
|
||||||
|
|
|
@ -9,26 +9,23 @@ def test_generate_user_keys():
|
||||||
|
|
||||||
|
|
||||||
def test_valid_session(client):
|
def test_valid_session(client):
|
||||||
|
assert not valid_user_session({'fernet_keys': '', 'config': {}})
|
||||||
with client.session_transaction() as session:
|
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)
|
assert valid_user_session(session)
|
||||||
|
|
||||||
|
|
||||||
def test_request_key_generation(client):
|
def test_request_key_generation(client):
|
||||||
text_key = ''
|
rv = client.get('/')
|
||||||
rv = client.get('/search?q=test+1')
|
cookie = rv.headers['Set-Cookie']
|
||||||
|
|
||||||
|
rv = client.get('/search?q=test+1', headers={'Cookie': cookie})
|
||||||
assert rv._status_code == 200
|
assert rv._status_code == 200
|
||||||
|
|
||||||
with client.session_transaction() as session:
|
with client.session_transaction() as session:
|
||||||
assert valid_user_session(session)
|
assert valid_user_session(session)
|
||||||
text_key = session['fernet_keys']['text_key']
|
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
|
assert rv._status_code == 200
|
||||||
|
|
||||||
with client.session_transaction() as session:
|
with client.session_transaction() as session:
|
||||||
|
|
Loading…
Reference in New Issue