Skip to content

Commit

Permalink
Merge pull request #2303 from MikeTheReader/master
Browse files Browse the repository at this point in the history
Added tests for make_response and get_debug_flag to improve coverage of helpers.py
  • Loading branch information
davidism authored May 23, 2017
2 parents 11d2eec + 7c882a4 commit c8e56d5
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from werkzeug.http import parse_cache_control_header, parse_options_header
from werkzeug.http import http_date
from flask._compat import StringIO, text_type
from flask.helpers import get_debug_flag, make_response


def has_encoding(name):
Expand Down Expand Up @@ -941,3 +942,32 @@ def test_safe_join_exceptions(self):
for args in failing:
with pytest.raises(NotFound):
print(flask.safe_join(*args))

class TestHelpers(object):

@pytest.mark.parametrize('debug, expected_flag, expected_default_flag', [
('', None, True),
('0', False, False),
('False', False, False),
('No', False, False),
('True', True, True)
])
def test_get_debug_flag(self, monkeypatch, debug, expected_flag, expected_default_flag):
monkeypatch.setenv('FLASK_DEBUG', debug)
if expected_flag is None:
assert get_debug_flag() is None
else:
assert get_debug_flag() == expected_flag
assert get_debug_flag(default=True) == expected_default_flag

def test_make_response(self):
app = flask.Flask(__name__)
with app.test_request_context():
rv = flask.helpers.make_response()
assert rv.status_code == 200
assert rv.mimetype == 'text/html'

rv = flask.helpers.make_response('Hello')
assert rv.status_code == 200
assert rv.data == b'Hello'
assert rv.mimetype == 'text/html'

0 comments on commit c8e56d5

Please sign in to comment.