aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2022-08-13 00:10:56 +0200
committerDaniel Schadt <kingdread@gmx.de>2022-08-13 00:13:23 +0200
commit305f605a540e3531e27c240445314dcdc3a69a09 (patch)
tree0fd7fd6c85bd7825d814c69ac1c13e9cdaf3ac7a /tests
parent3f803b30199d363207e6cb2f4c2a8fb981c02855 (diff)
downloadfietsboek-305f605a540e3531e27c240445314dcdc3a69a09.tar.gz
fietsboek-305f605a540e3531e27c240445314dcdc3a69a09.tar.bz2
fietsboek-305f605a540e3531e27c240445314dcdc3a69a09.zip
fix tests
Now that the filtering is done via SQL, it is not enough for the user and the objects to be in the session - they need to be in the database, similar to the added tracks. Note that it was not entirely necessary in this case, since the tracks are public, but it provides the proper functionality in the future.
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py32
1 files changed, 26 insertions, 6 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index a91d2f4..8f7f77c 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -9,6 +9,8 @@ import pytest
import transaction
import webtest
+from sqlalchemy import delete, select
+
from fietsboek import main
from fietsboek import models
from fietsboek.models.meta import Base
@@ -145,7 +147,7 @@ def route_path(app_request):
@pytest.fixture()
-def logged_in(dbsession, testapp, route_path):
+def logged_in(testapp, route_path, dbsession, tm):
"""
A fixture that represents a logged in state.
@@ -153,14 +155,32 @@ def logged_in(dbsession, testapp, route_path):
Returns the user that was logged in.
"""
- user = models.User(email='foo@bar.com', is_verified=True)
- user.set_password("foobar")
- dbsession.add(user)
+ tm.abort()
+
+ with tm:
+ user = models.User(email='foo@barre.com', is_verified=True)
+ user.set_password("foobar")
+ dbsession.add(user)
+ dbsession.flush()
+ user_id = user.id
+
+ tm.begin()
+ tm.doom()
login = testapp.get(route_path('login'))
form = login.form
- form['email'] = 'foo@bar.com'
+ form['email'] = 'foo@barre.com'
form['password'] = 'foobar'
response = form.submit()
assert response.status_code == 302
- return user
+
+ try:
+ # Make sure to return an object that is not bound to the wrong db
+ # session by re-fetching it with the proper fixture session:
+ yield dbsession.execute(select(models.User).filter_by(id=user_id)).scalar_one()
+ finally:
+ tm.abort()
+ with tm:
+ dbsession.execute(delete(models.User).filter_by(id=user_id))
+ tm.begin()
+ tm.doom()