Skip to content

Commit c8c8a8d

Browse files
committed
fixes notifications and cleanup tests
1 parent b38bd96 commit c8c8a8d

File tree

6 files changed

+33
-13
lines changed

6 files changed

+33
-13
lines changed

packages/notifications-library/src/notifications_library/_models.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@
22

33
from models_library.products import ProductName
44

5-
65
#
76
# *Data are models used for rendering
87
#
8+
9+
10+
@dataclass(frozen=True)
11+
class JinjaTemplateDbGet:
12+
product_name: ProductName
13+
name: str
14+
content: str
15+
16+
917
@dataclass(frozen=True)
1018
class UserData:
1119
first_name: str

packages/notifications-library/src/notifications_library/_repository.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
from collections.abc import AsyncIterable
2+
13
import sqlalchemy as sa
24
from models_library.products import ProductName
35
from models_library.users import UserID
4-
from notifications_library._models import UserData
6+
from notifications_library._models import (
7+
JinjaTemplateDbGet,
8+
UserData,
9+
)
510
from simcore_postgres_database.models.jinja2_templates import jinja2_templates
611
from simcore_postgres_database.models.products_to_templates import products_to_templates
712
from simcore_postgres_database.models.users import users
@@ -37,7 +42,9 @@ async def get_user_data(self, user_id: UserID) -> UserData:
3742

3843

3944
class TemplatesRepo(_BaseRepo):
40-
async def iter_email_templates(self, product_name: ProductName):
45+
async def iter_email_templates(
46+
self, product_name: ProductName
47+
) -> AsyncIterable[JinjaTemplateDbGet]:
4148
async with pass_or_acquire_connection(self.db_engine) as conn:
4249
async for row in await conn.stream(
4350
sa.select(
@@ -50,9 +57,13 @@ async def iter_email_templates(self, product_name: ProductName):
5057
& (jinja2_templates.c.name.ilike("%.email.%"))
5158
)
5259
):
53-
yield row
60+
yield JinjaTemplateDbGet(
61+
product_name=product_name, name=row.name, content=row.content
62+
)
5463

55-
async def iter_product_templates(self, product_name: ProductName):
64+
async def iter_product_templates(
65+
self, product_name: ProductName
66+
) -> AsyncIterable[JinjaTemplateDbGet]:
5667
async with pass_or_acquire_connection(self.db_engine) as conn:
5768
async for row in await conn.stream(
5869
sa.select(
@@ -63,4 +74,6 @@ async def iter_product_templates(self, product_name: ProductName):
6374
.select_from(products_to_templates.join(jinja2_templates))
6475
.where(products_to_templates.c.product_name == product_name)
6576
):
66-
yield row
77+
yield JinjaTemplateDbGet(
78+
product_name=row.product_name, name=row.name, content=row.template
79+
)

packages/notifications-library/src/notifications_library/_templates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from aiofiles.os import wrap as sync_to_async
1111
from models_library.products import ProductName
1212

13-
from ._db import TemplatesRepo
13+
from ._repository import TemplatesRepo
1414

1515
_logger = logging.getLogger(__name__)
1616

packages/notifications-library/tests/with_db/test__repository.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async def test_user_data_repo(
3333

3434
repo = UsersRepo(sqlalchemy_async_engine)
3535
got = await repo.get_user_data(user_id)
36-
assert UserData(*got) == user_data
36+
assert got == user_data
3737

3838

3939
async def test_payments_data_repo(
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
from urllib.parse import quote
22

33
from aiohttp import web
4-
from models_library.basic_types import IDStr
54
from yarl import URL
65

76

8-
def _url_for_confirmation(app: web.Application, code: IDStr) -> URL:
7+
def _url_for_confirmation(app: web.Application, code: str) -> URL:
98
# NOTE: this is in a query parameter, and can contain ? for example.
109
safe_code = quote(code, safe="")
1110
return app.router["auth_confirmation"].url_for(code=safe_code)
1211

1312

14-
def make_confirmation_link(request: web.Request, code: IDStr) -> str:
13+
def make_confirmation_link(request: web.Request, code: str) -> str:
14+
assert code # nosec
1515
link = _url_for_confirmation(request.app, code=code)
1616
return f"{request.scheme}://{request.host}{link}"

services/web/server/src/simcore_service_webserver/login/_login_repository_legacy.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import asyncpg
66
from aiohttp import web
7-
from models_library.basic_types import IDStr
87
from servicelib.utils_secrets import generate_passcode
98

109
from . import _login_repository_legacy_sql
@@ -22,7 +21,7 @@
2221

2322

2423
class BaseConfirmationTokenDict(TypedDict):
25-
code: IDStr
24+
code: str
2625
action: ActionLiteralStr
2726

2827

0 commit comments

Comments
 (0)