Skip to content

Feat: setup pytest #18

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

Open
wants to merge 1 commit 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
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
benv/
__pycache__
.pytest_cache/
4 changes: 3 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ COMPOSE_PROJECT_NAME=flaskblog
POSTGRES_USER=flaskblog
POSTGRES_PASSWORD=blogpassword

PYTHONUNBUFFERED=true
PYTHONUNBUFFERED=true

FLASK_APP="blogexample/app.py"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
benv/
*.pyc
__pycache__/
.pytest_cache/
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Login/Admin related modules deliberately not implemented, and the blueprint can

* Now navigate to ```http://localhost:8000``` in the browser to test it out.

## How to run tests

* Run the test: `docker-compose exec website python -m pytest`

## *Optional*
* Build a model (Posts, Tags, Comments)

Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ WTForms-Alchemy==0.16.9
flask_ckeditor

pytz

# test
pytest==6.2.
20 changes: 20 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest
from blogexample.app import create_app


@pytest.fixture()
def app():
app = create_app()
app.config["TESTING"] = True

yield app


@pytest.fixture()
def client(app):
return app.test_client()


@pytest.fixture()
def runner(app):
return app.test_cli_runner()
10 changes: 10 additions & 0 deletions tests/test_blog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def test_can_get_home_page(client):
response = client.get("/")
assert 200 == response.status_code
assert b"<title>Flask BLOG</title>" in response.data


def test_can_show_posts(client):
response = client.get("/posts")
assert 200 == response.status_code
assert b"<title>Posts</title>" in response.data