diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a8ce546 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +benv/ +__pycache__ +.pytest_cache/ \ No newline at end of file diff --git a/.env b/.env index 44062ab..5159ff1 100644 --- a/.env +++ b/.env @@ -3,4 +3,6 @@ COMPOSE_PROJECT_NAME=flaskblog POSTGRES_USER=flaskblog POSTGRES_PASSWORD=blogpassword -PYTHONUNBUFFERED=true \ No newline at end of file +PYTHONUNBUFFERED=true + +FLASK_APP="blogexample/app.py" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1face41..caf17c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ benv/ *.pyc +__pycache__/ +.pytest_cache/ \ No newline at end of file diff --git a/README.md b/README.md index b0c14b4..6a57853 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/requirements.txt b/requirements.txt index d5f92bc..1f08ac1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,3 +20,6 @@ WTForms-Alchemy==0.16.9 flask_ckeditor pytz + +# test +pytest==6.2. diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..8bf6785 --- /dev/null +++ b/tests/conftest.py @@ -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() diff --git a/tests/test_blog.py b/tests/test_blog.py new file mode 100644 index 0000000..aea8472 --- /dev/null +++ b/tests/test_blog.py @@ -0,0 +1,10 @@ +def test_can_get_home_page(client): + response = client.get("/") + assert 200 == response.status_code + assert b"