Browse Source

Merge pull request #2303 from MikeTheReader/master

Added tests for make_response and get_debug_flag to improve coverage of helpers.py
pull/2304/head
David Lord 8 years ago committed by GitHub
parent
commit
c8e56d5807
  1. 30
      tests/test_helpers.py

30
tests/test_helpers.py

@ -22,6 +22,7 @@ from werkzeug.exceptions import BadRequest, NotFound
from werkzeug.http import parse_cache_control_header, parse_options_header from werkzeug.http import parse_cache_control_header, parse_options_header
from werkzeug.http import http_date from werkzeug.http import http_date
from flask._compat import StringIO, text_type from flask._compat import StringIO, text_type
from flask.helpers import get_debug_flag, make_response
def has_encoding(name): def has_encoding(name):
@ -941,3 +942,32 @@ class TestSafeJoin(object):
for args in failing: for args in failing:
with pytest.raises(NotFound): with pytest.raises(NotFound):
print(flask.safe_join(*args)) 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'

Loading…
Cancel
Save