From a567330a68912c407403741f3a2d344c46e4d34a Mon Sep 17 00:00:00 2001 From: Ben Shiller Date: Sun, 28 Feb 2021 01:28:04 +0000 Subject: [PATCH] Added test coverage --- Dockerfile | 3 +-- MANIFEST.in | 4 ++-- docker-compose.yml | 4 ++-- my_homepage/__init__.py | 19 ++++++------------- setup.cfg | 7 +++++++ tests/test_website.py | 17 +++++++++++++++++ 6 files changed, 35 insertions(+), 19 deletions(-) create mode 100644 setup.cfg create mode 100644 tests/test_website.py diff --git a/Dockerfile b/Dockerfile index b908a12..0035220 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,5 +10,4 @@ ENV FLASK_ENV production COPY . . -CMD ["gunicorn", "-b", "0.0.0.0:5000", "my_homepage:create_app()"] -#CMD ["gunicorn", "-b", "127.0.0.1:5000", "my_homepage:create_app()"] +CMD ["gunicorn", "-b", "0.0.0.0:4040", "my_homepage:create_app()"] diff --git a/MANIFEST.in b/MANIFEST.in index bc7f54f..e801637 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,3 @@ -graft flaskr/static -graft flaskr/templates +graft my_homepage/static +graft my_homepage/templates global-exclude *.pyc diff --git a/docker-compose.yml b/docker-compose.yml index d088821..e0892ff 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3.9' +version: '3' services: web: @@ -7,4 +7,4 @@ services: volumes: - .:/app ports: - - "5000:5000" + - "4040:4040" diff --git a/my_homepage/__init__.py b/my_homepage/__init__.py index cb77293..c21e4ad 100644 --- a/my_homepage/__init__.py +++ b/my_homepage/__init__.py @@ -7,20 +7,13 @@ def create_app(test_config=None): # create and configure the app app = Flask(__name__, instance_relative_config=True) - #if test_config is None: - # # load the instance config, if it exists, when not testing - # app.config.from_pyfile('config.py', silent=True) - #else: - # # load the test config if passed in - # app.config.from_mapping(test_config) + if test_config is None: + # load the instance config, if it exists, when not testing + app.config.from_pyfile('config.py', silent=True) + else: + # load the test config if passed in + app.config.from_mapping(test_config) - ## ensure the instance folder exists - #try: - # os.makedirs(app.instance_path) - #except OSError: - # pass - - # a simple page that says hello @app.route('/') def index(): return render_template('index.html') diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..0b7f9f7 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,7 @@ +[tool:pytest] +testpaths = tests + +[coverage:run] +branch = True +source = + my_homepage diff --git a/tests/test_website.py b/tests/test_website.py new file mode 100644 index 0000000..49686bb --- /dev/null +++ b/tests/test_website.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 + +import pytest +from my_homepage import create_app + +@pytest.fixture +def app(): + app = create_app({"TESTING": True}) + yield app + +@pytest.fixture +def client(app): + return app.test_client() + +def test_app(client): + response = client.get("/") + assert(response.status_code == 200)