clean up new json tests
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent f16e477 · Browse files · 1 file·+15 added−15 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+15 added−15 removed
- tests:+15 added−15 removed
Provenance
- Commit
f193f59- Tree
fb5e1d6- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
f16e477
1 file changed+15 added−15 removed
modified:tests/test_helpers.py+15 added-15 removed
17 unmodified lines18 from logging import StreamHandler19 from werkzeug.exceptions import BadRequest, NotFound20 from werkzeug.http import parse_cache_control_header, parse_options_header21 from werkzeug.http import http_date22-from flask._compat import StringIO, text_type, PY222+from flask._compat import StringIO, text_type23 24 25 def has_encoding(name):26 try:74 unmodified lines101 assert rv == u'"\u2603"'102 103 def test_json_dump_to_file(self):104 app = flask.Flask(__name__)105+ test_data = {'name': 'Flask'}106+ out = StringIO()107 106- test_data = {'lol': 'wut'}107-108 with app.app_context():109- t_fh = open('test_json_dump_file', 'w')110- flask.json.dump(test_data, t_fh)111- t_fh.close()112-113- t_fh = open('test_json_dump_file', 'r')114- rv = flask.json.load(t_fh)109+ flask.json.dump(test_data, out)110+ out.seek(0)111+ rv = flask.json.load(out)112 assert rv == test_data116- t_fh.close()117- os.remove('test_json_dump_file')113 114 def test_jsonify_basic_types(self):115 """Test jsonify with basic types."""116 # Should be able to use pytest parametrize on this, but I couldn't68 unmodified lines185 assert flask.json.loads(rv.data)['x'] == http_date(d.timetuple())186 187 def test_jsonify_uuid_types(self):188 """Test jsonify with uuid.UUID types"""189+190 test_uuid = uuid.UUID(bytes=b'\xDE\xAD\xBE\xEF'*4)191 192 app = flask.Flask(__name__)197- c = app.test_client()193 url = '/uuid_test'199- app.add_url_rule(url, 'uuid_test', lambda val=test_uuid: flask.jsonify(x=val))194+ app.add_url_rule(url, url, lambda: flask.jsonify(x=test_uuid))195+196+ c = app.test_client()197 rv = c.get(url)201- assert rv.mimetype == 'application/json'202- assert flask.json.loads(rv.data)['x'] == str(test_uuid)198 199+ rv_x = flask.json.loads(rv.data)['x']200+ assert rv_x == str(test_uuid)201+ rv_uuid = uuid.UUID(rv_x)202+ assert rv_uuid == test_uuid203+204 def test_json_attr(self):205 app = flask.Flask(__name__)206 @app.route('/add', methods=['POST'])207 def add():600 unmodified lines