Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Flask-like test_client to replace sanic_endpoint_test #431

Merged
merged 3 commits into from Feb 15, 2017

Conversation

subyraman
Copy link
Contributor

This is a big PR but it is fully backwards compatible with previous code.

The sanic_endpoint_test method was incongruous with the Flask testing API, and also wasn't fully documented. Rework testing so that, similar to flask, you run tests against methods like app.test_client.get. The methods are essentially sugar around sanic_endpoint_test, so it preserves all the work done before.

From the docs I wrote:

The test_client exposes get, post, put, delete, patch, head and options methods
for you to run against your application. A simple example (using pytest) is like follows:

# Import the Sanic app, usually created with Sanic(__name__)
from external_server import app

def test_index_returns_200():
    request, response = app.test_client.get('/')
    assert response.status == 200

def test_index_put_not_allowed():
    request, response = app.test_client.put('/')
    assert response.status == 405

Ripped the bandaid in this PR by rewriting the tests to use the test_client as well.

Put in a deprecation notice that sanic_endpoint_test would be removed in version 1.0, can be changed if that's too aggressive.

sanic/utils.py Outdated
*request_args, **request_kwargs):
warnings.warn(
"Use of sanic_endpoint_test will be deprecated in"
"version 1.0. Please use the `test_client` available"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably leave this to say the next major version after 0.4.0

@JordanP
Copy link

JordanP commented Feb 15, 2017

I had a quick look at this PR and coming from a Flask background this way of testing app seems more natural to me.

@seemethere seemethere added this to the 0.4.0 milestone Feb 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants