Skip to content

Commit 24c1154

Browse files
fix: models
1 parent c318e90 commit 24c1154

File tree

5 files changed

+77
-28
lines changed

5 files changed

+77
-28
lines changed

packages/models-library/src/models_library/rpc/notifications/events/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
AccountApprovedEvent,
55
AccountRejectedEvent,
66
AccountRequestedEvent,
7+
ProductData,
8+
ProductUIData,
9+
UserData,
710
)
811

912
Event: TypeAlias = AccountRequestedEvent | AccountApprovedEvent | AccountRejectedEvent
@@ -14,6 +17,9 @@
1417
"AccountRejectedEvent",
1518
"AccountRequestedEvent",
1619
"Event",
20+
"ProductData",
21+
"ProductUIData",
22+
"UserData",
1723
)
1824

1925
# nopycln: file

packages/models-library/src/models_library/rpc/notifications/events/_account_events.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,46 @@
11
from typing import Literal
22

33
from common_library.pydantic_basic_types import NotEmptyStr
4+
from models_library.products import ProductName
45
from pydantic import BaseModel, EmailStr
56

67

7-
class AccountRequestedEvent(BaseModel):
8-
type: Literal["account_requested"] = "account_requested"
9-
8+
class UserData(BaseModel):
9+
username: str
1010
first_name: str
1111
last_name: str
1212
email: EmailStr
1313

1414
# TODO: add more fields as needed
1515

1616

17+
class ProductUIData(BaseModel):
18+
project_alias: str
19+
logo_url: str | None = (
20+
None # default_logo = "https://raw.githubusercontent.com/ITISFoundation/osparc-simcore/refs/heads/master/services/static-webserver/client/source/resource/osparc/osparc-white.svg" in base.html
21+
)
22+
strong_color: str | None = (
23+
None # default_strong_color = "rgb(131, 0, 191)" in base.html
24+
)
25+
26+
27+
class ProductData(BaseModel):
28+
product_name: ProductName
29+
display_name: str
30+
vendor_display_inline: str
31+
support_email: str
32+
homepage_url: str | None # default_homepage = "https://osparc.io/" in base.html
33+
ui: ProductUIData
34+
35+
36+
class AccountRequestedEvent(BaseModel):
37+
type: Literal["account_requested"] = "account_requested"
38+
39+
user: UserData
40+
product: ProductData
41+
host: str
42+
43+
1744
class AccountApprovedEvent(BaseModel):
1845
type: Literal["account_approved"] = "account_approved"
1946

services/notifications/src/simcore_service_notifications/core/events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def create_app_lifespan(settings: ApplicationSettings) -> LifespanManager:
4545
app_lifespan.add(postgres_database_lifespan)
4646
app_lifespan.add(postgres_lifespan)
4747

48-
if settings.NOTIFICATIONS_CELERY and not settings.NOTIFICATIONS_WORKER_MODE:
48+
if not settings.NOTIFICATIONS_WORKER_MODE:
4949
# - rabbitmq
5050
app_lifespan.add(rabbitmq_lifespan)
5151

services/notifications/tests/unit/conftest.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,43 +38,42 @@ def app_environment(
3838
mock_environment: EnvVarsDict,
3939
postgres_db: sa.engine.Engine, # wait for postgres service to start
4040
postgres_env_vars_dict: EnvVarsDict,
41+
rabbit_service: RabbitSettings,
42+
redis_service: RedisSettings,
4143
) -> EnvVarsDict:
4244
return setenvs_from_dict(
4345
monkeypatch,
4446
{
4547
**mock_environment,
4648
**postgres_env_vars_dict,
49+
"RABBIT_HOST": rabbit_service.RABBIT_HOST,
50+
"RABBIT_PASSWORD": rabbit_service.RABBIT_PASSWORD.get_secret_value(),
51+
"RABBIT_PORT": f"{rabbit_service.RABBIT_PORT}",
52+
"RABBIT_SECURE": f"{rabbit_service.RABBIT_SECURE}",
53+
"RABBIT_USER": rabbit_service.RABBIT_USER,
54+
"REDIS_SECURE": redis_service.REDIS_SECURE,
55+
"REDIS_HOST": redis_service.REDIS_HOST,
56+
"REDIS_PORT": f"{redis_service.REDIS_PORT}",
57+
"REDIS_PASSWORD": redis_service.REDIS_PASSWORD.get_secret_value(),
4758
},
4859
)
4960

