Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…a-webapp into AYR-390/footer-component
  • Loading branch information
zaiziclebby committed Nov 2, 2023
2 parents 495d183 + be2670a commit 7534be7
Show file tree
Hide file tree
Showing 49 changed files with 1,272 additions and 1,467 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/pre_commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Pre-commit check
on:
pull_request:
branches: ["main"]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]
6 changes: 3 additions & 3 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.11"]

steps:
- uses: actions/checkout@v3
Expand All @@ -27,9 +27,9 @@ jobs:
- name: Check dependencies for known security vulnerabilities
run: safety check -r requirements.txt
- name: Check code for potential security vulnerabilities
run: bandit -r .
run: bandit -c pyproject.toml -r .
- name: Check code formatting
run: black . -l 120 --check
run: black . --check
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Run Unit Tests

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
unit_test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.11

- name: Install Poetry
run: pip install poetry

- name: Install dependencies
run: poetry install

- name: Run Pytest tests
run: AWS_DEFAULT_REGION=eu-west-2 poetry run pytest --cov=app/main --cov-report term-missing -vvv app/tests/
13 changes: 10 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -23,7 +23,14 @@ repos:
- id: flake8

- repo: https://github.com/psf/black
rev: 23.9.1
rev: 23.10.0
hooks:
- id: black
language_version: python3.11
language_version: python3

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
args: ["--profile", "black", "--filter-files"]
17 changes: 7 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
# Changelog
# CHANGELOG

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/<org-or-user>/<repo-name>/compare/0.1.0...main)
It is part of the [TRE template repository](https://github.com/nationalarchives/da-tre-template)

## [0.1.0](https://github.com/<org-or-user>/<repo-name>/releases/tag/0.1.0) - dd/mm/yyyy
## [0.0.1] - 2023-01-31

### Added

### Changed

### Deprecated

### Removed
- The keep a change log CHANGELOG

### Fixed

### Security
- Minor typos
18 changes: 18 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Copyright (C) 2023 Crown Copyright (The National Archives)

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ flask run

You should now have the app running on <http://localhost:5000/>

## Demos

There are some helpful demos included by default that show all of the components available from GOV.UK Frontend Jinja and a selection of forms and validation patterns from GOV.UK Frontend WTForms. These are located in the `app/demos` and `app/templates/demos` directories, along with the `demos` blueprint. Use them for reference whilst building your service, but make sure to delete them, along with the relevant section in `build.sh`, before deploying the app.

## Testing

To run the tests:
Expand Down
40 changes: 29 additions & 11 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import boto3
from flask import Flask
from flask_assets import Bundle, Environment
from flask_compress import Compress
Expand All @@ -8,31 +9,48 @@
from govuk_frontend_wtf.main import WTFormsHelpers
from jinja2 import ChoiceLoader, PackageLoader, PrefixLoader


from config import Config

assets = Environment()
compress = Compress()
csrf = CSRFProtect()
limiter = Limiter(get_remote_address, default_limits=["2 per second", "60 per minute"])
limiter = Limiter(
get_remote_address, default_limits=["2 per second", "60 per minute"]
)
talisman = Talisman()


def null_to_dash(value):
return "—" if value == "null" else value
if value == "null":
return "-"
if value is None:
return "-"
return value


def create_app(config_class=Config):
app = Flask(__name__, static_url_path="/assets")
app.config.from_object(config_class)

force_https = False if app.config["TESTING"] else True

# use only for local development
if app.config["DEFAULT_AWS_PROFILE"]:
boto3.setup_default_session(
profile_name=app.config["DEFAULT_AWS_PROFILE"]
)

app.jinja_env.lstrip_blocks = True
app.jinja_env.trim_blocks = True
app.jinja_env.filters["null_to_dash"] = null_to_dash
app.jinja_loader = ChoiceLoader(
[
PackageLoader("app"),
PrefixLoader(
{
"govuk_frontend_jinja": PackageLoader("govuk_frontend_jinja"),
"govuk_frontend_jinja": PackageLoader(
"govuk_frontend_jinja"
),
"govuk_frontend_wtf": PackageLoader("govuk_frontend_wtf"),
}
),
Expand All @@ -45,33 +63,33 @@ def create_app(config_class=Config):
"script-src": ["'self'"],
}

app.jinja_env.filters["null_to_dash"] = null_to_dash

# Initialise app extensions
assets.init_app(app)
compress.init_app(app)
csrf.init_app(app)
limiter.init_app(app)
talisman.init_app(app, content_security_policy=csp)
talisman.init_app(app, content_security_policy=csp, force_https=force_https)
WTFormsHelpers(app)

# Create static asset bundles
css = Bundle(
"src/css/*.css", filters="cssmin", output="dist/css/custom-%(version)s.min.css"
"src/css/*.css",
filters="cssmin",
output="dist/css/custom-%(version)s.min.css",
)
js = Bundle(
"src/js/*.js", filters="jsmin", output="dist/js/custom-%(version)s.min.js"
"src/js/*.js",
filters="jsmin",
output="dist/js/custom-%(version)s.min.js",
)
if "css" not in assets:
assets.register("css", css)
if "js" not in assets:
assets.register("js", js)

# Register blueprints
from app.demos import bp as demo_bp
from app.main import bp as main_bp

app.register_blueprint(demo_bp)
app.register_blueprint(main_bp)

return app
5 changes: 0 additions & 5 deletions app/demos/__init__.py

This file was deleted.

18 changes: 0 additions & 18 deletions app/demos/custom_validators.py

This file was deleted.

Loading

0 comments on commit 7534be7

Please sign in to comment.