-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Déplace get_authorized_forums() vers zds/forum/utils.py (#6522)
- ce n'est pas (plus ?) un templatetag - renommage en get_authorized_forums_pk() pour être plus explicite sur ce qui est retourné - ajout de tests
- Loading branch information
1 parent
46b253e
commit aaacd06
Showing
4 changed files
with
53 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from django.contrib.auth.models import Group | ||
from django.test import TestCase | ||
|
||
from zds.forum.tests.factories import create_category_and_forum | ||
from zds.forum.utils import get_authorized_forums_pk | ||
from zds.member.tests.factories import ProfileFactory, StaffProfileFactory | ||
|
||
|
||
class GetAuthorizedForumsTests(TestCase): | ||
def test_get_authorized_forums_pk(self): | ||
user = ProfileFactory().user | ||
staff = StaffProfileFactory().user | ||
|
||
# 1. Create a hidden forum belonging to a hidden staff group: | ||
group = Group.objects.create(name="Les illuminatis anonymes de ZdS") | ||
_, hidden_forum = create_category_and_forum(group) | ||
|
||
staff.groups.add(group) | ||
staff.save() | ||
|
||
# 2. Create a public forum: | ||
_, public_forum = create_category_and_forum() | ||
|
||
# 3. Regular user can access only the public forum: | ||
self.assertEqual(get_authorized_forums_pk(user), [public_forum.pk]) | ||
|
||
# 4. Staff user can access all forums: | ||
self.assertEqual(sorted(get_authorized_forums_pk(staff)), sorted([hidden_forum.pk, public_forum.pk])) | ||
|
||
# 5. By default, only public forums are available: | ||
self.assertEqual(get_authorized_forums_pk(None), [public_forum.pk]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.