-
-
Notifications
You must be signed in to change notification settings - Fork 965
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed #1756 -- hide unpublished events from side menus for staff #1820
Fixed #1756 -- hide unpublished events from side menus for staff #1820
Conversation
dc500c9
to
ac1080d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, nice work! 🎸
The code change looks good, I just had a note about the test (I like the use of assertQuerySetEqual
on response.context["events"]
by the way, that seems like a robust and effective way to test what we want here 👍🏻 ).
blog/tests.py
Outdated
response = self.client.get(reverse("weblog:index")) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertQuerySetEqual(response.context["events"], []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new test already passes with the old version of the code, because it's not useing a logged-in staff user.
I suggest to test things with three types of users: anonymous (not logged in), logged in (not staff), and logged in (staff). Something like this should work (not tested):
response = self.client.get(reverse("weblog:index")) | |
self.assertEqual(response.status_code, 200) | |
self.assertQuerySetEqual(response.context["events"], []) | |
for user in [ | |
None, | |
User.objects.create(is_staff=False), | |
User.objects.create(is_staff=True), | |
]: | |
if user: | |
self.client.force_login(user) | |
response = self.client.get(reverse("weblog:index")) | |
with self.subTest(user=user): | |
self.assertEqual(response.status_code, 200) | |
self.assertQuerySetEqual(response.context["events"], []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for these tests! I didn't think to check the anonymous, staff, and non-staff users. I've added these cases along with a superuser for good measure!
ac1080d
to
0909a14
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent, nice work 👍🏻
@ontowhee awesome work. Thank you! |
Fixed #1756. Only return published events, even for staff users.