|
1 | 1 | import json |
2 | 2 |
|
3 | 3 | from django.contrib.auth import get_user_model |
| 4 | +from django.test import override_settings |
4 | 5 | from django.test.client import RequestFactory |
5 | 6 | from django.urls import reverse |
6 | 7 | from django.utils import timezone |
|
9 | 10 |
|
10 | 11 | from ...schedule.models import Block, Day, DayType, Time |
11 | 12 | from ..exceptions import SignupException |
12 | | -from ..models import EighthActivity, EighthBlock, EighthScheduledActivity, EighthSignup |
| 13 | +from ..models import EighthActivity, EighthBlock, EighthScheduledActivity, EighthSignup, EighthWaitlist |
13 | 14 | from .eighth_test import EighthAbstractTest |
14 | 15 |
|
15 | 16 |
|
@@ -295,6 +296,43 @@ def test_eighth_signup_view(self): |
295 | 296 | self.assertEqual(302, response.status_code) |
296 | 297 | self.assertEqual(reverse("eighth_signup", kwargs={"block_id": block1.id}) + f"?user={user.id}", response.url) |
297 | 298 |
|
| 299 | + @override_settings(ENABLE_WAITLIST=True) |
| 300 | + def test_eighth_signup_view_includes_waitlist_metadata(self): |
| 301 | + get_user_model().objects.all().delete() |
| 302 | + user = self.login("2021awilliam") |
| 303 | + user.user_type = "student" |
| 304 | + user.graduation_year = get_senior_graduation_year() |
| 305 | + user.save() |
| 306 | + |
| 307 | + today = timezone.localtime().date() |
| 308 | + block = EighthBlock.objects.get_or_create(date=today, block_letter="A")[0] |
| 309 | + |
| 310 | + activity_waitlisted = EighthActivity.objects.get_or_create(name="Waitlisted Activity", default_capacity=1)[0] |
| 311 | + scheduled_waitlisted = EighthScheduledActivity.objects.get_or_create(block=block, activity=activity_waitlisted, capacity=1)[0] |
| 312 | + |
| 313 | + activity_other = EighthActivity.objects.get_or_create(name="Other Activity", default_capacity=1)[0] |
| 314 | + scheduled_other = EighthScheduledActivity.objects.get_or_create(block=block, activity=activity_other, capacity=1)[0] |
| 315 | + |
| 316 | + other_user = get_user_model().objects.create(username="someone_else", graduation_year=get_senior_graduation_year()) |
| 317 | + EighthWaitlist.objects.create(user=user, block=block, scheduled_activity=scheduled_waitlisted) |
| 318 | + EighthWaitlist.objects.create(user=other_user, block=block, scheduled_activity=scheduled_waitlisted) |
| 319 | + EighthWaitlist.objects.create(user=other_user, block=block, scheduled_activity=scheduled_other) |
| 320 | + |
| 321 | + response = self.client.get(reverse("eighth_signup", kwargs={"block_id": block.id})) |
| 322 | + self.assertEqual(200, response.status_code) |
| 323 | + |
| 324 | + act_list = json.loads(str(response.context["activities_list"]).encode().decode("unicode-escape")) |
| 325 | + waitlisted_info = act_list[str(activity_waitlisted.id)] |
| 326 | + other_info = act_list[str(activity_other.id)] |
| 327 | + |
| 328 | + self.assertTrue(waitlisted_info["waitlisted"]) |
| 329 | + self.assertEqual(1, waitlisted_info["waitlist_position"]) |
| 330 | + self.assertEqual(2, waitlisted_info["waitlist_count"]) |
| 331 | + |
| 332 | + self.assertFalse(other_info["waitlisted"]) |
| 333 | + self.assertEqual(0, other_info["waitlist_position"]) |
| 334 | + self.assertEqual(1, other_info["waitlist_count"]) |
| 335 | + |
298 | 336 | def test_eighth_multi_signup_view(self): |
299 | 337 | """Tests :func:`~intranet.apps.eighth.views.signup.eighth_multi_signup_view`.""" |
300 | 338 |
|
|
0 commit comments