From e11999fbd9098f9434ac9635a9c1061612896ccf Mon Sep 17 00:00:00 2001 From: ip999 Date: Mon, 20 Jul 2020 14:46:08 +0100 Subject: [PATCH] initial commit --- .github/workflows/python-app.yml | 29 +++++++++++++++++++++++++++++ hello.py | 19 +++++++++++++++++++ test.py | 15 +++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 .github/workflows/python-app.yml create mode 100644 hello.py create mode 100644 test.py diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..97685ca --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,29 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Python application - tests + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Test with pytest + run: | + pytest test.py diff --git a/hello.py b/hello.py new file mode 100644 index 0000000..427b65d --- /dev/null +++ b/hello.py @@ -0,0 +1,19 @@ +from flask import Flask +from flask import make_response +app = Flask(__name__) + + +@app.route('/') +def home(): + return "Hello World!\n" + + +@app.route('/') +def other_page(page_name): + response = make_response('ERROR: The page named %s does not exist.' + % page_name, 404) + return response + + +if __name__ == '__main__': + app.run(debug=True, host='0.0.0.0') diff --git a/test.py b/test.py new file mode 100644 index 0000000..9605ef7 --- /dev/null +++ b/test.py @@ -0,0 +1,15 @@ +from hello import app + + +def test_home(): + tester = app.test_client() + response = tester.get('/', content_type='html/text') + assert response.status_code == 200 + assert b'Hello World!' in response.data + + +def test_other(): + tester = app.test_client() + response = tester.get('a', content_type='html/text') + assert response.status_code == 404 + assert b'does not exist' in response.data \ No newline at end of file