Skip to content

Instantly share code, notes, and snippets.

@jakab922
Created December 2, 2014 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakab922/39a14f28b91de041b4f2 to your computer and use it in GitHub Desktop.
Save jakab922/39a14f28b91de041b4f2 to your computer and use it in GitHub Desktop.
# BaseTestClient is flask.testing.FlaskClient
class TestClient(BaseTestClient):
"""
Test Client.
"""
def __exit__(self, exc_type, exc_value, tb):
self.preserve_context = False
top = _request_ctx_stack.top
if top is not None and top.preserved:
pass
def open(self, *args, **kwargs):
if "data" in kwargs and not isinstance(kwargs["data"], MultiDict):
kwargs["data"] = testlib.form.FormData(kwargs["data"])
return super(TestClient, self).open(*args, **kwargs)
@cachedproperty
def urls(self):
return self.application.url_map.bind("localhost", "/")
def url_for(self, endpoint, **kwargs):
return self.urls.build(endpoint, kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment