Skip to content
Merged
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
5 changes: 3 additions & 2 deletions .github/workflows/github-actions-demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ jobs:

- name: Install dependencies
run: |
pip install requirements.txt
pip install -r requirements.txt

- name: Run unit test
run: |
pytest
export PYTHONPATH="${{ github.workspace }}"
pytest tests/test_app.py

code-quality:
runs-on: ubuntu-latest
Expand Down
25 changes: 15 additions & 10 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
from flask import Flask, render_template


# Create an instance of the Flask class.
app = Flask(__name__)

# __name__ is a special variable that gets the name of the current Python module.

@app.route('/')
def home():
"""Serves the home page."""
# Render the home.html template
return render_template('home.html')

# Define a route for an 'about' page.

@app.route('/about')
def about():
"""Serves the about page."""
# Render the about.html template
return render_template('about.html')

# This block allows you to run the app directly from the command line.
if __name__ == '__main__':
# debug=True will auto-reload the server on code changes and show detailed errors.
# For production, consider using a production-ready WSGI server like Gunicorn.
# host='0.0.0.0' makes the app accessible from any IP, which is necessary for containerized deployments like Cloud Run.
app.run(debug=True, host='0.0.0.0', port=8080) # Using port 8080 as a common port for containerized apps.

if __name__ == '__main__':
# debug=True will auto-reload the server on code changes
# and show detailed errors.
# For production, consider using a production-ready WSGI server
# like Gunicorn.
# host='0.0.0.0' makes the app accessible from any IP,
# which is necessary for containerized deployments like Cloud Run.
app.run(
debug=True,
host='0.0.0.0',
port=8080
)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Flask
pytest
2 changes: 1 addition & 1 deletion templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block content %}
<h1>Hello, World!</h1>
<p>Welcome to your enhanced Python web app with a UI.</p>
<p>Welcome to your enhanced Python web app with a UI which is served on Cloud routing.</p>
<p>This page is rendered using a Jinja2 template and styled with CSS.</p>
{% endblock %}

30 changes: 30 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pytest
from app import app # Import your Flask app instance


@pytest.fixture
def client():
"""Create a test client for the Flask app."""
app.config['TESTING'] = True
with app.test_client() as client:
yield client


def test_home_page(client):
"""Test the home page route."""
response = client.get('/')
assert response.status_code == 200
# You might want to add more specific assertions about the content
# For example, check if a specific string is present in the response data:
# assert b"Hello, World!" in response.data


def test_about_page(client):
"""Test the about page route."""
response = client.get('/about')
assert response.status_code == 200
# Add more specific assertions about the content if needed


if __name__ == '__main__':
pytest.main()