[docs]deftest_eighth_admin_dashboard_view(self):"""Tests :func:`~intranet.apps.eighth.views.admin.general.eighth_admin_dashboard_view`."""user=self.login()# Test as non-eighth adminresponse=self.client.get(reverse("eighth_admin_dashboard"))self.assertEqual(response.status_code,302)user=self.make_admin()foriinrange(1,21):self.add_activity(name=f"Test{i}")Group.objects.create(name=f"Test{i}")user=get_user_model().objects.create(username=f"awilliam{i}")EighthRoom.objects.create(name=f"Test{i}")EighthSponsor.objects.create(user=user,first_name=f"Angela{i}",last_name="William")self.add_block(date="9001-4-20",block_letter="A")response=self.client.get(reverse("eighth_admin_dashboard"))self.assertTemplateUsed(response,"eighth/admin/dashboard.html")self.assertEqual(response.context["start_date"],awaredate())self.assertQuerysetEqual(response.context["all_activities"],[repr(activity)foractivityinEighthActivity.objects.all().order_by("name")],transform=repr)self.assertQuerysetEqual(response.context["blocks_after_start_date"],[repr(block)forblockinEighthBlock.objects.all()],transform=repr)self.assertQuerysetEqual(response.context["groups"],[repr(group)forgroupinGroup.objects.all().order_by("name")],transform=repr)self.assertQuerysetEqual(response.context["rooms"],[repr(room)forroominEighthRoom.objects.all()],transform=repr)self.assertQuerysetEqual(response.context["sponsors"],[repr(sponsor)forsponsorinEighthSponsor.objects.order_by("last_name","first_name").all()],transform=repr,)self.assertQuerysetEqual(response.context["blocks_next"],[repr(block)forblockinEighthBlock.objects.filter(date="9001-4-20").all()],transform=repr)self.assertEqual(response.context["blocks_next_date"],datetime.datetime(9001,4,20).date())self.assertEqual(response.context["admin_page_title"],"Eighth Period Admin")self.assertEqual(response.context["signup_users_count"],get_user_model().objects.get_students().count())
[docs]deftest_edit_start_date_view(self):"""Tests :func:`~intranet.apps.eighth.views.admin.general.edit_start_date_view`."""self.make_admin()# Load the pageresponse=self.client.get(reverse("eighth_admin_edit_start_date"))self.assertEqual(200,response.status_code)# Change the date - set it to yesterdayresponse=self.client.post(reverse("eighth_admin_edit_start_date"),data={"date":(timezone.localtime().date()-timezone.timedelta(days=1)).isoformat()})self.assertEqual(302,response.status_code)
[docs]deftest_cache_view(self):"""Tests :func:`~intranet.apps.eighth.views.admin.general.cache_view`."""self.make_admin()# Load the pageresponse=self.client.get(reverse("eighth_admin_cache"))self.assertEqual(200,response.status_code)# Change the date - set it to yesterdayresponse=self.client.post(reverse("eighth_admin_cache"),data={"invalidate_all":True})self.assertEqual(200,response.status_code)
[docs]deftest_history_view(self):"""Tests :func:`~intranet.apps.eighth.views.admin.general.history_view`."""self.make_admin()# Load the pageresponse=self.client.get(reverse("eighth_admin_history"))self.assertEqual(200,response.status_code)