[docs]classEighthAbstractTest(IonTestCase):"""Base class to be inherited by the test cases for the Eighth app."""defsetUp(self):self.user=get_user_model().objects.get_or_create(username="awilliam",graduation_year=get_senior_graduation_year()+1,id=8889)[0]
[docs]defcreate_sponsor(self)->User:""" Creates a teacher. Returns: a User object that is a teacher """returnget_user_model().objects.get_or_create(username="ateacher",first_name="A",last_name="Teacher",user_type="teacher")[0]
[docs]defadd_block(self,date:str,block_letter:str,**kwargs)->EighthBlock:""" Adds an EighthBlock. Arguments are passed to intranet.apps.eighth.forms.admin.blocks.QuickBlockForm. Args: date: Date in YYYY-MM-DD format block_letter: The corresponding block letter Returns: The EighthBlock that was created. """# Bypass the manual block creation form.kwargs.update({"custom_block":True})response=self.client.post(reverse("eighth_admin_add_block"),{"date":date,"block_letter":block_letter,**kwargs})self.assertEqual(response.status_code,302)returnEighthBlock.objects.get(date=date,block_letter=block_letter)
[docs]defadd_room(self,name:str,capacity:int=1,**kwargs)->EighthRoom:""" Adds an EighthRoom. Arguments are passed to intranet.apps.eighth.forms.admin.rooms.RoomForm. Args: name: The name of the room. capacity: The room capacity. Returns: The EighthRoom created. """response=self.client.post(reverse("eighth_admin_add_room"),{"name":name,"capacity":capacity,**kwargs})self.assertEqual(response.status_code,302)returnEighthRoom.objects.get(name=name)
[docs]defadd_activity(self,name:str,**args)->EighthActivity:""" Add an EighthActivity. Args: name: The name of the activity to add args: The remaining arguments are passed to :func:`~intranet.apps.eighth.views.admin.activities.add_activity_view`. Returns: The EighthActivity added. """arguments={"name":name}arguments.update(args)response=self.client.post(reverse("eighth_admin_add_activity"),arguments)self.assertEqual(response.status_code,302)returnEighthActivity.objects.get(name=arguments["name"])
[docs]defschedule_activity(self,block_id:int,activity_id:int,capacity:int=1)->EighthScheduledActivity:""" Creates an EighthScheduledActivity; aka schedule an eighth period activity. Args: block_id: The block ID activity_id: Activity ID capacity: Maximum capacity for this activity Returns: The EighthScheduledActivity created. """# FIXME: figure out a way to do this that involves less hard-coding.args={"form-TOTAL_FORMS":"1","form-INITIAL_FORMS":"0","form-MAX_NUM_FORMS":"","form-0-block":block_id,"form-0-activity":activity_id,"form-0-scheduled":True,"form-0-capacity":capacity,}response=self.client.post(reverse("eighth_admin_schedule_activity"),args)self.assertEqual(response.status_code,302)returnEighthScheduledActivity.objects.get(block__id=block_id,activity__id=activity_id)