Skip to content
Myr

Create json_dumps() method on new EnvironBuilder

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

authored by Daniel Pope · committed by Daniel Pope · parent 976dfed · Browse files · 3 files+11 added−14 removed
This commit

State

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

Diff stats

3 files+11 added−14 removed

  • tests:+0 added−5 removed
  • other:+11 added−9 removed

3 files+11 added−14 removed

modified:flask/testing.py+9 added-9 removed
80 unmodified lines
81 if url.query:82 sep = b"?" if isinstance(url.query, bytes) else "?"83 path += sep + url.query8485 if "json" in kwargs:86 assert "data" not in kwargs, "Client cannot provide both 'json' and 'data'."87 kwargs["data"] = self.json_dumps(kwargs.pop("json"), app=app)8889 if "content_type" not in kwargs:90 kwargs["content_type"] = "application/json"9192 super(EnvironBuilder, self).__init__(path, base_url, *args, **kwargs)85 self.app = app86 super(EnvironBuilder, self).__init__(path, base_url, *args, **kwargs)8795 json_dumps = staticmethod(json_dumps)88 def json_dumps(self, obj, **args):89 """Serialize ``obj`` to a JSON-formatted string.9091 The serialization will be configured according to the config associated92 with this EnvironBuilder's ``app``.93 """94 args.setdefault("app", self.app)95 return json_dumps(obj, **args)969798def make_test_environ_builder(*args, **kwargs):99 """Create a :class:`flask.testing.EnvironBuilder`.100101 .. deprecated: 1.1
182 unmodified lines
modified:tests/test_testing.py-5 removed
134 unmodified lines
135 eb = EnvironBuilder(app, json=u"\u20ac")136 assert eb.input_stream.read().decode("utf8") == u'"\u20ac"'137138139def test_environbuilder_json_dumps_static():140 """EnvironBuilder.json_dumps() can be called as a static method."""141 assert EnvironBuilder.json_dumps(u"\u20ac") == u'"\\u20ac"'142143139def test_blueprint_with_subdomain():140 app = flask.Flask(__name__, subdomain_matching=True)141 app.config["SERVER_NAME"] = "example.com:1234"142 app.config["APPLICATION_ROOT"] = "/foo"
302 unmodified lines
modified:CHANGES.rst+2 added
64 unmodified lines
65 all preserved request contexts are popped when the block exits,66 ensuring nested contexts are cleaned up correctly. :pr:`3157`67- Show a better error message when the view return type is not68 supported. :issue:`3214`69- ``flask.testing.make_test_environ_builder()`` has been deprecated in70 favour of a new class ``flask.testing.EnvironBuilder``. :pr:`3232`7172.. _#2935: https://github.com/pallets/flask/issues/293573.. _#2957: https://github.com/pallets/flask/issues/295774.. _#2994: https://github.com/pallets/flask/pull/2994
947 unmodified lines