Skip to content

Commit d708136

Browse files
committed
Merge pull request #1 from albipuliga/main
Added test template
2 parents 8bbb5b5 + 4091ddd commit d708136

File tree

11 files changed

+78
-201
lines changed

11 files changed

+78
-201
lines changed

.github/CODE_OF_CONDUCT.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

.github/ISSUE_TEMPLATE.md

Lines changed: 0 additions & 33 deletions
This file was deleted.

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 0 additions & 45 deletions
This file was deleted.

.github/workflows/workflow.yaml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,29 @@ jobs:
2525
template: ./main.bicep
2626
parameters: ./main.parameters.json
2727

28-
build-and-push-image:
28+
run-tests:
29+
runs-on: ubuntu-latest
2930
needs: deploy-infrastructure
31+
steps:
32+
- uses: actions/checkout@v3
33+
34+
- name: Set up Python
35+
uses: actions/setup-python@v4
36+
with:
37+
python-version: "3.x"
38+
39+
- name: Install dependencies
40+
run: |
41+
python -m pip install --upgrade pip
42+
pip install -r requirements.txt
43+
pip install pytest
44+
45+
- name: Run tests
46+
run: |
47+
PYTHONPATH=$PYTHONPATH:$(pwd) pytest tests/
48+
49+
build-and-push-image:
50+
needs: [deploy-infrastructure, run-tests]
3051
runs-on: ubuntu-latest
3152
env:
3253
KEY_VAULT_NAME_DEV: "dkumlin-demo-kvtest"

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"python.testing.pytestArgs": [
3+
"tests"
4+
],
5+
"python.testing.unittestEnabled": false,
6+
"python.testing.pytestEnabled": true
7+
}

CHANGELOG.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 0 additions & 76 deletions
This file was deleted.

LICENSE.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,19 @@ Created `.github/workflows/workflow.yaml` with three main stages:
4343
- Creates/updates Azure resources
4444
- Sets up RBAC permissions
4545

46-
2. **Container Build & Push Stage**
46+
2. **Run Tests Stage**
47+
48+
- Builds the Docker image
49+
- Runs tests on the container
50+
- Exits with error if tests fail
51+
52+
3. **Container Build & Push Stage**
4753

4854
- Builds the Docker image
4955
- Tags with git SHA
5056
- Pushes to Azure Container Registry
5157

52-
3. **Web App Deployment Stage**
58+
4. **Web App Deployment Stage**
5359
- Pulls latest image from ACR
5460
- Deploys to Azure Web App
5561
- Updates container configuration

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Flask==2.2.2
22
gunicorn
3-
Werkzeug==2.2.2
3+
Werkzeug==2.2.2

tests/test_app.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import pytest
2+
3+
from app import app
4+
5+
6+
@pytest.fixture
7+
def client():
8+
app.config["TESTING"] = True
9+
with app.test_client() as client:
10+
yield client
11+
12+
13+
def test_index_route(client):
14+
"""Test the index route returns correct template"""
15+
response = client.get("/")
16+
assert response.status_code == 200
17+
assert b"<title>Hello Azure - Python Quickstart</title>" in response.data
18+
19+
20+
def test_favicon_route(client):
21+
"""Test favicon.ico is served correctly"""
22+
response = client.get("/favicon.ico")
23+
assert response.status_code == 200
24+
assert response.mimetype == "image/vnd.microsoft.icon"
25+
26+
27+
def test_hello_route_with_name(client):
28+
"""Test hello route with a name parameter"""
29+
response = client.post("/hello", data={"name": "Test User"})
30+
assert response.status_code == 200
31+
assert (
32+
b"Test User" in response.data
33+
) # Less strict assertion that checks if name appears anywhere
34+
35+
36+
def test_hello_route_without_name(client):
37+
"""Test hello route redirects when no name provided"""
38+
response = client.post("/hello", data={})
39+
assert response.status_code == 302
40+
assert response.headers["Location"] == "/"

0 commit comments

Comments
 (0)