Skip to content

Commit 6c4f709

Browse files
committed
fixes
1 parent 5f093bb commit 6c4f709

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

services/web/server/src/simcore_service_webserver/users/_users_repository.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import contextlib
22
from typing import Any
33

4-
import simcore_postgres_database.errors as db_errors
54
import sqlalchemy as sa
65
from aiohttp import web
76
from common_library.users_enums import UserRole
@@ -34,6 +33,7 @@
3433
)
3534
from sqlalchemy import delete
3635
from sqlalchemy.engine.row import Row
36+
from sqlalchemy.exc import IntegrityError
3737
from sqlalchemy.ext.asyncio import AsyncConnection, AsyncEngine
3838

3939
from ..db.plugin import get_asyncpg_engine
@@ -386,7 +386,13 @@ async def get_my_profile(app: web.Application, *, user_id: UserID) -> MyProfile:
386386
"hide_email",
387387
users.c.privacy_hide_email,
388388
).label("privacy"),
389-
sa.func.date(users.c.expires_at).label("expiration_date"),
389+
sa.case(
390+
(
391+
users.c.expires_at.isnot(None),
392+
sa.func.date(users.c.expires_at),
393+
),
394+
else_=None, # or some default value if necessary
395+
).label("expiration_date"),
390396
).where(users.c.id == user_id)
391397
)
392398
row = await result.first()
@@ -424,7 +430,7 @@ async def update_user_profile(
424430
.values(**updated_values)
425431
)
426432

427-
except db_errors.UniqueViolation as err:
433+
except IntegrityError as err:
428434
user_name = updated_values.get("name")
429435

430436
raise UserNameDuplicateError(

services/web/server/tests/unit/with_dbs/03/test_users.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
import simcore_service_webserver.login._auth_api
1717
from aiohttp.test_utils import TestClient
1818
from aiopg.sa.connection import SAConnection
19+
from common_library.users_enums import UserRole, UserStatus
1920
from faker import Faker
2021
from models_library.api_schemas_webserver.auth import AccountRequestInfo
2122
from models_library.api_schemas_webserver.users import MyProfileGet, UserGet
22-
from models_library.generics import Envelope
2323
from psycopg2 import OperationalError
2424
from pytest_simcore.helpers.assert_checks import assert_status
2525
from pytest_simcore.helpers.faker_factories import (
@@ -30,7 +30,6 @@
3030
from pytest_simcore.helpers.webserver_login import UserInfoDict
3131
from servicelib.aiohttp import status
3232
from servicelib.rest_constants import RESPONSE_MODEL_POLICY
33-
from simcore_postgres_database.models.users import UserRole, UserStatus
3433
from simcore_service_webserver.users._common.schemas import (
3534
MAX_BYTES_SIZE_EXTRAS,
3635
PreRegisteredUserGet,
@@ -116,36 +115,31 @@ async def test_get_profile(
116115
resp = await client.get(f"{url}")
117116
data, error = await assert_status(resp, status.HTTP_200_OK)
118117

119-
resp_model = Envelope[MyProfileGet].model_validate(await resp.json())
120-
121-
assert resp_model.data.model_dump(**RESPONSE_MODEL_POLICY, mode="json") == data
122-
assert resp_model.error is None
123-
124-
profile = resp_model.data
125-
126-
product_group = {
127-
"accessRights": {"delete": False, "read": False, "write": False},
128-
"description": "osparc product group",
129-
"gid": 2,
130-
"inclusionRules": {},
131-
"label": "osparc",
132-
"thumbnail": None,
133-
}
118+
assert not error
119+
profile = MyProfileGet.model_validate(data)
134120

135121
assert profile.login == logged_user["email"]
136122
assert profile.first_name == logged_user.get("first_name", None)
137123
assert profile.last_name == logged_user.get("last_name", None)
138124
assert profile.role == user_role.name
139125
assert profile.groups
126+
assert profile.expiration_date is None
140127

141128
got_profile_groups = profile.groups.model_dump(**RESPONSE_MODEL_POLICY, mode="json")
142129
assert got_profile_groups["me"] == primary_group
143130
assert got_profile_groups["all"] == all_group
131+
assert got_profile_groups["product"] == {
132+
"accessRights": {"delete": False, "read": False, "write": False},
133+
"description": "osparc product group",
134+
"gid": 2,
135+
"label": "osparc",
136+
"thumbnail": None,
137+
}
144138

145139
sorted_by_group_id = functools.partial(sorted, key=lambda d: d["gid"])
146140
assert sorted_by_group_id(
147141
got_profile_groups["organizations"]
148-
) == sorted_by_group_id([*standard_groups, product_group])
142+
) == sorted_by_group_id(standard_groups)
149143

150144
assert profile.preferences == await get_frontend_user_preferences_aggregation(
151145
client.app, user_id=logged_user["id"], product_name="osparc"
@@ -160,25 +154,28 @@ async def test_update_profile(
160154
):
161155
assert client.app
162156

163-
resp = await client.get("/v0/me")
164-
data, _ = await assert_status(resp, status.HTTP_200_OK)
157+
# GET
158+
url = client.app.router["get_my_profile"].url_for()
159+
resp = await client.get(f"{url}")
165160

161+
data, _ = await assert_status(resp, status.HTTP_200_OK)
166162
assert data["role"] == user_role.name
167163
before = deepcopy(data)
168164

165+
# UPDATE
169166
url = client.app.router["update_my_profile"].url_for()
170-
assert url.path == "/v0/me"
171167
resp = await client.patch(
172168
f"{url}",
173169
json={
174170
"last_name": "Foo",
175171
},
176172
)
177173
_, error = await assert_status(resp, status.HTTP_204_NO_CONTENT)
178-
179174
assert not error
180175

181-
resp = await client.get("/v0/me")
176+
# GET
177+
url = client.app.router["get_my_profile"].url_for()
178+
resp = await client.get(f"{url}")
182179
data, _ = await assert_status(resp, status.HTTP_200_OK)
183180

184181
assert data["last_name"] == "Foo"

0 commit comments

Comments
 (0)