def test_context_data(self) -> None:
     # Arrange
     request = RequestFactory().get("/")
     organization = Organization.objects.first()
     event = Event.objects.create(
         slug="test-event",
         host=organization,
         administrator=organization,
         start=date(2021, 12, 29),
     )
     view = InstructorRecruitmentCreate(request=request, object=None)
     view.event = event
     # Act
     context = view.get_context_data()
     # Assert
     self.assertEqual(
         context,
         {
             "title": "Begin Instructor Selection Process for test-event",
             "event": event,
             "event_dates": "Dec 29, 2021-???",
             "view": view,
             "model": InstructorRecruitment,
             # it needs to be the same instance, otherwise the test fails
             "form": context["form"],
         },
     )
 def test_get_other_object(self) -> None:
     # Arrange
     organization = Organization.objects.first()
     event = Event.objects.create(
         slug="test-event",
         host=organization,
         administrator=organization,
     )
     view = InstructorRecruitmentCreate(kwargs={"event_id": event.pk})
     # Act
     object = view.get_other_object()
     # Assert
     self.assertEqual(event, object)
 def test_post(self) -> None:
     # Arrange
     request = RequestFactory().post("/")
     organization = Organization.objects.first()
     event = Event.objects.create(
         slug="test-event",
         host=organization,
         administrator=organization,
     )
     view = InstructorRecruitmentCreate(kwargs={"event_id": event.pk})
     # Act
     with mock.patch("recruitment.views.super") as mock_super:
         view.post(request)
     # Assert
     self.assertEqual(view.request, request)
     self.assertEqual(view.event, event)
     mock_super().post.assert_called_once_with(request)
 def test_get_form_kwargs(self) -> None:
     # Arrange
     request = RequestFactory().get("/")
     organization = Organization.objects.first()
     event = Event.objects.create(
         slug="test-event",
         host=organization,
         administrator=organization,
     )
     view = InstructorRecruitmentCreate(request=request)
     view.event = event
     # Act
     kwargs = view.get_form_kwargs()
     # Assert
     self.assertEqual(kwargs, {
         "initial": {},
         "prefix": "instructorrecruitment"
     })
 def test_form_valid(self) -> None:
     # Arrange
     request = RequestFactory().get("/")
     mock_form = mock.MagicMock()
     organization = Organization.objects.first()
     event = Event.objects.create(
         slug="test-event",
         host=organization,
         administrator=organization,
     )
     view = InstructorRecruitmentCreate(request=request)
     view.event = event
     # Act
     with mock.patch("recruitment.views.super") as mock_super:
         view.form_valid(mock_form)
     # Assert
     mock_form.save.assert_called_once_with(commit=False)
     self.assertEqual(view.object.event, event)
     mock_super().form_valid.assert_called_once_with(mock_form)
 def test_class_fields(self) -> None:
     # Arrange
     view = InstructorRecruitmentCreate()
     # Assert
     self.assertEqual(view.permission_required,
                      "recruitment.add_instructorrecruitment")
     self.assertEqual(view.model, InstructorRecruitment)
     self.assertEqual(view.template_name,
                      "recruitment/instructorrecruitment_add.html")
     self.assertEqual(view.form_class, InstructorRecruitmentCreateForm)
     self.assertEqual(view.event, None)
 def test_get_initial(self) -> None:
     # Arrange
     request = RequestFactory().get("/")
     organization = Organization.objects.first()
     event = Event.objects.create(
         slug="test-event",
         host=organization,
         administrator=organization,
     )
     workshop_request = WorkshopRequest.objects.create(
         event=event,
         personal="Harry",
         family="Potter",
         email="*****@*****.**",
         institution_other_name="Hogwarts",
         location="Scotland",
         country="GB",
         audience_description="Students of Hogwarts",
         user_notes="Only Gryffindor allowed.",
         number_attendees="10-40",
         administrative_fee="nonprofit",
         language=Language.objects.get(name="English"),
     )
     view = InstructorRecruitmentCreate(request=request, object=None)
     view.event = event
     # Act
     initial = view.get_initial()
     # Assert
     self.assertEqual(
         initial,
         {
             "notes":
             f"{workshop_request.audience_description}\n\n"
             f"{workshop_request.user_notes}",
         },
     )