def test_doctor_appointments(test_user): doctor_profile = DoctorProfileFactory() AppointmentFactory(visitor=test_user) doctor_appointment = AppointmentFactory(doctor=doctor_profile) queryset = AppointmentSelector.doctor_appointments(doctor_profile) assert isinstance(queryset, QuerySet) assert queryset.count() == 1 assert queryset.first() == doctor_appointment
def appointments(self, request, doctor_uuid, **kwargs): """It shows the appointments to the professionals.""" doctor = DoctorProfileSelector.get_by_uuid(doctor_uuid) appointments = AppointmentSelector.doctor_appointments(doctor) return Response(AppointmentSerializer(appointments, many=True).data)
def retrieve(self, request, appointment_uuid, **kwargs): appointment = AppointmentSelector.get_by_uuid(appointment_uuid) return Response(AppointmentSerializer(appointment).data)
def appointments(self, request, **kwargs): """It shows the visitors' appointments.""" appointments = AppointmentSelector.user_appointments(request.user) return Response(AppointmentSerializer(appointments, many=True).data)
def get_context_data(self, **kwargs): context = super().get_context_data() context['user'] = self.request.user context['appointments'] = AppointmentSelector.user_appointments(self.request.user) return context
def test_user_appointments_empty(test_user): doctor_profile = DoctorProfileFactory() AppointmentFactory(doctor=doctor_profile) queryset = AppointmentSelector.user_appointments(test_user) assert isinstance(queryset, QuerySet) assert queryset.count() == 0
def test_get_by_uuid_not_found(): with pytest.raises(NotFound) as exec_info: AppointmentSelector.get_by_uuid(faker.uuid4()) assert exec_info.value.detail.code == APPOINTMENT_NOT_FOUND['code']
def test_get_by_uuid(): appointment = AppointmentFactory() selected_appointment = AppointmentSelector.get_by_uuid(str(appointment.uuid)) assert isinstance(selected_appointment, Appointment) assert selected_appointment == appointment