mirror of
https://github.com/ae-utbm/sith.git
synced 2026-12-05 07:12:48 +00:00
add tests
This commit is contained in:
1 parent
d7fa0b5ed6
commit
2ac2bb48c2
2 files changed
+57
-1
No files matched your search
@@ -295,6 +295,49 @@ def test_user_update_groups(client: Client):
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_user_update_groups_non_admin(client: Client):
|
||||
"""Test that a non-admin user can update the groups it is allowed to."""
|
||||
managed_group = baker.make(Group, is_manually_manageable=True)
|
||||
other_group = baker.make(Group, is_manually_manageable=True)
|
||||
operator = subscriber_user.make(
|
||||
groups=[baker.make(Group, managed_groups=[managed_group])]
|
||||
)
|
||||
user = baker.make(User, groups=[other_group])
|
||||
client.force_login(operator)
|
||||
response = client.post(
|
||||
reverse("core:user_groups", kwargs={"user_id": user.id}),
|
||||
data={"groups": [managed_group.id]},
|
||||
)
|
||||
assertRedirects(response, user.get_absolute_url())
|
||||
# the manageable group should have been attributed
|
||||
# and the non-manageable groups should be kept
|
||||
assert set(user.groups.all()) == {
|
||||
Group.objects.get(pk=settings.SITH_GROUP_PUBLIC_ID),
|
||||
managed_group,
|
||||
other_group,
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_user_update_groups_denied(client: Client):
|
||||
"""Test that a user that can manage no group cannot access the page at all."""
|
||||
operator = subscriber_user.make(groups=[baker.make(Group)])
|
||||
user = baker.make(User)
|
||||
client.force_login(operator)
|
||||
response = client.get(reverse("core:user_groups", kwargs={"user_id": user.id}))
|
||||
assert response.status_code == 403
|
||||
response = client.post(
|
||||
reverse("core:user_groups", kwargs={"user_id": user.id}),
|
||||
data={"groups": [baker.make(Group).id]},
|
||||
)
|
||||
assert response.status_code == 403
|
||||
# no group should have been attributed at all
|
||||
assert set(user.groups.all()) == {
|
||||
Group.objects.get(pk=settings.SITH_GROUP_PUBLIC_ID)
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_logout(client: Client):
|
||||
user = baker.make(User)
|
||||
@@ -378,6 +421,19 @@ def test_displayed_user_self_tabs(user_factory, expected_tabs: list[str]):
|
||||
"account",
|
||||
],
|
||||
),
|
||||
(
|
||||
# this user is in a group that is allowed to manage another group
|
||||
# so the groups tab should be displayed
|
||||
lambda: subscriber_user.make(
|
||||
groups=[
|
||||
baker.make(
|
||||
Group,
|
||||
managed_groups=[baker.make(Group, is_manually_manageable=True)],
|
||||
)
|
||||
]
|
||||
),
|
||||
["infos", "godfathers", "pictures", "clubs", "groups"],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_displayed_other_user_tabs(user_factory, expected_tabs: list[str]):
|
||||
|
||||
Reference in new issue
Block a user