Skip to content
Myr

Add tests for flask.json.dump() and test that jsonify correctly converts uuids.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Nathan Land · committed by David Lord · parent 9121e10 · Browse files · 1 file+29 added−0 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+29 added−0 removed

  • tests:+29 added−0 removed

1 file+29 added−0 removed

modified:tests/test_helpers.py+29 added
10 unmodified lines
1112import pytest1314import os15import uuid16import datetime17import flask18from logging import StreamHandler19from werkzeug.exceptions import BadRequest, NotFound
79 unmodified lines
99 with app.app_context():100 rv = flask.json.dumps(u'\N{SNOWMAN}')101 assert rv == u'"\u2603"'102103 def test_json_dump_to_file(self):104 app = flask.Flask(__name__)105106 test_data = {'lol': 'wut'}107108 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()112113 t_fh = open('test_json_dump_file', 'r')114 rv = flask.json.load(t_fh)115 assert rv == test_data116 t_fh.close()117 os.remove('test_json_dump_file')118119 def test_jsonify_basic_types(self):120 """Test jsonify with basic types."""121 # Should be able to use pytest parametrize on this, but I couldn't122 # figure out the correct syntax
65 unmodified lines
188 rv = c.get(url)189 assert rv.mimetype == 'application/json'190 assert flask.json.loads(rv.data)['x'] == http_date(d.timetuple())191192 def test_jsonify_uuid_types(self):193 """Test jsonify with uuid.UUID types"""194 test_uuid = uuid.UUID(bytes=b'\xDE\xAD\xBE\xEF'*4)195196 app = flask.Flask(__name__)197 c = app.test_client()198 url = '/uuid_test'199 app.add_url_rule(url, 'uuid_test', lambda val=test_uuid: flask.jsonify(x=val))200 rv = c.get(url)201 assert rv.mimetype == 'application/json'202 assert flask.json.loads(rv.data)['x'] == str(test_uuid)203204 def test_json_attr(self):205 app = flask.Flask(__name__)206 @app.route('/add', methods=['POST'])207 def add():
600 unmodified lines