File tree 2 files changed +20
-18
lines changed
2 files changed +20
-18
lines changed Original file line number Diff line number Diff line change 1
1
import pytest
2
- from flask import Flask , g
2
+ from flask import Flask , current_app , g
3
3
from flask .testing import FlaskClient
4
4
5
5
from teufa import db as dbm
6
6
from teufa .app import create_app
7
7
from teufa .ext import db
8
8
9
9
10
+ def pytest_configure ():
11
+ app = create_app ()
12
+ app .app_context ().push ()
13
+
14
+
10
15
@pytest .fixture
11
16
def app ():
12
- app = create_app ()
13
- with app .app_context ():
14
- dbm .Base .metadata .create_all (db .engine )
17
+ dbm .Base .metadata .create_all (db .engine )
15
18
16
- tenant = dbm .Tenant (
17
- name = "Default" ,
18
- hostname = "localhost" ,
19
- )
20
- db .session .add (tenant )
21
- db .session .commit ()
22
- g .tenant = tenant
19
+ tenant = dbm .Tenant (
20
+ name = "Default" ,
21
+ hostname = "localhost" ,
22
+ )
23
+ db .session .add (tenant )
24
+ db .session .commit ()
23
25
24
- yield app
26
+ with current_app .app_context ():
27
+ yield current_app
25
28
26
- dbm .Base .metadata .drop_all (db .engine )
29
+ dbm .Base .metadata .drop_all (db .engine )
27
30
28
31
29
32
@pytest .fixture
Original file line number Diff line number Diff line change @@ -15,11 +15,10 @@ def create_app():
15
15
16
16
@app .before_request
17
17
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 ()
23
22
24
23
@app .teardown_request
25
24
def teardown_request (exc ):
You can’t perform that action at this time.
0 commit comments