Skip to content

Commit 009decd

Browse files
committed
Adding tests for maintenance mode pages
1 parent 6fa2fa4 commit 009decd

File tree

6 files changed

+44
-6
lines changed

6 files changed

+44
-6
lines changed

.github/workflows/test.yml

+5
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@ jobs:
2323
run: |
2424
python -m pip install --upgrade pip
2525
python -m pip install -r requirements/generated/requirements-development.txt
26+
2627
2728
- name: Unit test with pytest
2829
run: |
2930
pip install pytest pytest-cov
31+
# This is required because at the moment the assets are being built in the app
32+
# When the app tries to access sass files in node_modules it will fail unless this is included
33+
npm install
34+
3035
coverage run -m pytest tests/unit_tests
3136
coverage xml
3237

app/static/src/scss/custom.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Example of a custom SCSS file which is combined into one SCSS application file by Flask Assets */
2-
@import "node_modules/govuk-frontend/dist/govuk/settings/index";
2+
@import "node_modules/govuk-frontend/dist/govuk/settings/index.css";
33

44
/* Example below of using GOVUK frontend SCSS variables in custom SCSS */
55
.moj-skeleton {
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Import GOVUK frontend SCSS to be compiled to CSS */
2-
@import "node_modules/govuk-frontend/dist/govuk/all";
2+
@import "node_modules/govuk-frontend/dist/govuk/all.css";
33

44
/* Import your custom SCSS below to be compiled into one by Flask Assets */
55
@import "./custom";

tests/unit_tests/conftest.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import pytest
2+
from app import Config
3+
from app import create_app
4+
5+
6+
class TestConfig(Config):
7+
TESTING = True
8+
DEBUG = True
9+
SERVER_NAME = "localhost"
10+
RATELIMIT_ENABLED = False
11+
SECRET_KEY = "TEST_KEY"
12+
13+
14+
@pytest.fixture(scope="session")
15+
def app():
16+
app = create_app(TestConfig)
17+
yield app
18+
19+
20+
@pytest.fixture()
21+
def client(app):
22+
return app.test_client()

tests/unit_tests/test_example.py

-4
This file was deleted.

tests/unit_tests/test_pages.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def test_maintenance_page_on(app, client):
2+
app.config["MAINTENANCE_MODE"] = True
3+
response = client.get("/")
4+
assert response.status_code == 302
5+
assert response.headers["location"] == "/maintenance-mode"
6+
response = client.get("/", follow_redirects=True)
7+
assert response.status_code == 503
8+
assert response.request.path == "/maintenance-mode"
9+
10+
11+
def test_maintenance_page_off(app, client):
12+
app.config["MAINTENANCE_MODE"] = False
13+
response = client.get("/maintenance-mode", follow_redirects=True)
14+
assert response.status_code == 200
15+
assert response.request.path == "/"

0 commit comments

Comments
 (0)