|
5 | 5 | from datetime import timedelta |
6 | 6 | from django.core.cache import cache |
7 | 7 |
|
| 8 | +from django.urls import reverse |
| 9 | + |
8 | 10 | from courses.models import ( |
9 | 11 | Course, |
10 | 12 | Homework, |
@@ -155,3 +157,51 @@ def test_leaderboard_cache_invalidation(self): |
155 | 157 |
|
156 | 158 | # Cache should be invalidated (None) |
157 | 159 | self.assertIsNone(cache.get(cache_key)) |
| 160 | + |
| 161 | + def test_score_breakdown_admin_button_visible_for_staff(self): |
| 162 | + """Test that admin edit button is visible on score breakdown page for staff users""" |
| 163 | + enrollment = self.create_student("student1") |
| 164 | + admin_user = User.objects.create_user(username="admin", is_staff=True) |
| 165 | + |
| 166 | + self.client.force_login(admin_user) |
| 167 | + url = reverse("leaderboard_score_breakdown", kwargs={ |
| 168 | + "course_slug": self.course.slug, |
| 169 | + "enrollment_id": enrollment.id, |
| 170 | + }) |
| 171 | + response = self.client.get(url) |
| 172 | + |
| 173 | + self.assertEqual(response.status_code, 200) |
| 174 | + admin_edit_url = reverse("cadmin_enrollment_edit", kwargs={ |
| 175 | + "course_slug": self.course.slug, |
| 176 | + "enrollment_id": enrollment.id, |
| 177 | + }) |
| 178 | + self.assertContains(response, admin_edit_url) |
| 179 | + self.assertContains(response, "fa-cog") |
| 180 | + |
| 181 | + def test_score_breakdown_admin_button_hidden_for_regular_user(self): |
| 182 | + """Test that admin edit button is hidden on score breakdown page for regular users""" |
| 183 | + enrollment = self.create_student("student1") |
| 184 | + regular_user = User.objects.create_user(username="regular", is_staff=False) |
| 185 | + |
| 186 | + self.client.force_login(regular_user) |
| 187 | + url = reverse("leaderboard_score_breakdown", kwargs={ |
| 188 | + "course_slug": self.course.slug, |
| 189 | + "enrollment_id": enrollment.id, |
| 190 | + }) |
| 191 | + response = self.client.get(url) |
| 192 | + |
| 193 | + self.assertEqual(response.status_code, 200) |
| 194 | + self.assertNotContains(response, "fa-cog") |
| 195 | + |
| 196 | + def test_score_breakdown_admin_button_hidden_for_anonymous(self): |
| 197 | + """Test that admin edit button is hidden on score breakdown page for anonymous users""" |
| 198 | + enrollment = self.create_student("student1") |
| 199 | + |
| 200 | + url = reverse("leaderboard_score_breakdown", kwargs={ |
| 201 | + "course_slug": self.course.slug, |
| 202 | + "enrollment_id": enrollment.id, |
| 203 | + }) |
| 204 | + response = self.client.get(url) |
| 205 | + |
| 206 | + self.assertEqual(response.status_code, 200) |
| 207 | + self.assertNotContains(response, "fa-cog") |
0 commit comments