Skip to content

Commit 6653c6f

Browse files
committed
Add tests for fixtures
1 parent bd005ba commit 6653c6f

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
@pytest.fixture
99
def app():
1010
app = Flask(__name__)
11+
app.config['SECRET_KEY'] = '42'
1112

1213
@app.route('/')
1314
def index():

tests/test_fixtures.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
import pytest
4+
5+
from flask import url_for
6+
7+
8+
class TestFixtures:
9+
10+
def test_config_access(self, config):
11+
assert config['SECRET_KEY'] == '42'
12+
13+
def test_application_has_pushed_context(self, app):
14+
assert url_for('ping') == '/ping'
15+
16+
def test_client(self, client):
17+
assert client.get(url_for('ping')).status == b'200 OK'
18+
19+
def test_accept_json(self, accept_json):
20+
assert accept_json == [('Accept', 'application/json')]
21+
22+
def test_accept_jsonp(self, accept_jsonp):
23+
assert accept_jsonp == [('Accept', 'application/json-p')]
24+
25+
26+
class TestAppMarker:
27+
28+
@pytest.mark.app(debug=False)
29+
def test_not_debug_app(self, app):
30+
assert not app.debug, 'Ensure the app not in debug mode'
31+
32+
@pytest.mark.app(foo=42)
33+
def test_update_application_config(self, config):
34+
assert config['FOO'] == 42
35+
36+
37+
class TestJSONResponse:
38+
39+
def test_json_response(self, client, accept_json):
40+
res = client.get(url_for('ping'), headers=accept_json)
41+
assert res.json == {'ping': 'pong'}
42+
43+
def test_dont_rewrite_existing_implementation(self, app, accept_json):
44+
class MyResponse(app.response_class):
45+
@property
46+
def json(self):
47+
'''What is the meaning of life, the universe and everything?'''
48+
return 42
49+
50+
app.response_class = MyResponse
51+
client = app.test_client()
52+
53+
res = client.get(url_for('ping'), headers=accept_json)
54+
assert res.json == 42
55+
56+
57+
@pytest.mark.usefixtures('client_class')
58+
class TestClientClass:
59+
60+
def test_client_attribute(self):
61+
assert hasattr(self, 'client')
62+
assert self.client.get(url_for('ping')).json == {'ping': 'pong'}

0 commit comments

Comments
 (0)