Skip to content

Commit 5ed3775

Browse files
committed
Refs python-gino/gino#215, added docs and tests
1 parent 57b1690 commit 5ed3775

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

tests/test_sanic.py

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,9 @@
99

1010

1111
# noinspection PyShadowingNames
12-
@pytest.fixture
13-
@async_generator
14-
async def app():
12+
async def _app(config):
1513
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)
2115

2216
db = Gino(app)
2317

@@ -69,13 +63,39 @@ async def add_user(request):
6963
await e.close()
7064

7165

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):
7385
request, response = app.test_client.get('/')
7486
assert response.status == 200
7587
assert response.text == 'Hello, world!'
7688

7789

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):
7999
request, response = app.test_client.get('/users/1')
80100
assert response.status == 404
81101

@@ -91,3 +111,11 @@ def test(app):
91111
request, response = app.test_client.get('/users/1')
92112
assert response.status == 200
93113
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

Comments
 (0)