Skip to content

Commit

Permalink
more UT on Runner
Browse files Browse the repository at this point in the history
  • Loading branch information
manatlan committed Jun 8, 2024
1 parent e26a58e commit 3d310a6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ IMPORTANT : the "tag.update" feature doesn't reset the inactivity timeout !
Example to add a static endpoint :

```python
from starlette.responses import PlainTextResponse

async def serve(req):
return open("...","r").read()
return PlainTextResponse("body {}")

app=Runner( App, debug=False, ssl=True )
app.add_route("/my.css", serve)
Expand Down
44 changes: 43 additions & 1 deletion test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from htagweb import Runner
import sys,json
from starlette.testclient import TestClient
from starlette.responses import PlainTextResponse

import bs4

Expand Down Expand Up @@ -37,7 +38,6 @@ def test_runner_http_mode():
def do_tests(client):
response = client.get('/')

# assert that get bootstrap page
assert response.status_code == 200
assert "<!DOCTYPE html>" in response.text

Expand All @@ -51,3 +51,45 @@ def do_tests(client):
app=Runner("examples.simple.App",http_only=True)
with TestClient(app) as client:
do_tests(client)


def test_runner_route_static():

def do_tests(client):
# assert nothing is at "/"
response = client.get('/')
assert response.status_code == 404

# but something is at "/hello"
response = client.get('/hello')
assert response.status_code == 200
assert response.text == "world"


async def serve(req): return PlainTextResponse("world")

app=Runner()
app.add_route("/hello", serve)
with TestClient(app) as client:
do_tests(client)


def test_runner_route_app():

def do_tests(client):
# assert nothing is at "/"
response = client.get('/')
assert response.status_code == 404

# but something is at "/hello"
response = client.get('/an_app')
assert response.status_code == 200
assert "<!DOCTYPE html>" in response.text

async def serve_an_app(req):
return await req.app.handle(req,"examples.simple.App")

app=Runner()
app.add_route("/an_app", serve_an_app)
with TestClient(app) as client:
do_tests(client)

0 comments on commit 3d310a6

Please sign in to comment.