Skip to content

Commit 429023d

Browse files
committed
Merge pull request #26 from vitalk/better-test-coverage
Add tests for fixtures and markers
2 parents bd005ba + b36bc17 commit 429023d

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

pytest_flask/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
__version__ = "0.7.3"
4+
__version__ = "0.7.4"

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: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 TestJSONResponse:
27+
28+
def test_json_response(self, client, accept_json):
29+
res = client.get(url_for('ping'), headers=accept_json)
30+
assert res.json == {'ping': 'pong'}
31+
32+
def test_dont_rewrite_existing_implementation(self, app, accept_json):
33+
class MyResponse(app.response_class):
34+
@property
35+
def json(self):
36+
'''What is the meaning of life, the universe and everything?'''
37+
return 42
38+
39+
app.response_class = MyResponse
40+
client = app.test_client()
41+
42+
res = client.get(url_for('ping'), headers=accept_json)
43+
assert res.json == 42
44+
45+
46+
@pytest.mark.usefixtures('client_class')
47+
class TestClientClass:
48+
49+
def test_client_attribute(self):
50+
assert hasattr(self, 'client')
51+
assert self.client.get(url_for('ping')).json == {'ping': 'pong'}

tests/test_markers.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
import pytest
4+
5+
6+
class TestAppMarker:
7+
8+
@pytest.mark.app(debug=False)
9+
def test_not_debug_app(self, app):
10+
assert not app.debug, 'Ensure the app not in debug mode'
11+
12+
@pytest.mark.app(foo=42)
13+
def test_update_application_config(self, config):
14+
assert config['FOO'] == 42

0 commit comments

Comments
 (0)