9
9
10
10
11
11
# noinspection PyShadowingNames
12
- @pytest .fixture
13
- @async_generator
14
- async def app ():
12
+ async def _app (config ):
15
13
app = sanic .Sanic ()
16
- app .config ['DB_HOST' ] = DB_ARGS ['host' ]
17
- app .config ['DB_PORT' ] = DB_ARGS ['port' ]
18
- app .config ['DB_USER' ] = DB_ARGS ['user' ]
19
- app .config ['DB_PASSWORD' ] = DB_ARGS ['password' ]
20
- app .config ['DB_DATABASE' ] = DB_ARGS ['database' ]
14
+ app .config .update (config )
21
15
22
16
db = Gino (app )
23
17
@@ -69,13 +63,39 @@ async def add_user(request):
69
63
await e .close ()
70
64
71
65
72
- def test_index_returns_200 (app ):
66
+ @pytest .fixture
67
+ @async_generator
68
+ async def app ():
69
+ await _app ({
70
+ 'DB_HOST' : DB_ARGS ['host' ],
71
+ 'DB_PORT' : DB_ARGS ['port' ],
72
+ 'DB_USER' : DB_ARGS ['user' ],
73
+ 'DB_PASSWORD' : DB_ARGS ['password' ],
74
+ 'DB_DATABASE' : DB_ARGS ['database' ],
75
+ })
76
+
77
+
78
+ @pytest .fixture
79
+ @async_generator
80
+ async def app_dsn ():
81
+ await _app ({'DB_DSN' : PG_URL })
82
+
83
+
84
+ def _test_index_returns_200 (app ):
73
85
request , response = app .test_client .get ('/' )
74
86
assert response .status == 200
75
87
assert response .text == 'Hello, world!'
76
88
77
89
78
- def test (app ):
90
+ def test_index_returns_200 (app ):
91
+ _test_index_returns_200 (app )
92
+
93
+
94
+ def test_index_returns_200_dsn (app_dsn ):
95
+ _test_index_returns_200 (app_dsn )
96
+
97
+
98
+ def _test (app ):
79
99
request , response = app .test_client .get ('/users/1' )
80
100
assert response .status == 404
81
101
@@ -91,3 +111,11 @@ def test(app):
91
111
request , response = app .test_client .get ('/users/1' )
92
112
assert response .status == 200
93
113
assert response .json == dict (id = 1 , nickname = 'fantix' )
114
+
115
+
116
+ def test (app ):
117
+ _test (app )
118
+
119
+
120
+ def test_dsn (app_dsn ):
121
+ _test (app_dsn )
0 commit comments