Skip to content

Commit cab7956

Browse files
committed
Merge remote-tracking branch 'origin/main' into feature/eja-eli-173-create-postman-collection-automagically
2 parents 4545a30 + 37a6d1f commit cab7956

30 files changed

+1301
-912
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ sandbox/specification/*
4444
/lines-of-code-report*
4545
/specification/postman
4646
/sandbox/specification/*
47+
/integration-test-results.xml
4748
/specification/tmp/*

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# ==============================================================================
44
include scripts/init.mk
55

6+
MAKE_DIR := $(abspath $(shell pwd))
7+
68
#Installs dependencies using poetry.
79
install-python:
810
poetry install
@@ -39,13 +41,15 @@ publish: clean
3941
#Files to loop over in release
4042
_dist_include="pytest.ini poetry.lock poetry.toml pyproject.toml Makefile build/. tests"
4143

42-
4344
# Example CI/CD targets are: dependencies, build, publish, deploy, clean, etc.
4445

4546
dependencies: # Install dependencies needed to build and test the project @Pipeline
4647
scripts/dependencies.sh
4748

48-
build: # Build lambda in dist
49+
.PHONY: build
50+
build: dist/lambda.zip # Build lambda.zip in dist/
51+
52+
dist/lambda.zip: $(MAKE_DIR)/pyproject.toml $(MAKE_DIR)/poetry.lock $(shell find src -type f)
4953
poetry build-lambda -vv
5054

5155
deploy: # Deploy the project artefact to the target environment @Pipeline

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ The following software packages, or their equivalents, are expected to be instal
7272
7373
| Variable | Default | Description |
7474
|-------------------------|-------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
75-
| `DYNAMODB_ENDPOINT` | `http://localhost:4566` | Endpoint for the app to access DynamoDB |
76-
| `AWS_REGION` | `eu-west-1` | AWS Region |
77-
| `AWS_ACCESS_KEY` | `dummy_key` | AWS Access Key |
75+
| `AWS_ACCESS_KEY_ID` | `dummy_key` | AWS Access Key |
76+
| `AWS_DEFAULT_REGION` | `eu-west-1` | AWS Region |
7877
| `AWS_SECRET_ACCESS_KEY` | `dummy_secret` | AWS Secret Access Key |
78+
| `DYNAMODB_ENDPOINT` | `http://localhost:4566` | Endpoint for the app to access DynamoDB |
7979
| `LOG_LEVEL` | `WARNING` | Logging level. Must be one of `DEBUG`, `INFO`, `WARNING`, `ERROR` or `CRITICAL` as per [Logging Levels](https://docs.python.org/3/library/logging.html#logging-levels) |
8080
8181
## Usage

poetry.lock

Lines changed: 833 additions & 516 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ gitpython = "^3.1.44"
4242
pytest = "^8.3.4"
4343
pytest-asyncio = "^0.25.3"
4444
pytest-cov = "^6.0.0"
45-
#pytest-nhsd-apim = "^3.3.2"
45+
pytest-nhsd-apim = "^5.0.0"
4646
aiohttp = "^3.11.12"
4747
awscli = "^1.37.24"
4848
awscli-local = "^0.22.0"
@@ -82,6 +82,8 @@ log_cli = true
8282
log_cli_level = "DEBUG"
8383
log_format = "%(asctime)s %(levelname)s %(message)s"
8484
log_date_format = "%Y-%m-%d %H:%M:%S"
85+
asyncio_mode = "auto"
86+
asyncio_default_fixture_loop_scope = "function"
8587

8688
[tool.coverage.run]
8789
relative_files = true

src/eligibility_signposting_api/app.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from eligibility_signposting_api import repos, services
1111
from eligibility_signposting_api.config import config, init_logging
1212
from eligibility_signposting_api.error_handler import handle_exception
13-
from eligibility_signposting_api.views import eligibility, hello
13+
from eligibility_signposting_api.views import eligibility_blueprint
1414

1515
init_logging()
1616
logger = logging.getLogger(__name__)
@@ -24,7 +24,9 @@ def main() -> None: # pragma: no cover
2424

2525
def lambda_handler(event: LambdaEvent, context: LambdaContext) -> dict[str, Any]: # pragma: no cover
2626
"""Run the Flask app as an AWS Lambda."""
27-
handler = Mangum(WsgiToAsgi(create_app()))
27+
app = create_app()
28+
app.debug = config()["log_level"] == logging.DEBUG
29+
handler = Mangum(WsgiToAsgi(app), lifespan="off")
2830
return handler(event, context)
2931

3032

@@ -33,15 +35,14 @@ def create_app() -> Flask:
3335
logger.info("app created")
3436

3537
# Register views & error handler
36-
app.register_blueprint(eligibility, url_prefix="/eligibility")
37-
app.register_blueprint(hello, url_prefix="/hello")
38+
app.register_blueprint(eligibility_blueprint, url_prefix="/eligibility")
3839
app.register_error_handler(Exception, handle_exception)
3940

4041
# Set up dependency injection using wireup
41-
container = wireup.create_sync_container(service_modules=[services, repos], parameters={**config(), **app.config})
42+
container = wireup.create_sync_container(service_modules=[services, repos], parameters={**app.config, **config()})
4243
wireup.integration.flask.setup(container, app)
4344

44-
logger.info("app ready")
45+
logger.info("app ready", extra={"config": {**app.config, **config()}})
4546
return app
4647

4748

src/eligibility_signposting_api/config.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import os
3+
from collections.abc import Sequence
34
from functools import lru_cache
45
from typing import Any, NewType
56

@@ -16,17 +17,22 @@
1617
@lru_cache
1718
def config() -> dict[str, Any]:
1819
return {
20+
"aws_access_key_id": AwsAccessKey(os.getenv("AWS_ACCESS_KEY_ID", "dummy_key")),
21+
"aws_default_region": AwsRegion(os.getenv("AWS_DEFAULT_REGION", "eu-west-1")),
1922
"dynamodb_endpoint": URL(os.getenv("DYNAMODB_ENDPOINT", "http://localhost:4566")),
20-
"aws_region": AwsRegion(os.getenv("AWS_REGION", "eu-west-1")),
21-
"aws_access_key_id": AwsAccessKey(os.getenv("AWS_ACCESS_KEY", "dummy_key")),
2223
"aws_secret_access_key": AwsSecretAccessKey(os.getenv("AWS_SECRET_ACCESS_KEY", "dummy_secret")),
2324
"log_level": LOG_LEVEL,
2425
}
2526

2627

27-
def init_logging() -> None:
28+
def init_logging(quieten: Sequence[str] = ("asyncio", "botocore", "boto3", "mangum", "urllib3")) -> None:
2829
log_format = "%(asctime)s %(levelname)-8s %(name)s %(module)s.py:%(funcName)s():%(lineno)d %(message)s"
2930
formatter = JsonFormatter(log_format)
3031
handler = logging.StreamHandler()
3132
handler.setFormatter(formatter)
32-
logging.basicConfig(level=LOG_LEVEL, format=log_format, handlers=[handler])
33+
logging.root.handlers = [] # Clear any existing handlers
34+
logging.root.setLevel(LOG_LEVEL) # Set log level
35+
logging.root.addHandler(handler) # Add handler
36+
37+
for q in quieten:
38+
logging.getLogger(q).setLevel(logging.WARNING)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
from datetime import date
12
from typing import NewType
23

4+
from pydantic import BaseModel
5+
36
NHSNumber = NewType("NHSNumber", str)
7+
DateOfBirth = NewType("DateOfBirth", date)
8+
Postcode = NewType("Postcode", str)
9+
10+
11+
class Eligibility(BaseModel):
12+
processed_suggestions: list[dict]

src/eligibility_signposting_api/model/person.py

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1+
from .eligibility_repo import EligibilityRepo
12
from .exceptions import NotFoundError
2-
from .person_repo import PersonRepo
33

4-
__all__ = ["NotFoundError", "PersonRepo"]
4+
__all__ = ["EligibilityRepo", "NotFoundError"]

0 commit comments

Comments
 (0)