Skip to content

Commit 184073f

Browse files
authored
Merge pull request #1 from albipuliga/main
Added test template
2 parents 8bbb5b5 + 0058d03 commit 184073f

File tree

12 files changed

+91
-214
lines changed

12 files changed

+91
-214
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: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,36 @@ 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:
32-
KEY_VAULT_NAME_DEV: "dkumlin-demo-kvtest"
53+
KEY_VAULT_NAME_DEV: "apuliga-demo-kvtest"
3354
KEY_VAULT_SECRET_ACR_USERNAME: "acr-username"
3455
KEY_VAULT_SECRET_ACR_PASSWORD: "acr-password0"
35-
CONTAINER_REGISTRY_SERVER_URL_DEV: "dkumlinacrdemo.azurecr.io"
36-
IMAGE_NAME_DEV: "dkumlin-demo-image"
56+
CONTAINER_REGISTRY_SERVER_URL_DEV: "apuligaacrdemo.azurecr.io"
57+
IMAGE_NAME_DEV: "apuliga-demo-image"
3758
steps:
3859
- uses: actions/checkout@v3
3960

@@ -75,9 +96,9 @@ jobs:
7596
needs: build-and-push-image
7697
runs-on: ubuntu-latest
7798
env:
78-
CONTAINER_REGISTRY_SERVER_URL_DEV: "dkumlinacrdemo.azurecr.io"
79-
IMAGE_NAME_DEV: "dkumlin-demo-image"
80-
WEB_APP: "dkumlin-demo-web-app"
99+
CONTAINER_REGISTRY_SERVER_URL_DEV: "apuligaacrdemo.azurecr.io"
100+
IMAGE_NAME_DEV: "apuliga-demo-image"
101+
WEB_APP: "apuliga-demo-web-app"
81102
steps:
82103
- name: Login to Azure CLI
83104
uses: azure/login@v1

.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: 9 additions & 3 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
@@ -68,7 +74,7 @@ Created `.github/workflows/workflow.yaml` with three main stages:
6874
1. **Fork/Clone the Repository**
6975

7076
2. **Update Parameters**
71-
Replace all instances of `dkumlin` with your identifier in:
77+
Replace all instances of `yourname` with your identifier in:
7278

7379
```json
7480
// main.parameters.json

main.parameters.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
"value": "westeurope"
77
},
88
"acrName": {
9-
"value": "dkumlinacrdemo"
9+
"value": "apuligaacrdemo"
1010
},
1111
"appServicePlanName": {
12-
"value": "dkumlin-demo-service-plan"
12+
"value": "apuliga-demo-service-plan"
1313
},
1414
"webAppName": {
15-
"value": "dkumlin-demo-web-app"
15+
"value": "apuliga-demo-web-app"
1616
},
1717
"containerRegistryImageName": {
18-
"value": "dkumlin-demo-image"
18+
"value": "apuliga-demo-image"
1919
},
2020
"containerRegistryImageVersion": {
2121
"value": "latest"
2222
},
2323
"keyVaultName": {
24-
"value": "dkumlin-demo-kvtest"
24+
"value": "apuliga-demo-kvtest"
2525
},
2626
"keyVaultRoleAssignments": {
2727
"value": [
@@ -38,4 +38,4 @@
3838
]
3939
}
4040
}
41-
}
41+
}

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)