def test_search_by_appointment_cancel_reason(self, coe_advisor, client): """Appointments can be searched for by cancel reason and cancel reason explained.""" appointment = Appointment.find_by_id(1) Appointment.cancel( appointment_id=appointment.id, canceled_by=AuthorizedUser.get_id_per_uid('6972201'), cancel_reason='Sick cat', cancel_reason_explained= 'Student needed to attend to ailing feline.', ) response = client.post( '/api/search', data=json.dumps({ 'appointments': True, 'notes': True, 'searchPhrase': 'cat' }), content_type='application/json', ) self._assert(response, appointment_count=1) response = client.post( '/api/search', data=json.dumps({ 'appointments': True, 'notes': True, 'searchPhrase': 'feline' }), content_type='application/json', ) self._assert(response, appointment_count=1)
def test_search_by_appointment_cancel_reason(self, coe_advisor, client): """Appointments can be searched for by cancel reason and cancel reason explained.""" appointment = Appointment.find_by_id(1) Appointment.cancel( appointment_id=appointment.id, cancelled_by=AuthorizedUser.get_id_per_uid('6972201'), cancel_reason='Sick cat', cancel_reason_explained= 'Student needed to attend to ailing feline.', ) api_json = _api_search(client, 'cat', appointments=True) self._assert(api_json, appointment_count=1) api_json = _api_search(client, 'feline', appointments=True) self._assert(api_json, appointment_count=1)
def _create_cancelled_appointments(): coe_advisor_user_id = AuthorizedUser.get_id_per_uid('90412') scheduler_user_id = AuthorizedUser.get_id_per_uid('6972201') cancel_me = Appointment.create( appointment_type='Drop-in', created_by=coe_advisor_user_id, dept_code='COENG', details='We will cancel this appointment.', student_sid='7890123456', topics=['Whoops'], ) Appointment.cancel( appointment_id=cancel_me.id, cancelled_by=scheduler_user_id, cancel_reason='Just because', cancel_reason_explained='I felt like it.', )
def cancel_appointment(appointment_id): appointment = Appointment.find_by_id(appointment_id) if not appointment: raise ResourceNotFoundError('Unknown path') has_privilege = current_user.is_admin or appointment.dept_code in _dept_codes_with_scheduler_privilege() if not has_privilege: raise ForbiddenRequestError(f'You are unauthorized to manage {appointment.dept_code} appointments.') if not appointment.status_change_available(): raise BadRequestError(appointment.to_api_json(current_user.get_id())) params = request.get_json() cancel_reason = params.get('cancelReason', None) cancel_reason_explained = params.get('cancelReasonExplained', None) Appointment.cancel( appointment_id=appointment_id, cancelled_by=current_user.get_id(), cancel_reason=cancel_reason, cancel_reason_explained=cancel_reason_explained, ) return Response(status=200)
def cancel_appointment(appointment_id): appointment = Appointment.find_by_id(appointment_id) if not appointment: raise ResourceNotFoundError('Unknown path') if current_user.is_admin or appointment.dept_code in _dept_codes_with_scheduler_privilege( ): params = request.get_json() cancel_reason = params.get('cancelReason', None) cancel_reason_explained = params.get('cancelReasonExplained', None) appointment = Appointment.cancel( appointment_id=appointment_id, canceled_by=current_user.get_id(), cancel_reason=cancel_reason, cancel_reason_explained=cancel_reason_explained, ) api_json = appointment.to_api_json(current_user.get_id()) _put_student_profile_per_appointment([api_json]) return tolerant_jsonify(api_json) else: raise ForbiddenRequestError( f'You are unauthorized to manage {appointment.dept_code} appointments.' )