Skip to content
Snippets Groups Projects
Commit 046aa38a authored by Daniel Göbel's avatar Daniel Göbel
Browse files

Resolve "Error when registering a user without roles"

parent e12ff01d
No related branches found
No related tags found
1 merge request!7Resolve "Error when registering a user without roles"
...@@ -70,6 +70,7 @@ integration-test-job: # Runs integration tests with the database ...@@ -70,6 +70,7 @@ integration-test-job: # Runs integration tests with the database
alias: integration-test-mock-s3 alias: integration-test-mock-s3
variables: variables:
MOTO_PORT: 8000 MOTO_PORT: 8000
HEALTHCHECK_TCP_PORT: 8000
script: script:
- python clowm/check_ceph_connection.py - python clowm/check_ceph_connection.py
- python clowm/check_database_connection.py - python clowm/check_database_connection.py
...@@ -102,6 +103,7 @@ e2e-test-job: # Runs e2e tests on the API endpoints ...@@ -102,6 +103,7 @@ e2e-test-job: # Runs e2e tests on the API endpoints
alias: e2e-test-mock-s3 alias: e2e-test-mock-s3
variables: variables:
MOTO_PORT: 8000 MOTO_PORT: 8000
HEALTHCHECK_TCP_PORT: 8000
script: script:
- python clowm/check_ceph_connection.py - python clowm/check_ceph_connection.py
- python clowm/check_database_connection.py - python clowm/check_database_connection.py
......
...@@ -47,7 +47,7 @@ class CRUDUser: ...@@ -47,7 +47,7 @@ class CRUDUser:
insert_params = [{"uid": user.uid, "role_id": mapping[role]} for role in roles] insert_params = [{"uid": user.uid, "role_id": mapping[role]} for role in roles]
await db.execute(insert(UserRoleMapping), insert_params) await db.execute(insert(UserRoleMapping), insert_params)
await db.commit() await db.commit()
await db.refresh(user, attribute_names=["roles"]) await db.refresh(user, attribute_names=["roles"])
return user return user
@staticmethod @staticmethod
......
...@@ -357,6 +357,7 @@ class TestLoginRoute: ...@@ -357,6 +357,7 @@ class TestLoginRoute:
assert mock_rgw_admin.get_user(jwt["sub"])["keys"][0]["user"] is not None assert mock_rgw_admin.get_user(jwt["sub"])["keys"][0]["user"] is not None
# Check that user is created in DB # Check that user is created in DB
await db.reset()
db_user = await db.scalar(select(User).where(User.uid == uid)) db_user = await db.scalar(select(User).where(User.uid == uid))
assert db_user assert db_user
await db.refresh(db_user) # refresh the python object in sqlalchemy identity map await db.refresh(db_user) # refresh the python object in sqlalchemy identity map
......
...@@ -269,3 +269,44 @@ class TestUserRoutesCreate(_TestUserRoutes): ...@@ -269,3 +269,44 @@ class TestUserRoutesCreate(_TestUserRoutes):
assert user.lifescience_id is None assert user.lifescience_id is None
assert user.roles[0] == user_in.roles[0] assert user.roles[0] == user_in.roles[0]
assert user.display_name == user_in.display_name assert user.display_name == user_in.display_name
@pytest.mark.asyncio
async def test_create_user_without_roles(
self, client: AsyncClient, random_user: UserWithAuthHeader, db: AsyncSession, cleanup: CleanupList
) -> None:
"""
Test for creating a new user.
Parameters
----------
client : httpx.AsyncClient
HTTP Client to perform the request on.
db : sqlalchemy.ext.asyncio.AsyncSession.
Async database session to perform query on.
random_user : clowm.tests.utils.UserWithAuthHeader
Random user for testing.
cleanup : clowm.tests.utils.utils.CleanupList
Cleanup object where (async) functions can be registered which get executed after a (failed) test.
"""
user_in = UserIn(
display_name=random_lower_string(),
roles=[],
email=f"{random_lower_string(16)}@example.org",
)
response = await client.post(
self.base_path, headers=random_user.auth_headers, content=user_in.model_dump_json()
)
assert response.status_code == status.HTTP_201_CREATED
user = UserOutExtended.model_validate_json(response.content)
async def delete_user() -> None:
await db.execute(delete(User).where(User.uid == user.uid))
await db.commit()
cleanup.add_task(delete_user)
assert user.uid
assert len(user.roles) == 0
assert user.lifescience_id is None
assert user.display_name == user_in.display_name
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment