File tree Expand file tree Collapse file tree 11 files changed +78
-201
lines changed Expand file tree Collapse file tree 11 files changed +78
-201
lines changed Load Diff This file was deleted.
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 25
25
template : ./main.bicep
26
26
parameters : ./main.parameters.json
27
27
28
- build-and-push-image :
28
+ run-tests :
29
+ runs-on : ubuntu-latest
29
30
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]
30
51
runs-on : ubuntu-latest
31
52
env :
32
53
KEY_VAULT_NAME_DEV : " dkumlin-demo-kvtest"
Original file line number Diff line number Diff line change
1
+ {
2
+ "python.testing.pytestArgs" : [
3
+ " tests"
4
+ ],
5
+ "python.testing.unittestEnabled" : false ,
6
+ "python.testing.pytestEnabled" : true
7
+ }
Load Diff This file was deleted.
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -43,13 +43,19 @@ Created `.github/workflows/workflow.yaml` with three main stages:
43
43
- Creates/updates Azure resources
44
44
- Sets up RBAC permissions
45
45
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**
47
53
48
54
- Builds the Docker image
49
55
- Tags with git SHA
50
56
- Pushes to Azure Container Registry
51
57
52
- 3 . ** Web App Deployment Stage**
58
+ 4 . ** Web App Deployment Stage**
53
59
- Pulls latest image from ACR
54
60
- Deploys to Azure Web App
55
61
- Updates container configuration
Original file line number Diff line number Diff line change 1
1
Flask == 2.2.2
2
2
gunicorn
3
- Werkzeug == 2.2.2
3
+ Werkzeug == 2.2.2
Original file line number Diff line number Diff line change
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" ] == "/"
You can’t perform that action at this time.
0 commit comments