diff --git a/README.md b/README.md index d31de43..c70cd2b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +__ARCHIVED:__ this project is not updated anymore, the Starlette API may have changed in these years + # An example Starlette application Install and run: @@ -5,8 +7,10 @@ Install and run: ```shell git clone https://github.com/encode/starlette-example.git cd starlette-example -scripts/install -scripts/run +./scripts/install +./scripts/run +# to test +./scripts/test ``` Open `http://127.0.0.1:8000/` in your browser: diff --git a/app/__pycache__/app.cpython-37.pyc b/app/__pycache__/app.cpython-37.pyc new file mode 100644 index 0000000..4fe8dc3 Binary files /dev/null and b/app/__pycache__/app.cpython-37.pyc differ diff --git a/app.py b/app/app.py similarity index 100% rename from app.py rename to app/app.py diff --git a/requirements.txt b/requirements.txt index 3982784..0d9e0c6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,6 @@ aiofiles jinja2 starlette uvicorn +# requests and pytest used for testing +pytest +requests diff --git a/scripts/install b/scripts/install index 0a7b733..02ce37e 100755 --- a/scripts/install +++ b/scripts/install @@ -1,2 +1,2 @@ -virtualenv venv --python=python3 +python3 -m venv venv venv/bin/pip install -r requirements.txt diff --git a/scripts/run b/scripts/run index f5d0762..31381a0 100755 --- a/scripts/run +++ b/scripts/run @@ -1 +1 @@ -venv/bin/python app.py +venv/bin/python3 app/app.py diff --git a/scripts/test b/scripts/test new file mode 100755 index 0000000..52bebf3 --- /dev/null +++ b/scripts/test @@ -0,0 +1 @@ +venv/bin/python3 -m pytest tests diff --git a/tests/__pycache__/test_main.cpython-37-pytest-5.0.1.pyc b/tests/__pycache__/test_main.cpython-37-pytest-5.0.1.pyc new file mode 100644 index 0000000..05d9ecd Binary files /dev/null and b/tests/__pycache__/test_main.cpython-37-pytest-5.0.1.pyc differ diff --git a/tests/test_main.py b/tests/test_main.py new file mode 100644 index 0000000..1a84cc7 --- /dev/null +++ b/tests/test_main.py @@ -0,0 +1,20 @@ +from starlette.responses import HTMLResponse +from starlette.testclient import TestClient +import pytest + +from app.app import app + +@pytest.fixture +def client(): + return TestClient(app) + +def test_home(client): + response = client.get('/') + assert response.status_code == 200 + assert 'mi porta gravida at' in response.content.decode('utf-8') + +def test_missing(client): + response = client.get('/fake-path') + assert response.status_code == 404 + assert 'Page not found.' in response.content.decode('utf-8') +