Sanic: Move sanic.utils's testing facilities to under tests namespace

Created on 2 Jan 2017  路  8Comments  路  Source: sanic-org/sanic

sanic.utils has a dependency on aiohttp package and sanic.utils.local_request() and sanic.utils.sanic_endpoint_test() are using it. However both two functions are only accessed from test codes. aiohttp is only listed in tox.ini's deps, not requirements.txt so I think it shows that there was no intention to bring aiohttp into the main. Why don't we move sanic.utils to tests/ and just use sanic.utils name for 'real' utils needed by sanic package itself?

idea discussion

All 8 comments

The problem would be that these functions are important for users in testing their own endpoints. I think it would be a shame to remove them.

Yes, not breaking users' code is crucial. But I think that it'd be better to arrange in some future, yes, some future... 馃槶 We can gradually deprecate them.

It originally was under the test namespace but I thought it'd be useful to have it open to anyone else who needed to use it to test their own applications.

We can have this idea discussion open for a couple of weeks but my view is that we should keep it where it is (maybe rename it to something else).

+1 to the idea of moving it to a separate test namespace. I can only imagine that as Sanic grows that testing utilities should be grouped in their own place.

I think it would be better to have it under the application so you could use something like:

from sanic import Sanic
app = Sanic(__name__)

# add a route here

app.test_endpoint(uri, method, *request_args, **request_kwargs)

Maybe do something like Flask's test_client instead of test_endpoint? It certainly comes in handy for unit testing, and it's a more idiomatic in my opinion.

This issue can be closed with #431, with the next release Sanic will have a Flask-like test_client to run test requests against:

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

I'll allow it, closed per #431

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fiecato picture fiecato  路  3Comments

ZeeRoc picture ZeeRoc  路  3Comments

woutor picture woutor  路  3Comments

mobdim picture mobdim  路  4Comments

litelife picture litelife  路  3Comments