Skip to content

Commit

Permalink
move test to user update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hjanott committed Nov 22, 2024
1 parent de6f279 commit 42eb249
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 50 deletions.
95 changes: 89 additions & 6 deletions tests/system/action/user/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,11 +973,61 @@ def test_perm_group_A_cml_manage_user_archived_meeting_in_other_committee(
self.assertCountEqual(user111["meeting_ids"], [1, 4])

def test_perm_group_A_meeting_manage_user(self) -> None:
"""May update group A fields on meeting scope. User belongs to 1 meeting without being part of a committee"""
"""
May update group A fields on meeting scope. User belongs to 1 meeting without being part of a committee.
Testing various scenarios:
* both default group
* default group has user.can_update permission
* requesting user is in admin group
"""
self.permission_setup()
self.set_user_groups(self.user_id, [2])
self.set_user_groups(self.user_id, [1])
self.set_user_groups(111, [1])

response = self.request(
"user.update",
{
"id": 111,
"username": "new_username",
"pronoun": "pronoun",
},
)
self.assert_status_code(response, 403)
self.assertIn(
"You are not allowed to perform action user.update. Missing permissions: OrganizationManagementLevel can_manage_users in organization 1 or CommitteeManagementLevel can_manage in committee 60 or Permission user.can_update in meeting {1}",
response.json["message"],
)
self.assert_model_exists(
"user/111",
{
"username": "User111",
"pronoun": None,
"meeting_ids": [1],
"committee_ids": None,
},
)

self.update_model("group/1", {"permissions": ["user.can_update"]})
response = self.request(
"user.update",
{
"id": 111,
"username": "new_user",
"pronoun": "pro",
},
)
self.assert_status_code(response, 200)
self.assert_model_exists(
"user/111",
{
"username": "new_user",
"pronoun": "pro",
"meeting_ids": [1],
"committee_ids": None,
},
)

self.set_user_groups(self.user_id, [2])
response = self.request(
"user.update",
{
Expand Down Expand Up @@ -1314,8 +1364,10 @@ def test_perm_group_F_with_meeting_scope(self) -> None:
"""
Test user update with various scenarios (admin in different meeting and committee no interference)
* not in same meeting fails
* same meeting but requesting user not in admin or permission group fails
* same meeting requesting user with permission user.can_update works
* same meeting both admin works
* same meeting request user is committee admin works
* same meeting requesting user is committee admin works
"""
self.permission_setup()
self.create_meeting(4)
Expand All @@ -1342,8 +1394,23 @@ def test_perm_group_F_with_meeting_scope(self) -> None:
},
)

self.set_user_groups(111, [2])
self.set_user_groups(self.user_id, [2, 5])
self.set_user_groups(self.user_id, [1, 5])
response = self.request(
"user.update",
{
"id": 111,
"default_password": "new_one",
},
)
self.assert_status_code(response, 403)
self.assert_model_exists(
"user/111",
{
"default_password": None,
},
)

self.update_model("group/1", {"permissions": ["user.can_update"]})
response = self.request(
"user.update",
{
Expand All @@ -1359,7 +1426,7 @@ def test_perm_group_F_with_meeting_scope(self) -> None:
},
)

self.set_committee_management_level([60], self.user_id)
self.set_user_groups(self.user_id, [2, 5])
response = self.request(
"user.update",
{
Expand All @@ -1375,6 +1442,22 @@ def test_perm_group_F_with_meeting_scope(self) -> None:
},
)

self.set_committee_management_level([60], self.user_id)
response = self.request(
"user.update",
{
"id": 111,
"default_password": "newest_one",
},
)
self.assert_status_code(response, 200)
self.assert_model_exists(
"user/111",
{
"default_password": "newest_one",
},
)

def test_perm_group_F_with_two_meeting_across_committees(self) -> None:
"""
May not update group F fields unless requesting user has admin rights in
Expand Down
44 changes: 0 additions & 44 deletions tests/system/presenter/test_get_user_editable.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,50 +331,6 @@ def test_with_same_meeting_can_update(self) -> None:
},
)

def test_with_single_meeting_can_update(self) -> None:
"""
User 7 can be edited because he is only one meeting which User 111 has can_update of.
"""
self.set_up()
self.create_meeting_for_two_users(7, 111, 7)
self.update_model("meeting/7", {"committee_id": 1})
self.update_model("group/9", {"permissions": ["user.can_update"]})
# User 111 has user.can_update group rights in meeting 7
# User 7 is normal user in meeting 7
meeting_user_to_group = {
7111: 9,
77: 7,
}
self.move_user_to_group(meeting_user_to_group)
self.update_model(
"user/7",
{
"meeting_user_ids": [77],
"meeting_ids": [7],
},
)
self.update_model(
"user/111",
{
"meeting_user_ids": [7111],
"meeting_ids": [7],
},
)
status_code, data = self.request(
"get_user_editable",
{
"user_ids": [7],
"fields": ["first_name", "default_password"],
},
)
self.assertEqual(status_code, 200)
self.assertEqual(
data,
{
"7": {"default_password": [True, ""], "first_name": [True, ""]},
},
)

def test_with_all_payload_groups(self) -> None:
"""
Tests all user.create/update payload field groups. Especially the field 'saml_id'.
Expand Down

0 comments on commit 42eb249

Please sign in to comment.