From a89e9a2bac3e6b35bd7af3d930f00b6a16c7810e Mon Sep 17 00:00:00 2001 From: Andrew Hosgood Date: Mon, 19 Aug 2024 19:07:04 +0100 Subject: [PATCH 1/4] Create Docker image for test application --- .github/workflows/ci.yml | 17 ++- docker-compose.yml | 14 +++ package.json | 1 - test-fixtures.mjs | 19 +-- test/Dockerfile | 8 ++ test/__init__.py | 3 - test/app/__init__.py | 19 ++- test/app/components/__init__.py | 2 +- test/app/components/routes.py | 2 +- test/app/templates/__init__.py | 2 +- test/app/templates/routes.py | 2 +- test/app/utilities/__init__.py | 2 +- test/app/utilities/routes.py | 2 +- test/poetry.lock | 214 ++++++++++++++++++++++++++++++++ test/pyproject.toml | 17 +++ test/requirements.txt | 5 - 16 files changed, 288 insertions(+), 41 deletions(-) create mode 100644 docker-compose.yml create mode 100644 test/Dockerfile delete mode 100644 test/__init__.py create mode 100644 test/poetry.lock create mode 100644 test/pyproject.toml delete mode 100644 test/requirements.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4e65845..8a15a8a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,12 +8,19 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 + - uses: actions/setup-python@v5 with: - python-version: '3.x' - - name: Install Python requirements - run: pip install -r test/requirements.txt + python-version: 3.12 + - uses: snok/install-poetry@v1 + with: + version: 1.8.1 + virtualenvs-create: true + virtualenvs-in-project: true + virtualenvs-path: .venv + - name: Install Poetry dependencies + run: | + cd test + poetry install --no-interaction --no-root - name: Run server run: flask --app test run --debug --port 5000 & - name: Install Node dependencies diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c639bc1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +services: + app: + build: + # context: test + dockerfile: test/Dockerfile + environment: + - ENVIRONMENT=develop + - CONFIG=config.Develop + - SECRET_KEY=abc123 + ports: + - 5000:8080 + volumes: + - ./test:/app + - ./tna_frontend_jinja:/home/app/tna_frontend_jinja diff --git a/package.json b/package.json index 0b1a530..b4819d3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,6 @@ { "scripts": { "prettier": "prettier --write '*.{mjs,json}'", - "run": "flask --app test run --debug --port 5000", "test": "node test-fixtures.mjs" }, "dependencies": { diff --git a/test-fixtures.mjs b/test-fixtures.mjs index a1cb5af..e2d45b6 100644 --- a/test-fixtures.mjs +++ b/test-fixtures.mjs @@ -93,7 +93,8 @@ for (let i = 0; i < components.length; i++) { const diff = diffChars(bodyPretty, fixturePretty) .map( (part) => - `${part.added ? "\x1b[32m" : part.removed ? "\x1b[31m" : "\x1b[0m" + `${ + part.added ? "\x1b[32m" : part.removed ? "\x1b[31m" : "\x1b[0m" }${part.value === " " ? "█" : part.value}`, ) .join(""); @@ -171,7 +172,8 @@ for (let i = 0; i < utilities.length; i++) { const diff = diffChars(bodyPretty, fixturePretty) .map( (part) => - `${part.added ? "\x1b[32m" : part.removed ? "\x1b[31m" : "\x1b[0m" + `${ + part.added ? "\x1b[32m" : part.removed ? "\x1b[31m" : "\x1b[0m" }${part.value === " " ? "█" : part.value}`, ) .join(""); @@ -189,12 +191,10 @@ for (let i = 0; i < utilities.length; i++) { const templatesDirectory = `${tnaFrontendDirectory}/nationalarchives/templates/`; const { fixtures } = JSON.parse( - fs.readFileSync(`${templatesDirectory}fixtures.json`, - "utf8", - ), + fs.readFileSync(`${templatesDirectory}fixtures.json`, "utf8"), ); -const genericFixture = fixtures.find(fixture => fixture.name === "generic") -const testUrl = `${testEndpoint}templates/base` +const genericFixture = fixtures.find((fixture) => fixture.name === "generic"); +const testUrl = `${testEndpoint}templates/base`; console.log("\nTemplates"); const response = await fetch(testUrl) .then((response) => { @@ -218,7 +218,8 @@ if (mismatch) { const diff = diffChars(bodyPretty, fixturePretty) .map( (part) => - `${part.added ? "\x1b[32m" : part.removed ? "\x1b[31m" : "\x1b[0m" + `${ + part.added ? "\x1b[32m" : part.removed ? "\x1b[31m" : "\x1b[0m" }${part.value === " " ? "█" : part.value}`, ) .join(""); @@ -230,4 +231,4 @@ if (mismatch) { throw new Error("Fixtures tests failed"); } else { pass(genericFixture.name); -} \ No newline at end of file +} diff --git a/test/Dockerfile b/test/Dockerfile new file mode 100644 index 0000000..c11d1d1 --- /dev/null +++ b/test/Dockerfile @@ -0,0 +1,8 @@ +FROM ghcr.io/nationalarchives/tna-python:latest + +COPY --chown=app test . +COPY --chown=app ../tna_frontend_jinja /home/app/tna_frontend_jinja + +RUN tna-build + +CMD ["tna-run", "app:app"] \ No newline at end of file diff --git a/test/__init__.py b/test/__init__.py deleted file mode 100644 index 793f52d..0000000 --- a/test/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from .app import create_app - -app = create_app() diff --git a/test/app/__init__.py b/test/app/__init__.py index a9264e3..bc24781 100644 --- a/test/app/__init__.py +++ b/test/app/__init__.py @@ -1,15 +1,10 @@ from flask import Flask +from .components import bp as components_bp +from .utilities import bp as utilities_bp +from .templates import bp as templates_bp +app = Flask(__name__, template_folder="/home/app/tna_frontend_jinja/templates") -def create_app(): - app = Flask(__name__, template_folder="../../tna_frontend_jinja/templates") - - from .components import bp as components_bp - from .utilities import bp as utilities_bp - from .templates import bp as templates_bp - - app.register_blueprint(components_bp, url_prefix="/components") - app.register_blueprint(utilities_bp, url_prefix="/utilities") - app.register_blueprint(templates_bp, url_prefix="/templates") - - return app +app.register_blueprint(components_bp, url_prefix="/components") +app.register_blueprint(utilities_bp, url_prefix="/utilities") +app.register_blueprint(templates_bp, url_prefix="/templates") diff --git a/test/app/components/__init__.py b/test/app/components/__init__.py index 8d3e784..247a085 100644 --- a/test/app/components/__init__.py +++ b/test/app/components/__init__.py @@ -2,4 +2,4 @@ bp = Blueprint("components", __name__, template_folder="test-templates") -from test.app.components import routes # noqa: E402,F401 +from app.components import routes # noqa: E402,F401 diff --git a/test/app/components/routes.py b/test/app/components/routes.py index a58e27c..ca63e2f 100644 --- a/test/app/components/routes.py +++ b/test/app/components/routes.py @@ -1,5 +1,5 @@ import json -from test.app.components import bp +from app.components import bp from flask import render_template, request diff --git a/test/app/templates/__init__.py b/test/app/templates/__init__.py index 1c9dab5..5377074 100644 --- a/test/app/templates/__init__.py +++ b/test/app/templates/__init__.py @@ -2,4 +2,4 @@ bp = Blueprint("templates", __name__, template_folder="../templates") -from test.app.templates import routes # noqa: E402,F401 +from app.templates import routes # noqa: E402,F401 diff --git a/test/app/templates/routes.py b/test/app/templates/routes.py index b810e3c..1c76132 100644 --- a/test/app/templates/routes.py +++ b/test/app/templates/routes.py @@ -1,5 +1,5 @@ import json -from test.app.templates import bp +from app.templates import bp from flask import render_template, request diff --git a/test/app/utilities/__init__.py b/test/app/utilities/__init__.py index 8f2c66d..c436436 100644 --- a/test/app/utilities/__init__.py +++ b/test/app/utilities/__init__.py @@ -2,4 +2,4 @@ bp = Blueprint("utilities", __name__, template_folder="test-templates") -from test.app.utilities import routes # noqa: E402,F401 +from app.utilities import routes # noqa: E402,F401 diff --git a/test/app/utilities/routes.py b/test/app/utilities/routes.py index 1cad905..121d323 100644 --- a/test/app/utilities/routes.py +++ b/test/app/utilities/routes.py @@ -1,5 +1,5 @@ import json -from test.app.utilities import bp +from app.utilities import bp from flask import render_template, request diff --git a/test/poetry.lock b/test/poetry.lock new file mode 100644 index 0000000..c01e611 --- /dev/null +++ b/test/poetry.lock @@ -0,0 +1,214 @@ +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. + +[[package]] +name = "blinker" +version = "1.8.2" +description = "Fast, simple object-to-object and broadcast signaling" +optional = false +python-versions = ">=3.8" +files = [ + {file = "blinker-1.8.2-py3-none-any.whl", hash = "sha256:1779309f71bf239144b9399d06ae925637cf6634cf6bd131104184531bf67c01"}, + {file = "blinker-1.8.2.tar.gz", hash = "sha256:8f77b09d3bf7c795e969e9486f39c2c5e9c39d4ee07424be2bc594ece9642d83"}, +] + +[[package]] +name = "click" +version = "8.1.7" +description = "Composable command line interface toolkit" +optional = false +python-versions = ">=3.7" +files = [ + {file = "click-8.1.7-py3-none-any.whl", hash = "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28"}, + {file = "click-8.1.7.tar.gz", hash = "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "platform_system == \"Windows\""} + +[[package]] +name = "colorama" +version = "0.4.6" +description = "Cross-platform colored terminal text." +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +files = [ + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, +] + +[[package]] +name = "flask" +version = "3.0.3" +description = "A simple framework for building complex web applications." +optional = false +python-versions = ">=3.8" +files = [ + {file = "flask-3.0.3-py3-none-any.whl", hash = "sha256:34e815dfaa43340d1d15a5c3a02b8476004037eb4840b34910c6e21679d288f3"}, + {file = "flask-3.0.3.tar.gz", hash = "sha256:ceb27b0af3823ea2737928a4d99d125a06175b8512c445cbd9a9ce200ef76842"}, +] + +[package.dependencies] +blinker = ">=1.6.2" +click = ">=8.1.3" +itsdangerous = ">=2.1.2" +Jinja2 = ">=3.1.2" +Werkzeug = ">=3.0.0" + +[package.extras] +async = ["asgiref (>=3.2)"] +dotenv = ["python-dotenv"] + +[[package]] +name = "flask-wtf" +version = "1.2.1" +description = "Form rendering, validation, and CSRF protection for Flask with WTForms." +optional = false +python-versions = ">=3.8" +files = [ + {file = "flask_wtf-1.2.1-py3-none-any.whl", hash = "sha256:fa6793f2fb7e812e0fe9743b282118e581fb1b6c45d414b8af05e659bd653287"}, + {file = "flask_wtf-1.2.1.tar.gz", hash = "sha256:8bb269eb9bb46b87e7c8233d7e7debdf1f8b74bf90cc1789988c29b37a97b695"}, +] + +[package.dependencies] +flask = "*" +itsdangerous = "*" +wtforms = "*" + +[package.extras] +email = ["email-validator"] + +[[package]] +name = "itsdangerous" +version = "2.2.0" +description = "Safely pass data to untrusted environments and back." +optional = false +python-versions = ">=3.8" +files = [ + {file = "itsdangerous-2.2.0-py3-none-any.whl", hash = "sha256:c6242fc49e35958c8b15141343aa660db5fc54d4f13a1db01a3f5891b98700ef"}, + {file = "itsdangerous-2.2.0.tar.gz", hash = "sha256:e0050c0b7da1eea53ffaf149c0cfbb5c6e2e2b69c4bef22c81fa6eb73e5f6173"}, +] + +[[package]] +name = "jinja2" +version = "3.1.4" +description = "A very fast and expressive template engine." +optional = false +python-versions = ">=3.7" +files = [ + {file = "jinja2-3.1.4-py3-none-any.whl", hash = "sha256:bc5dd2abb727a5319567b7a813e6a2e7318c39f4f487cfe6c89c6f9c7d25197d"}, + {file = "jinja2-3.1.4.tar.gz", hash = "sha256:4a3aee7acbbe7303aede8e9648d13b8bf88a429282aa6122a993f0ac800cb369"}, +] + +[package.dependencies] +MarkupSafe = ">=2.0" + +[package.extras] +i18n = ["Babel (>=2.7)"] + +[[package]] +name = "markupsafe" +version = "2.1.5" +description = "Safely add untrusted strings to HTML/XML markup." +optional = false +python-versions = ">=3.7" +files = [ + {file = "MarkupSafe-2.1.5-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:a17a92de5231666cfbe003f0e4b9b3a7ae3afb1ec2845aadc2bacc93ff85febc"}, + {file = "MarkupSafe-2.1.5-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:72b6be590cc35924b02c78ef34b467da4ba07e4e0f0454a2c5907f473fc50ce5"}, + {file = "MarkupSafe-2.1.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e61659ba32cf2cf1481e575d0462554625196a1f2fc06a1c777d3f48e8865d46"}, + {file = "MarkupSafe-2.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2174c595a0d73a3080ca3257b40096db99799265e1c27cc5a610743acd86d62f"}, + {file = "MarkupSafe-2.1.5-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:ae2ad8ae6ebee9d2d94b17fb62763125f3f374c25618198f40cbb8b525411900"}, + {file = "MarkupSafe-2.1.5-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:075202fa5b72c86ad32dc7d0b56024ebdbcf2048c0ba09f1cde31bfdd57bcfff"}, + {file = "MarkupSafe-2.1.5-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:598e3276b64aff0e7b3451b72e94fa3c238d452e7ddcd893c3ab324717456bad"}, + {file = "MarkupSafe-2.1.5-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:fce659a462a1be54d2ffcacea5e3ba2d74daa74f30f5f143fe0c58636e355fdd"}, + {file = "MarkupSafe-2.1.5-cp310-cp310-win32.whl", hash = "sha256:d9fad5155d72433c921b782e58892377c44bd6252b5af2f67f16b194987338a4"}, + {file = "MarkupSafe-2.1.5-cp310-cp310-win_amd64.whl", hash = "sha256:bf50cd79a75d181c9181df03572cdce0fbb75cc353bc350712073108cba98de5"}, + {file = "MarkupSafe-2.1.5-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:629ddd2ca402ae6dbedfceeba9c46d5f7b2a61d9749597d4307f943ef198fc1f"}, + {file = "MarkupSafe-2.1.5-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:5b7b716f97b52c5a14bffdf688f971b2d5ef4029127f1ad7a513973cfd818df2"}, + {file = "MarkupSafe-2.1.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6ec585f69cec0aa07d945b20805be741395e28ac1627333b1c5b0105962ffced"}, + {file = "MarkupSafe-2.1.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b91c037585eba9095565a3556f611e3cbfaa42ca1e865f7b8015fe5c7336d5a5"}, + {file = "MarkupSafe-2.1.5-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7502934a33b54030eaf1194c21c692a534196063db72176b0c4028e140f8f32c"}, + {file = "MarkupSafe-2.1.5-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:0e397ac966fdf721b2c528cf028494e86172b4feba51d65f81ffd65c63798f3f"}, + {file = "MarkupSafe-2.1.5-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:c061bb86a71b42465156a3ee7bd58c8c2ceacdbeb95d05a99893e08b8467359a"}, + {file = "MarkupSafe-2.1.5-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:3a57fdd7ce31c7ff06cdfbf31dafa96cc533c21e443d57f5b1ecc6cdc668ec7f"}, + {file = "MarkupSafe-2.1.5-cp311-cp311-win32.whl", hash = "sha256:397081c1a0bfb5124355710fe79478cdbeb39626492b15d399526ae53422b906"}, + {file = "MarkupSafe-2.1.5-cp311-cp311-win_amd64.whl", hash = "sha256:2b7c57a4dfc4f16f7142221afe5ba4e093e09e728ca65c51f5620c9aaeb9a617"}, + {file = "MarkupSafe-2.1.5-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:8dec4936e9c3100156f8a2dc89c4b88d5c435175ff03413b443469c7c8c5f4d1"}, + {file = "MarkupSafe-2.1.5-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:3c6b973f22eb18a789b1460b4b91bf04ae3f0c4234a0a6aa6b0a92f6f7b951d4"}, + {file = "MarkupSafe-2.1.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ac07bad82163452a6884fe8fa0963fb98c2346ba78d779ec06bd7a6262132aee"}, + {file = "MarkupSafe-2.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f5dfb42c4604dddc8e4305050aa6deb084540643ed5804d7455b5df8fe16f5e5"}, + {file = "MarkupSafe-2.1.5-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:ea3d8a3d18833cf4304cd2fc9cbb1efe188ca9b5efef2bdac7adc20594a0e46b"}, + {file = "MarkupSafe-2.1.5-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:d050b3361367a06d752db6ead6e7edeb0009be66bc3bae0ee9d97fb326badc2a"}, + {file = "MarkupSafe-2.1.5-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:bec0a414d016ac1a18862a519e54b2fd0fc8bbfd6890376898a6c0891dd82e9f"}, + {file = "MarkupSafe-2.1.5-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:58c98fee265677f63a4385256a6d7683ab1832f3ddd1e66fe948d5880c21a169"}, + {file = "MarkupSafe-2.1.5-cp312-cp312-win32.whl", hash = "sha256:8590b4ae07a35970728874632fed7bd57b26b0102df2d2b233b6d9d82f6c62ad"}, + {file = "MarkupSafe-2.1.5-cp312-cp312-win_amd64.whl", hash = "sha256:823b65d8706e32ad2df51ed89496147a42a2a6e01c13cfb6ffb8b1e92bc910bb"}, + {file = "MarkupSafe-2.1.5-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:c8b29db45f8fe46ad280a7294f5c3ec36dbac9491f2d1c17345be8e69cc5928f"}, + {file = "MarkupSafe-2.1.5-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ec6a563cff360b50eed26f13adc43e61bc0c04d94b8be985e6fb24b81f6dcfdf"}, + {file = "MarkupSafe-2.1.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a549b9c31bec33820e885335b451286e2969a2d9e24879f83fe904a5ce59d70a"}, + {file = "MarkupSafe-2.1.5-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:4f11aa001c540f62c6166c7726f71f7573b52c68c31f014c25cc7901deea0b52"}, + {file = "MarkupSafe-2.1.5-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:7b2e5a267c855eea6b4283940daa6e88a285f5f2a67f2220203786dfa59b37e9"}, + {file = "MarkupSafe-2.1.5-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:2d2d793e36e230fd32babe143b04cec8a8b3eb8a3122d2aceb4a371e6b09b8df"}, + {file = "MarkupSafe-2.1.5-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:ce409136744f6521e39fd8e2a24c53fa18ad67aa5bc7c2cf83645cce5b5c4e50"}, + {file = "MarkupSafe-2.1.5-cp37-cp37m-win32.whl", hash = "sha256:4096e9de5c6fdf43fb4f04c26fb114f61ef0bf2e5604b6ee3019d51b69e8c371"}, + {file = "MarkupSafe-2.1.5-cp37-cp37m-win_amd64.whl", hash = "sha256:4275d846e41ecefa46e2015117a9f491e57a71ddd59bbead77e904dc02b1bed2"}, + {file = "MarkupSafe-2.1.5-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:656f7526c69fac7f600bd1f400991cc282b417d17539a1b228617081106feb4a"}, + {file = "MarkupSafe-2.1.5-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:97cafb1f3cbcd3fd2b6fbfb99ae11cdb14deea0736fc2b0952ee177f2b813a46"}, + {file = "MarkupSafe-2.1.5-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1f3fbcb7ef1f16e48246f704ab79d79da8a46891e2da03f8783a5b6fa41a9532"}, + {file = "MarkupSafe-2.1.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fa9db3f79de01457b03d4f01b34cf91bc0048eb2c3846ff26f66687c2f6d16ab"}, + {file = "MarkupSafe-2.1.5-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:ffee1f21e5ef0d712f9033568f8344d5da8cc2869dbd08d87c84656e6a2d2f68"}, + {file = "MarkupSafe-2.1.5-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:5dedb4db619ba5a2787a94d877bc8ffc0566f92a01c0ef214865e54ecc9ee5e0"}, + {file = "MarkupSafe-2.1.5-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:30b600cf0a7ac9234b2638fbc0fb6158ba5bdcdf46aeb631ead21248b9affbc4"}, + {file = "MarkupSafe-2.1.5-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:8dd717634f5a044f860435c1d8c16a270ddf0ef8588d4887037c5028b859b0c3"}, + {file = "MarkupSafe-2.1.5-cp38-cp38-win32.whl", hash = "sha256:daa4ee5a243f0f20d528d939d06670a298dd39b1ad5f8a72a4275124a7819eff"}, + {file = "MarkupSafe-2.1.5-cp38-cp38-win_amd64.whl", hash = "sha256:619bc166c4f2de5caa5a633b8b7326fbe98e0ccbfacabd87268a2b15ff73a029"}, + {file = "MarkupSafe-2.1.5-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:7a68b554d356a91cce1236aa7682dc01df0edba8d043fd1ce607c49dd3c1edcf"}, + {file = "MarkupSafe-2.1.5-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:db0b55e0f3cc0be60c1f19efdde9a637c32740486004f20d1cff53c3c0ece4d2"}, + {file = "MarkupSafe-2.1.5-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3e53af139f8579a6d5f7b76549125f0d94d7e630761a2111bc431fd820e163b8"}, + {file = "MarkupSafe-2.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:17b950fccb810b3293638215058e432159d2b71005c74371d784862b7e4683f3"}, + {file = "MarkupSafe-2.1.5-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:4c31f53cdae6ecfa91a77820e8b151dba54ab528ba65dfd235c80b086d68a465"}, + {file = "MarkupSafe-2.1.5-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:bff1b4290a66b490a2f4719358c0cdcd9bafb6b8f061e45c7a2460866bf50c2e"}, + {file = "MarkupSafe-2.1.5-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:bc1667f8b83f48511b94671e0e441401371dfd0f0a795c7daa4a3cd1dde55bea"}, + {file = "MarkupSafe-2.1.5-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:5049256f536511ee3f7e1b3f87d1d1209d327e818e6ae1365e8653d7e3abb6a6"}, + {file = "MarkupSafe-2.1.5-cp39-cp39-win32.whl", hash = "sha256:00e046b6dd71aa03a41079792f8473dc494d564611a8f89bbbd7cb93295ebdcf"}, + {file = "MarkupSafe-2.1.5-cp39-cp39-win_amd64.whl", hash = "sha256:fa173ec60341d6bb97a89f5ea19c85c5643c1e7dedebc22f5181eb73573142c5"}, + {file = "MarkupSafe-2.1.5.tar.gz", hash = "sha256:d283d37a890ba4c1ae73ffadf8046435c76e7bc2247bbb63c00bd1a709c6544b"}, +] + +[[package]] +name = "werkzeug" +version = "3.0.3" +description = "The comprehensive WSGI web application library." +optional = false +python-versions = ">=3.8" +files = [ + {file = "werkzeug-3.0.3-py3-none-any.whl", hash = "sha256:fc9645dc43e03e4d630d23143a04a7f947a9a3b5727cd535fdfe155a17cc48c8"}, + {file = "werkzeug-3.0.3.tar.gz", hash = "sha256:097e5bfda9f0aba8da6b8545146def481d06aa7d3266e7448e2cccf67dd8bd18"}, +] + +[package.dependencies] +MarkupSafe = ">=2.1.1" + +[package.extras] +watchdog = ["watchdog (>=2.3)"] + +[[package]] +name = "wtforms" +version = "3.1.2" +description = "Form validation and rendering for Python web development." +optional = false +python-versions = ">=3.8" +files = [ + {file = "wtforms-3.1.2-py3-none-any.whl", hash = "sha256:bf831c042829c8cdbad74c27575098d541d039b1faa74c771545ecac916f2c07"}, + {file = "wtforms-3.1.2.tar.gz", hash = "sha256:f8d76180d7239c94c6322f7990ae1216dae3659b7aa1cee94b6318bdffb474b9"}, +] + +[package.dependencies] +markupsafe = "*" + +[package.extras] +email = ["email-validator"] + +[metadata] +lock-version = "2.0" +python-versions = "^3.12" +content-hash = "4f23bebdccf7082b26f918d2208d484dc28705552eee81092989b79e70d6981e" diff --git a/test/pyproject.toml b/test/pyproject.toml new file mode 100644 index 0000000..8445cdb --- /dev/null +++ b/test/pyproject.toml @@ -0,0 +1,17 @@ +[tool.poetry] +name = "tna-frontend-jinja-test" +version = "0.1.0" +description = "" +authors = ["Andrew Hosgood "] +license = "MIT" +readme = "README.md" + +[tool.poetry.dependencies] +python = "^3.12" +Flask = "^3.0.3" +Flask-WTF = "^1.2.1" + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/test/requirements.txt b/test/requirements.txt deleted file mode 100644 index 7af6db2..0000000 --- a/test/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -black==23.3.0 -django==4.2.2 -flake8==6.0.0 -flask==2.3.2 -isort==5.12.0 \ No newline at end of file From 649473fb8522e12bd16b9bb5c2172f59293ec498 Mon Sep 17 00:00:00 2001 From: Andrew Hosgood Date: Tue, 20 Aug 2024 09:57:30 +0100 Subject: [PATCH 2/4] Update Docker port to 5001, fix workflows --- .github/workflows/ci.yml | 17 ++--------------- .github/workflows/python-publish.yml | 13 +++++-------- README.md | 5 ++--- docker-compose.yml | 2 +- test-fixtures.mjs | 2 +- 5 files changed, 11 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a15a8a..e7aae97 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,22 +8,9 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: 3.12 - - uses: snok/install-poetry@v1 - with: - version: 1.8.1 - virtualenvs-create: true - virtualenvs-in-project: true - virtualenvs-path: .venv - - name: Install Poetry dependencies - run: | - cd test - poetry install --no-interaction --no-root - - name: Run server - run: flask --app test run --debug --port 5000 & - name: Install Node dependencies run: npm install + - name: Start test server + run: docker compose up web -d - name: Run the tests run: node test-fixtures.mjs || exit 1 diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index f56c227..3528117 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -4,22 +4,19 @@ on: release: types: [published] +concurrency: + group: deploy-${{ github.ref }} + jobs: test: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - name: Install Python requirements - run: pip install -r test/requirements.txt - - name: Run server - run: flask --app test run --debug --port 5000 & - name: Install Node dependencies run: npm install + - name: Start test server + run: docker compose up web -d - name: Run the tests run: node test-fixtures.mjs || exit 1 diff --git a/README.md b/README.md index b524b4b..badbe45 100644 --- a/README.md +++ b/README.md @@ -97,8 +97,7 @@ We test each component against its published [component fixtures](https://github ## Test the templates ```sh -python -m venv venv -python install -r test/requirements.txt -flask --app test run --debug --port 5000 +npm install +docker compose up web -d node test-fixtures.mjs ``` diff --git a/docker-compose.yml b/docker-compose.yml index c639bc1..01c6176 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: - CONFIG=config.Develop - SECRET_KEY=abc123 ports: - - 5000:8080 + - 5001:8080 volumes: - ./test:/app - ./tna_frontend_jinja:/home/app/tna_frontend_jinja diff --git a/test-fixtures.mjs b/test-fixtures.mjs index e2d45b6..ea48a63 100644 --- a/test-fixtures.mjs +++ b/test-fixtures.mjs @@ -13,7 +13,7 @@ const fail = (message) => { }; console.log("Running tests..."); -const testEndpoint = "http://127.0.0.1:5000/"; +const testEndpoint = "http://127.0.0.1:5001/"; const standardiseHtml = (html) => html_beautify( html From f12e81bbf9157e9554b6c58ceed01234ad7ebb96 Mon Sep 17 00:00:00 2001 From: Andrew Hosgood Date: Tue, 20 Aug 2024 10:00:09 +0100 Subject: [PATCH 3/4] Remove app name from Docker up --- .github/workflows/ci.yml | 2 +- .github/workflows/python-publish.yml | 2 +- README.md | 2 +- package-lock.json | 17 +---------------- package.json | 5 ++--- 5 files changed, 6 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e7aae97..b955e95 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,6 @@ jobs: - name: Install Node dependencies run: npm install - name: Start test server - run: docker compose up web -d + run: docker compose up -d - name: Run the tests run: node test-fixtures.mjs || exit 1 diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 3528117..3e14821 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -16,7 +16,7 @@ jobs: - name: Install Node dependencies run: npm install - name: Start test server - run: docker compose up web -d + run: docker compose up -d - name: Run the tests run: node test-fixtures.mjs || exit 1 diff --git a/README.md b/README.md index badbe45..46a9533 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,6 @@ We test each component against its published [component fixtures](https://github ```sh npm install -docker compose up web -d +docker compose up -d node test-fixtures.mjs ``` diff --git a/package-lock.json b/package-lock.json index 66ffa0c..0a2ca7d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,8 +9,7 @@ "diff": "^5.1.0", "glob": "^10.2.7", "js-beautify": "^1.14.8", - "node-fetch": "^3.3.1", - "prettier": "^3.2.5" + "node-fetch": "^3.3.1" } }, "node_modules/@isaacs/cliui": { @@ -429,20 +428,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/prettier": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.2.tgz", - "integrity": "sha512-rAVeHYMcv8ATV5d508CFdn+8/pHPpXeIid1DdrPwXnaAdH7cqjVbpJaT5eq4yRAFU/lsbwYwSF/n5iNrdJHPQA==", - "bin": { - "prettier": "bin/prettier.cjs" - }, - "engines": { - "node": ">=14" - }, - "funding": { - "url": "https://github.com/prettier/prettier?sponsor=1" - } - }, "node_modules/proto-list": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/proto-list/-/proto-list-1.2.4.tgz", diff --git a/package.json b/package.json index b4819d3..f6cfc74 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "scripts": { - "prettier": "prettier --write '*.{mjs,json}'", + "prettier": "npx --yes prettier --write '*.{mjs,json}'", "test": "node test-fixtures.mjs" }, "dependencies": { @@ -8,7 +8,6 @@ "diff": "^5.1.0", "glob": "^10.2.7", "js-beautify": "^1.14.8", - "node-fetch": "^3.3.1", - "prettier": "^3.2.5" + "node-fetch": "^3.3.1" } } From 396a9408177c4c0bc6ca35229a745b0e14365051 Mon Sep 17 00:00:00 2001 From: Andrew Hosgood Date: Tue, 20 Aug 2024 10:02:35 +0100 Subject: [PATCH 4/4] Wait for Docker image to be ready --- .github/workflows/ci.yml | 4 ++++ .github/workflows/python-publish.yml | 4 ++++ test/app/__init__.py | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b955e95..aa33256 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,5 +12,9 @@ jobs: run: npm install - name: Start test server run: docker compose up -d + - name: Wait for response + uses: nev7n/wait_for_response@v1 + with: + url: http://localhost:5001/ready/ - name: Run the tests run: node test-fixtures.mjs || exit 1 diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 3e14821..ed068eb 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -17,6 +17,10 @@ jobs: run: npm install - name: Start test server run: docker compose up -d + - name: Wait for response + uses: nev7n/wait_for_response@v1 + with: + url: http://localhost:5001/ready/ - name: Run the tests run: node test-fixtures.mjs || exit 1 diff --git a/test/app/__init__.py b/test/app/__init__.py index bc24781..31d9065 100644 --- a/test/app/__init__.py +++ b/test/app/__init__.py @@ -5,6 +5,12 @@ app = Flask(__name__, template_folder="/home/app/tna_frontend_jinja/templates") + +@app.route("/ready/") +def ready(): + return "ok" + + app.register_blueprint(components_bp, url_prefix="/components") app.register_blueprint(utilities_bp, url_prefix="/utilities") app.register_blueprint(templates_bp, url_prefix="/templates")