Skip to content

Commit

Permalink
Set config default and tweak name
Browse files Browse the repository at this point in the history
Fix notification wording

Fix _changed_info docstring

Use pytestmark in test modules
  • Loading branch information
TheByronHimes committed May 13, 2024
1 parent b114889 commit 27888e4
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/.dev_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ file_registered_event_topic: internal_file_registry
file_registered_event_type: file_registered
iva_events_topic: ivas
iva_state_changed_event_type: iva_state_changed
user_data_event_topic: user_events
user_events_topic: users
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,7 @@ The service requires the following configuration parameters:
```


- **`user_data_event_topic`** *(string)*: The name of the topic containing user data events.


Examples:

```json
"user_data_events"
```

- **`user_events_topic`** *(string)*: The name of the topic containing user events. Default: `"users"`.

- **`access_request_events_topic`** *(string)*: Name of the event topic used to consume access request events.

Expand Down
11 changes: 4 additions & 7 deletions config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@
"title": "Notification Event Type",
"type": "string"
},
"user_data_event_topic": {
"description": "The name of the topic containing user data events.",
"examples": [
"user_data_events"
],
"title": "User Data Event Topic",
"user_events_topic": {
"default": "users",
"description": "The name of the topic containing user events.",
"title": "User Events Topic",
"type": "string"
},
"access_request_events_topic": {
Expand Down Expand Up @@ -223,7 +221,6 @@
"db_name",
"notification_event_topic",
"notification_event_type",
"user_data_event_topic",
"access_request_events_topic",
"access_request_created_event_type",
"access_request_allowed_event_type",
Expand Down
2 changes: 1 addition & 1 deletion example_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ notification_event_topic: notification_events
notification_event_type: notification
service_instance_id: '1'
service_name: nos
user_data_event_topic: user_events
user_events_topic: users
3 changes: 1 addition & 2 deletions src/nos/core/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ def formatted(self, **kwargs) -> "Notification":
"""
Your account details were recently updated. The changed details include: {changed_details}.
If you did not make the following changes or have
please contact the GHGA immediately at {support_email}.
If you did not make these changes or have questions, please contact the GHGA immediately at {support_email}.
""",
)
2 changes: 1 addition & 1 deletion src/nos/core/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ async def process_iva_state_change(self, *, user_iva: event_schemas.UserIvaState
def _changed_info(
self, existing_user: event_schemas.User, new_user: event_schemas.User
) -> str:
"""Check if critical user information has changed.
"""Check what critical user information has changed (if any).
Critical information includes the user's email address and name.
"""
Expand Down
9 changes: 4 additions & 5 deletions src/nos/translators/inbound/event_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,9 @@ async def _consume_validated(
class OutboxSubTranslatorConfig(BaseSettings):
"""Config for the outbox subscriber"""

user_data_event_topic: str = Field(
default=...,
description="The name of the topic containing user data events.",
examples=["user_data_events"],
user_events_topic: str = Field(
default="users",
description="The name of the topic containing user events.",
)


Expand All @@ -168,7 +167,7 @@ def __init__(
):
self._config = config
self._orchestrator = orchestrator
self.event_topic = config.user_data_event_topic
self.event_topic = config.user_events_topic

async def changed(self, resource_id: str, update: event_schemas.User) -> None:
"""Consume change event (created or updated) for user data."""
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/test_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ file_registered_event_topic: internal_file_registry
file_registered_event_type: file_registered
iva_events_topic: ivas
iva_state_changed_event_type: iva_state_changed
user_data_event_topic: user_events
user_events_topic: users
7 changes: 1 addition & 6 deletions tests/test_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from tests.fixtures.joint import JointFixture

DATASET_ID = "dataset1"
pytestmark = pytest.mark.asyncio()


def access_request_payload(user_id: str) -> dict[str, Any]:
Expand Down Expand Up @@ -83,7 +84,6 @@ def iva_state_payload(user_id: str, state: event_schemas.IvaState) -> dict[str,
),
],
)
@pytest.mark.asyncio
async def test_access_request(
joint_fixture: JointFixture,
user_notification_content: notifications.Notification,
Expand Down Expand Up @@ -159,7 +159,6 @@ async def test_access_request(
await joint_fixture.event_subscriber.run(forever=False)


@pytest.mark.asyncio
async def test_missing_user_id_access_requests(
joint_fixture: JointFixture, logot: Logot
):
Expand Down Expand Up @@ -191,7 +190,6 @@ async def test_missing_user_id_access_requests(
)


@pytest.mark.asyncio
async def test_missing_user_id_iva_state_changes(
joint_fixture: JointFixture, logot: Logot
):
Expand Down Expand Up @@ -228,7 +226,6 @@ async def test_missing_user_id_iva_state_changes(
)


@pytest.mark.asyncio
async def test_file_registered(joint_fixture: JointFixture):
"""Test that the file registered events are translated into a notification."""
# Prepare triggering event (the file registration event).
Expand Down Expand Up @@ -302,7 +299,6 @@ async def test_file_registered(joint_fixture: JointFixture):
),
],
)
@pytest.mark.asyncio
async def test_iva_state_change(
joint_fixture: JointFixture,
iva_state: event_schemas.IvaState,
Expand Down Expand Up @@ -377,7 +373,6 @@ async def test_iva_state_change(
await joint_fixture.event_subscriber.run(forever=False)


@pytest.mark.asyncio
async def test_all_ivas_reset(joint_fixture: JointFixture):
"""Test that the 'all IVA invalidated' events are translated into a notification."""
# Prepare triggering event (the IVA state change event).
Expand Down
13 changes: 6 additions & 7 deletions tests/test_outbox_subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
CHANGE_EVENT_TYPE = "upserted"
DELETE_EVENT_TYPE = "deleted"

pytestmark = pytest.mark.asyncio()


@pytest.mark.parametrize("user_id", ["test_id", "does_not_exist"])
@pytest.mark.asyncio
async def test_user_data_deletion(joint_fixture: JointFixture, user_id: str):
"""Ensure that the `delete` function works correctly.
Expand All @@ -45,7 +46,7 @@ async def test_user_data_deletion(joint_fixture: JointFixture, user_id: str):
await joint_fixture.kafka.publish_event(
payload={},
type_=DELETE_EVENT_TYPE,
topic=joint_fixture.config.user_data_event_topic,
topic=joint_fixture.config.user_events_topic,
key=user_id,
)

Expand Down Expand Up @@ -73,7 +74,6 @@ async def test_user_data_deletion(joint_fixture: JointFixture, user_id: str):
],
ids=["modified user", "new user"],
)
@pytest.mark.asyncio
async def test_user_data_upsert(
joint_fixture: JointFixture,
user: event_schemas.User,
Expand All @@ -94,14 +94,14 @@ async def test_user_data_upsert(
await joint_fixture.kafka.publish_event(
payload=user.model_dump(),
type_=CHANGE_EVENT_TYPE,
topic=joint_fixture.config.user_data_event_topic,
topic=joint_fixture.config.user_events_topic,
key=user.user_id,
)

# Run the outbox subscriber.
await joint_fixture.outbox_subscriber.run(forever=False)

# 4. Check that the user data is found.
# Check that the user data is found.
result = await joint_fixture.user_dao.get_by_id(user.user_id)
assert result == user

Expand All @@ -116,7 +116,6 @@ async def test_user_data_upsert(
],
ids=["name", "email", "both", "neither"],
)
@pytest.mark.asyncio
async def test_user_reregistration_notifications(
joint_fixture: JointFixture,
changed_details: dict[str, str],
Expand All @@ -133,7 +132,7 @@ async def test_user_reregistration_notifications(
await joint_fixture.kafka.publish_event(
payload=user.model_dump(),
type_=CHANGE_EVENT_TYPE,
topic=joint_fixture.config.user_data_event_topic,
topic=joint_fixture.config.user_events_topic,
key=user.user_id,
)

Expand Down

0 comments on commit 27888e4

Please sign in to comment.