Skip to content

Commit

Permalink
Fix missing f-string (#9)
Browse files Browse the repository at this point in the history
* Fix missing f-string

* Bump version

* Update README and toml

* Extend tests

* Fix logging issue
  • Loading branch information
lkuchenb authored Jun 18, 2024
1 parent 87215f0 commit dc587b8
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .pyproject_generation/pyproject_custom.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "nos"
version = "1.0.1"
version = "1.0.2"
description = "The Notification Orchestration Service controls the creation of notification events."
dependencies = [
"typer >= 0.9.0",
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ We recommend using the provided Docker container.

A pre-build version is available at [docker hub](https://hub.docker.com/repository/docker/ghga/notification-orchestration-service):
```bash
docker pull ghga/notification-orchestration-service:1.0.1
docker pull ghga/notification-orchestration-service:1.0.2
```

Or you can build the container yourself from the [`./Dockerfile`](./Dockerfile):
```bash
# Execute in the repo's root dir:
docker build -t ghga/notification-orchestration-service:1.0.1 .
docker build -t ghga/notification-orchestration-service:1.0.2 .
```

For production-ready deployment, we recommend using Kubernetes, however,
for simple use cases, you could execute the service using docker
on a single server:
```bash
# The entrypoint is preconfigured:
docker run -p 8080:8080 ghga/notification-orchestration-service:1.0.1 --help
docker run -p 8080:8080 ghga/notification-orchestration-service:1.0.2 --help
```

If you prefer not to use containers, you may install the service from source:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ classifiers = [
"Intended Audience :: Developers",
]
name = "nos"
version = "1.0.1"
version = "1.0.2"
description = "The Notification Orchestration Service controls the creation of notification events."
dependencies = [
"typer >= 0.9.0",
Expand Down
22 changes: 16 additions & 6 deletions src/nos/core/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,25 @@ async def process_access_request_notification(
- MissingUserError:
When the provided user ID does not exist in the DB.
"""
method_map: dict[str, Callable] = {
self._config.access_request_created_event_type: self._access_request_created,
self._config.access_request_allowed_event_type: self._access_request_allowed,
self._config.access_request_denied_event_type: self._access_request_denied,
event_type_assets: dict[str, tuple[str, Callable]] = {
self._config.access_request_created_event_type: (
"Access Request Created",
self._access_request_created,
),
self._config.access_request_allowed_event_type: (
"Access Request Allowed",
self._access_request_allowed,
),
self._config.access_request_denied_event_type: (
"Access Request Denied",
self._access_request_denied,
),
}
notification_name, handler = event_type_assets[event_type]
extra = { # for error logging
"user_id": user_id,
"dataset_id": dataset_id,
"notification_name": "Access Request Created",
"notification_name": notification_name,
}

try:
Expand All @@ -77,7 +87,7 @@ async def process_access_request_notification(
log.error(error, extra=extra)
raise error from err

await method_map[event_type](user=user, dataset_id=dataset_id)
await handler(user=user, dataset_id=dataset_id)

async def _access_request_created(
self, *, user: event_schemas.User, dataset_id: str
Expand Down
2 changes: 1 addition & 1 deletion src/nos/ports/inbound/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MissingUserError(RuntimeError):
def __init__(self, *, user_id: str, notification_name: str) -> None:
message = (
f"Unable to publish '{notification_name}' notification as user ID"
+ " '{user_id}' was not found in the database."
+ f" '{user_id}' was not found in the database."
)
super().__init__(message)

Expand Down
30 changes: 23 additions & 7 deletions tests/test_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,15 @@ async def test_missing_user_id_access_requests(
joint_fixture.config.access_request_allowed_event_type,
joint_fixture.config.access_request_denied_event_type,
)
notification_names = (
"Access Request Created",
"Access Request Allowed",
"Access Request Denied",
)

for event_type in event_types:
for event_type, notification_name in zip(
event_types, notification_names, strict=True
):
await joint_fixture.kafka.publish_event(
payload=payload,
type_=event_type,
Expand All @@ -184,8 +191,8 @@ async def test_missing_user_id_access_requests(
await joint_fixture.event_subscriber.run(forever=False)
logot.assert_logged(
logged.error(
"Unable to publish %s notification as user ID %s was not found in"
+ " the database."
f"Unable to publish '{notification_name}' notification as user ID '{
payload['user_id']}' was not found in the database."
)
)

Expand All @@ -209,7 +216,15 @@ async def test_missing_user_id_iva_state_changes(
joint_fixture.config.iva_state_changed_event_type, # verified
joint_fixture.config.iva_state_changed_event_type, # unverified
)
for payload, event_type in zip(payloads, event_types, strict=True):
notification_names = (
"IVA Code Requested",
"IVA Code Transmitted",
"IVA Code Validated",
"IVA Unverified",
)
for payload, event_type, notification_name in zip(
payloads, event_types, notification_names, strict=True
):
await joint_fixture.kafka.publish_event(
payload=payload,
type_=event_type,
Expand All @@ -220,8 +235,8 @@ async def test_missing_user_id_iva_state_changes(
await joint_fixture.event_subscriber.run(forever=False)
logot.assert_logged(
logged.error(
"Unable to publish %s notification as user ID %s was not found in"
+ " the database."
f"Unable to publish '{notification_name}' notification as user ID '{
payload['user_id']}' was not found in the database."
)
)

Expand Down Expand Up @@ -257,7 +272,8 @@ async def test_file_registered(joint_fixture: JointFixture):
recipient_email=joint_fixture.config.central_data_stewardship_email,
recipient_name="Data Steward",
subject="File upload completed",
plaintext_body=f"The file {DATASET_ID} has been successfully uploaded.",
plaintext_body=f"The file {
DATASET_ID} has been successfully uploaded.",
)

expected_event = ExpectedEvent(
Expand Down

0 comments on commit dc587b8

Please sign in to comment.