def test_finalist_reserves_office_hour_with_conflict_reserve_fails(self):
     start_time = minutes_from_now(60)
     end_time = minutes_from_now(90)
     finalist = _finalist()
     MentorProgramOfficeHourFactory(finalist=finalist,
                                    start_date_time=start_time,
                                    end_date_time=end_time)
     new_office_hour = MentorProgramOfficeHourFactory(
         finalist=None, start_date_time=start_time, end_date_time=end_time)
     self.post_response(new_office_hour.id, request_user=finalist)
     self.assert_not_reserved(new_office_hour)
    def test_finalist_reserves_office_hour_with_conflict_fail_message(self):
        start_time = minutes_from_now(60)
        end_time = minutes_from_now(90)
        finalist = _finalist()
        MentorProgramOfficeHourFactory(finalist=finalist,
                                       start_date_time=start_time,
                                       end_date_time=end_time)

        new_office_hour = MentorProgramOfficeHourFactory(
            finalist=None, start_date_time=start_time, end_date_time=end_time)
        response = self.post_response(new_office_hour.id,
                                      request_user=finalist)
        self.assert_ui_notification(response, False, self.view.CONFLICT_EXISTS)
    def test_finalist_reserves_office_hour_with_enclosing_conflict(self):
        # "enclosing conflict": existing hour starts before and ends after
        # new hour

        finalist = _finalist()
        MentorProgramOfficeHourFactory(finalist=finalist,
                                       start_date_time=minutes_from_now(30),
                                       end_date_time=minutes_from_now(120))
        new_office_hour = MentorProgramOfficeHourFactory(
            finalist=None,
            start_date_time=minutes_from_now(60),
            end_date_time=minutes_from_now(90))
        self.post_response(new_office_hour.id, request_user=finalist)
        self.assert_not_reserved(new_office_hour)
    def test_finalist_can_reserve_adjacecent_office_hour_session(self):
        start_time = minutes_from_now(30)
        shared_midpoint = minutes_from_now(60)
        end_time = minutes_from_now(90)

        finalist = _finalist()
        MentorProgramOfficeHourFactory(finalist=finalist,
                                       start_date_time=start_time,
                                       end_date_time=shared_midpoint)
        new_office_hour = MentorProgramOfficeHourFactory(
            finalist=None,
            start_date_time=shared_midpoint,
            end_date_time=end_time)
        self.post_response(new_office_hour.id, request_user=finalist)
        self.assert_reserved_by(new_office_hour, finalist)
 def test_outlook_link_in_reserve_office_hour_email_to_mentor(self):
     office_hour = MentorProgramOfficeHourFactory(finalist=None)
     mentor = office_hour.mentor
     self.post_response(office_hour.id, request_user=_finalist())
     self.assert_notified(mentor,
                          BASE_URLS.get('outlook'),
                          check_alternative=True)
 def test_reserve_on_behalf_of_mentor_gets_email_notification(self):
     # staff reserves a session on behalf of finalist, mentor is
     # notified by email
     office_hour = MentorProgramOfficeHourFactory(finalist=None)
     finalist = _finalist()
     self.post_response(office_hour.id, finalist.id)
     self.assert_notified(office_hour.mentor)
 def test_previously_reserved_office_hour_gets_failure(self):
     # a finalist reserves a reserved office hour, gets failure response
     office_hour = MentorProgramOfficeHourFactory()
     finalist = _finalist()
     response = self.post_response(office_hour.id, request_user=finalist)
     self.assert_ui_notification(response, False,
                                 self.view.OFFICE_HOUR_ALREADY_RESERVED)
 def test_staff_user_cancels_reservation_gets_ui_notification(self):
     '''A staff user cancelling someone else's office hour should succeed'''
     office_hour = MentorProgramOfficeHourFactory()
     response = self._submit_cancellation(office_hour,
                                          user=self.staff_user())
     notification = formatted_success_notification(office_hour)
     self.assert_ui_notification(response, True, notification)
 def test_non_finalist_attempts_to_reserve_office_hour_notification(self):
     office_hour = MentorProgramOfficeHourFactory(finalist=None)
     non_finalist = self.basic_user()
     response = self.post_response(office_hour.id,
                                   request_user=non_finalist)
     self.assert_ui_notification(response, False,
                                 self.view.USER_CANNOT_RESERVE_OFFICE_HOURS)
 def create_office_hour(self,
                        mentor=None,
                        finalist=None,
                        start_date_time=None,
                        duration_minutes=30,
                        timezone="America/New_York",
                        program=None,
                        location=None,
                        startup=None):
     create_params = {}
     mentor = mentor or _mentor(program)
     create_params['mentor'] = mentor
     duration = timedelta(duration_minutes)
     start_date_time = start_date_time or utc.localize(datetime.now())
     end_date_time = start_date_time + duration
     create_params['start_date_time'] = start_date_time
     create_params['end_date_time'] = end_date_time
     create_params['location__timezone'] = timezone
     create_params['finalist'] = finalist
     create_params['program'] = program
     if startup:
         create_params['startup'] = startup
     if not timezone:
         create_params['location'] = location
     return MentorProgramOfficeHourFactory(**create_params)
 def test_finalist_reserves_office_hour_with_nonexistent_startup(self):
     startup_id = nonexistent_object_id(StartupFactory)
     office_hour = MentorProgramOfficeHourFactory(finalist=None)
     finalist = _finalist()
     response = self.post_response(office_hour.id,
                                   startup_id=startup_id,
                                   request_user=finalist)
     self.assert_ui_notification(response, False, self.view.NO_SUCH_STARTUP)
    def _submit_cancellation(self, office_hour, user, message=""):
        if office_hour is None:
            office_hour = MentorProgramOfficeHourFactory()
            office_hour_id = office_hour.id
            office_hour.delete()
        else:
            office_hour_id = office_hour.id
        user.set_password("password")
        user.save()

        with self.login(email=user.email):
            url = reverse(CancelOfficeHourReservationView.view_name)
            data = {"office_hour_id": office_hour_id,
                    "user_id": user.id,
                    "message": message}
            response = self.client.post(url, data=data)
        return response
 def test_email_notification_includes_submitted_message(self):
     cancellation_message = "Sorry I had to cancel"
     office_hour = MentorProgramOfficeHourFactory()
     self._submit_cancellation(office_hour,
                               user=office_hour.finalist,
                               message=cancellation_message)
     self.assert_notified(office_hour.mentor,
                          message=cancellation_message)
 def test_finalist_cancels_and_gets_ui_notification(self):
     '''A finalist cancelling their reservation should receive a
     UI success notification'''
     office_hour = MentorProgramOfficeHourFactory()
     response = self._submit_cancellation(office_hour,
                                          user=office_hour.finalist)
     notification = formatted_success_notification(office_hour)
     self.assert_ui_notification(response, True, notification)
 def test_non_staff_reserve_on_behalf_of_failure(self):
     # finalist reserves a session on behalf of finalist, gets failure
     office_hour = MentorProgramOfficeHourFactory(finalist=None)
     finalist = _finalist()
     response = self.post_response(office_hour.id,
                                   finalist.id,
                                   request_user=_finalist())
     self.assert_ui_notification(response, False,
                                 RESERVE_PERMISSION_DENIED_DETAIL)
    def test_correct_date_format_in_confirmation_email(self):
        # a finalist reserves and office hour, gets a confirmation email

        office_hour = MentorProgramOfficeHourFactory(finalist=None)
        finalist = _finalist()
        self.post_response(office_hour.id, request_user=finalist)
        email = mail.outbox[0]
        localized_time = localized_office_hour_start_time(office_hour)
        self.assertIn(localized_time.strftime("%I:%M"),
                      email.alternatives[0][0])
 def test_finalist_reserves_office_hour_with_unrelated_startup(self):
     startup_id = StartupFactory().id
     office_hour = MentorProgramOfficeHourFactory(finalist=None)
     finalist = _finalist()
     response = self.post_response(office_hour.id,
                                   startup_id=startup_id,
                                   request_user=finalist)
     message = self.view.STARTUP_NOT_ASSOCIATED_WITH_USER.format(
         finalist.email)
     self.assert_ui_notification(response, False, message)
    def test_finalist_reserves_office_hour_timecard(self):
        # a finalist reserves an office hour, gets timecard details in response
        office_hour = MentorProgramOfficeHourFactory(finalist=None)
        finalist = _finalist()
        stm = StartupTeamMemberFactory(user=finalist)

        response = self.post_response(office_hour.id,
                                      startup_id=stm.startup.id,
                                      request_user=finalist)
        self.assert_response_contains_session_details(response, office_hour)
 def _create_office_hour_obj(
     self,
     mentor,
     minutes_from_now=0,
     finalist=None,
     start_date_time=None,
     block_duration=30,
 ):
     start_time = start_date_time or _now() + timedelta(
         minutes=minutes_from_now)
     end_time = start_time + timedelta(minutes=block_duration)
     return MentorProgramOfficeHourFactory(
         mentor=mentor,
         start_date_time=start_time,
         end_date_time=end_time,
         finalist=finalist,
     )
 def test_staff_user_cancels_reservation(self):
     '''A staff user cancelling someone else's office hour should succeed'''
     office_hour = MentorProgramOfficeHourFactory()
     self._submit_cancellation(office_hour, user=self.staff_user())
     self.assert_reservation_cancelled(office_hour)
 def test_finalist_cancels_mentor_gets_notification(self):
     '''A finalist cancelling their reservation should trigger a
     notification to the mentor'''
     office_hour = MentorProgramOfficeHourFactory()
     self._submit_cancellation(office_hour, user=office_hour.finalist)
     self.assert_notified(office_hour.mentor)
 def test_correct_date_format_in_notification_email(self):
     office_hour = MentorProgramOfficeHourFactory()
     self._submit_cancellation(office_hour, user=office_hour.finalist)
     email = mail.outbox[0]
     localized_time = localized_office_hour_start_time(office_hour)
     self.assertIn(localized_time.strftime("%I:%M"), email.body)
 def test_user_cancels_non_existent_reservation_no_notification(self):
     office_hour = MentorProgramOfficeHourFactory(finalist=None)
     self._submit_cancellation(office_hour, user=self.make_user())
     self.assert_not_notified(office_hour.mentor)
 def test_non_staff_user_not_finalist_fails(self):
     '''A non-staff user attempting to cancel someone else's reservation
     should fail'''
     office_hour = MentorProgramOfficeHourFactory()
     self._submit_cancellation(office_hour, user=self.make_user())
     self.assert_reservation_not_cancelled(office_hour)
 def test_staff_user_cancels_nonexistent_reservation_ui_notification(self):
     office_hour = MentorProgramOfficeHourFactory(finalist=None)
     response = self._submit_cancellation(office_hour,
                                          user=self.staff_user())
     self.assert_ui_notification(response, False, NO_SUCH_RESERVATION)
 def test_finalist_cancels_their_own_office_hour_reservation(self):
     office_hour = MentorProgramOfficeHourFactory()
     self._submit_cancellation(office_hour, user=office_hour.finalist)
     self.assert_reservation_cancelled(office_hour)
 def test_staff_user_trigger_notification_finalist(self):
     '''A staff user cancelling someone else's office hour should trigger a
     notification to the finalist'''
     office_hour = MentorProgramOfficeHourFactory()
     self._submit_cancellation(office_hour, user=self.staff_user())
     self.assert_notified(office_hour.finalist)
 def test_finalist_cancels_and_gets_notification(self):
     '''A finalist cancelling their reservation should receive a
     notification'''
     office_hour = MentorProgramOfficeHourFactory()
     self._submit_cancellation(office_hour, user=office_hour.finalist)
     self.assert_notified(office_hour.finalist)
 def test_non_staff_user_not_finalist_no_notification(self):
     '''A non-staff user attempting to cancel someone else's reservation
     should not receive a notification'''
     office_hour = MentorProgramOfficeHourFactory()
     self._submit_cancellation(office_hour, user=self.make_user())
     self.assert_not_notified(office_hour.mentor)
 def test_finalist_reserves_office_hour_success(self):
     # a finalist reserves an office hour, gets success response
     office_hour = MentorProgramOfficeHourFactory(finalist=None)
     finalist = _finalist()
     response = self.post_response(office_hour.id, request_user=finalist)
     self.assert_ui_notification(response, True, None, office_hour)