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 basic tests #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
__ARCHIVED:__ this project is not updated anymore, the Starlette API may have changed in these years

# An example Starlette application

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:
Expand Down
Binary file added app/__pycache__/app.cpython-37.pyc
Binary file not shown.
File renamed without changes.
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ aiofiles
jinja2
starlette
uvicorn
# requests and pytest used for testing
pytest
requests
2 changes: 1 addition & 1 deletion scripts/install
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
virtualenv venv --python=python3
python3 -m venv venv
venv/bin/pip install -r requirements.txt
2 changes: 1 addition & 1 deletion scripts/run
Original file line number Diff line number Diff line change
@@ -1 +1 @@
venv/bin/python app.py
venv/bin/python3 app/app.py
1 change: 1 addition & 0 deletions scripts/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
venv/bin/python3 -m pytest tests
Binary file not shown.
20 changes: 20 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -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')