5061

51-
@pytest.fixture
52-
def enabled_rabbitmq(
53-
app_environment: EnvVarsDict, rabbit_service: RabbitSettings
54-
) -> RabbitSettings:
55-
return rabbit_service
56-
57-
58-
@pytest.fixture
59-
def enabled_redis(
60-
app_environment: EnvVarsDict, redis_service: RedisSettings
61-
) -> RedisSettings:
62-
return redis_service
63-
64-
6562
@pytest.fixture
6663
def app_settings(
6764
app_environment: EnvVarsDict,
68-
enabled_rabbitmq: RabbitSettings,
69-
enabled_redis: RedisSettings,
65+
monkeypatch: pytest.MonkeyPatch,
7066
) -> ApplicationSettings:
67+
monkeypatch.setenv("NOTIFICATIONS_WORKER_MODE", "false")
7168
settings = ApplicationSettings.create_from_envs()
7269
print(f"{settings.model_dump_json(indent=2)=}")
7370
return settings
7471

7572

7673
@pytest.fixture
77-
async def fastapi_app(app_settings: ApplicationSettings) -> AsyncIterator[FastAPI]:
74+
async def mock_fastapi_app(
75+
mock_celery_app: None, app_settings: ApplicationSettings
76+
) -> AsyncIterator[FastAPI]:
7877
app: FastAPI = create_app(app_settings)
7978

8079
async with LifespanManager(app, startup_timeout=30, shutdown_timeout=30):
@@ -111,7 +110,6 @@ def mock_celery_app(mocker: MockerFixture, celery_config: dict[str, Any]) -> Cel
111110
async def mock_celery_worker(
112111
app_environment: EnvVarsDict,
113112
celery_app: Celery,
114-
fastapi_app: FastAPI,
115113
monkeypatch: pytest.MonkeyPatch,
116114
) -> AsyncIterator[Any]:
117115
monkeypatch.setenv("NOTIFICATIONS_WORKER_MODE", "true")
@@ -121,7 +119,7 @@ def _on_worker_init_wrapper(sender: WorkController, **_kwargs):
121119
assert app_settings.NOTIFICATIONS_CELERY # nosec
122120
return partial(
123121
on_worker_init,
124-
FastAPIAppServer(app=fastapi_app),
122+
FastAPIAppServer(app=create_app(app_settings)),
125123
app_settings.NOTIFICATIONS_CELERY,
126124
)(sender, **_kwargs)
127125

services/notifications/tests/unit/test_send_email_tasks.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
from models_library.rpc.notifications.channels import EmailAddress, EmailChannel
55
from models_library.rpc.notifications.events import (
66
AccountRequestedEvent,
7+
ProductData,
8+
ProductUIData,
9+
UserData,
710
)
811
from servicelib.rabbitmq import RabbitMQRPCClient
912
from servicelib.rabbitmq.rpc_interfaces.notifications import (
@@ -18,9 +21,8 @@
1821

1922

2023
@pytest.mark.usefixtures(
21-
"mock_celery_app",
2224
"mock_celery_worker",
23-
"fastapi_app",
25+
"mock_fastapi_app",
2426
)
2527
async def test_account_requested(
2628
notifications_rabbitmq_rpc_client: RabbitMQRPCClient,
@@ -32,9 +34,25 @@ async def test_account_requested(
3234
notifications_rabbitmq_rpc_client,
3335
notification=Notification(
3436
event=AccountRequestedEvent(
35-
first_name=faker.first_name(),
36-
last_name=faker.last_name(),
37-
email=user_email,
37+
user=UserData(
38+
username=faker.user_name(),
39+
first_name=faker.first_name(),
40+
last_name=faker.last_name(),
41+
email=user_email,
42+
),
43+
product=ProductData(
44+
product_name=faker.company(),
45+
display_name=faker.company(),
46+
vendor_display_inline=faker.company_suffix(),
47+
support_email=faker.email(),
48+
homepage_url=faker.url(),
49+
ui=ProductUIData(
50+
project_alias=faker.word(),
51+
logo_url=faker.image_url(),
52+
strong_color=faker.color_name(),
53+
),
54+
),
55+
host=faker.url(),
3856
),
3957
channel=EmailChannel(
4058
from_addr=EmailAddress(addr_spec=faker.email()),

0 commit comments

Comments
 (0)