File tree Expand file tree Collapse file tree 2 files changed +26
-19
lines changed
Expand file tree Collapse file tree 2 files changed +26
-19
lines changed Original file line number Diff line number Diff line change 11import pytest
2- from flask import Flask , g
2+ from flask import Flask , current_app , g
33from flask .testing import FlaskClient
44
55from teufa import db as dbm
66from teufa .app import create_app
77from teufa .ext import db
88
99
10- @pytest .fixture
11- def app ():
10+ def pytest_configure ():
1211 app = create_app ()
13- with app .app_context ():
14- dbm .Base .metadata .create_all (db .engine )
12+ app .app_context ().push ()
13+
14+
15+ def create_default_tenant ():
16+ tenant = dbm .Tenant (
17+ name = "Default" ,
18+ hostname = "localhost" ,
19+ )
20+ db .session .add (tenant )
21+ db .session .commit ()
1522
16- tenant = dbm .Tenant (
17- name = "Default" ,
18- hostname = "localhost" ,
19- )
20- db .session .add (tenant )
21- db .session .commit ()
22- g .tenant = tenant
23+ g .tenant = tenant
24+
25+
26+ @pytest .fixture
27+ def app ():
28+ dbm .Base .metadata .create_all (db .engine )
2329
24- yield app
30+ with current_app .app_context ():
31+ create_default_tenant ()
32+ yield current_app
2533
26- dbm .Base .metadata .drop_all (db .engine )
34+ dbm .Base .metadata .drop_all (db .engine )
2735
2836
2937@pytest .fixture
Original file line number Diff line number Diff line change @@ -15,11 +15,10 @@ def create_app():
1515
1616 @app .before_request
1717 def before_request ():
18- if not hasattr (g , "tenant" ):
19- hostname = request .host .split (":" )[0 ]
20- g .tenant = db .session .scalars (
21- select (dbm .Tenant ).filter_by (hostname = hostname ).limit (1 )
22- ).first ()
18+ hostname = request .host .split (":" )[0 ]
19+ g .tenant = db .session .scalars (
20+ select (dbm .Tenant ).filter_by (hostname = hostname ).limit (1 )
21+ ).first ()
2322
2423 @app .teardown_request
2524 def teardown_request (exc ):
You can’t perform that action at this time.
0 commit comments