ZeroIntensity / view.py

The Batteries-Detachable Web Framework
https://view.zintensity.dev
MIT License
206 stars 15 forks source link

App Tests #62

Open ZeroIntensity opened 9 months ago

ZeroIntensity commented 9 months ago

The user should be able to write tests for their view app, like so:

@app.get("/")
async def index():
    ...

@index.test("my test name")  # could also be left blank, like @index.test
async def test_index(route: view.Test):
    assert (await route(query={"hello": "world"})).response == "foo"

# OR, it could be synchronous

@index.test("my test name")
def test_index(route: view.SyncTest):
    assert route(...).response == "..."  # manually call event loop internally

Then, the end user should be able to run their tests, like so:

$ view test
GET /hello (my test name) passed in 0.43ms
GET /fail failed after 1s:

assert route(...).response == "..."
AssertionError

They could also run tests for specific routes:

$ view test /hello --methods GET,POST
GET /hello (my test name) passed in 0.43ms

This should integrate with a virtual I/O system in #10 (i.e. database connections won't actually be called, and instead just made in memory for testing purposes)

ZeroIntensity commented 1 month ago

We should probably integrate with Pytest as well for batteries-detachable purposes.