def test_success_complete_restart(self): """ 모든 회차 설정이 끝난 경우 + 재설정인 경우 """ p = Patient.objects.create(code='A00112345678', kakao_user_id='abc123', measurement_noti_flag=True, daily_measurement_count=1, measurement_noti_time_1=datetime.datetime(2019, 11, 1, 15, 00, 00).astimezone()) response = self.client.post(self.url + '?restart=true', self.data, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertIn('모든 회차 알림 설정을 마쳤습니다', message_in_response(response)) self.assertIn('5dc709d48192ac0001c5d9cd', message_in_response(response))
def test_success_restart(self): """ 아직 회차 설정이 남은 경우 + 재설정인 경우 """ p = Patient.objects.create(code='A00112345678', kakao_user_id='abc123', measurement_noti_flag=True, daily_measurement_count=3, measurement_noti_time_1=datetime.datetime(2019, 11, 1, 15, 00, 00).astimezone()) response = self.client.post(self.url + '?restart=true', self.data, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertIn('10시 00분', message_in_response(response)) self.assertIn('5dc7097affa74800014107ac', message_in_response(response))
def test_fail_when_patient_didnt_set_noti_time(self): p = Patient.objects.create( code='P12312345678', kakao_user_id='asd123', medication_manage_flag=True, daily_medication_count=3, medication_noti_flag=True ) response = self.client.post(self.url, self.data, format='json') p.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertIn('설정된 복약 알림이 없습니다', message_in_response(response))
def test_success_for_question(self): """ 회차가 남아있는 경우 """ Patient.objects.create(code='A00112345678', kakao_user_id='abc123', measurement_manage_flag=True, daily_measurement_count=3) response = self.client.post(self.url, self.data, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertIn('1회차 산소포화도 확인 알림을 설정할까요', message_in_response(response))
def test_success(self): p = Patient.objects.create( code='P12312345678', kakao_user_id='asd123', medication_manage_flag=True, daily_medication_count=3, medication_noti_flag=True, medication_noti_time_1=datetime.time(hour=8), medication_noti_time_2=datetime.time(hour=10), medication_noti_time_3=datetime.time(hour=12), ) response = self.client.post(self.url, self.data, format='json') p.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertIn('오늘 복약 후에 몸에 이상 반응은 없었나요?', message_in_response(response))
def test_fail_404(self): """ Exception for 404 not found """ data = { 'userRequest': {'user': {'id': 'unknown-user-id'}}, } response = self.client.post(self.url, data, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertIn('계정을 먼저 등록해주셔야 해요. 계정을 등록하러 가볼까요?', message_in_response(response))
def test_success_for_complete(self): """ 회차가 남아있지 않은 경우 """ Patient.objects.create(code='A00112345678', kakao_user_id='abc123', measurement_noti_flag=True, daily_measurement_count=1, measurement_noti_time_1=datetime.datetime(2019, 11, 1, 15, 00, 00).astimezone()) response = self.client.post(self.url, self.data, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertIn('이미 모든 회차 알림 설정을 마쳤습니다.', message_in_response(response))
def test_measurement_management_entrance_reset(self): """ 산소포화도 관리 재설정 단계 진입 """ Patient.objects.create(code='P12312345678', kakao_user_id='asd123', measurement_manage_flag=True) data = { 'userRequest': {'user': {'id': 'asd123'}}, } response = self.client.post(self.url, data, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertIn('산소포화도 관리를 설정한 적이 있습니다. 다시 설정할까요?', message_in_response(response))
def test_measurement_management_entrance_first(self): """ 산소포화도 관리 첫 시작 단계 진입 """ Patient.objects.create(code='P12312345678', kakao_user_id='asd123') data = { 'userRequest': {'user': {'id': 'asd123'}}, } response = self.client.post(self.url, data, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertIn('안녕하세요 콜로크만 박사입니다. 저와 함께 산소포화도 관리를 시작해보시겠습니까', message_in_response(response))
def test_success(self): p = Patient.objects.create( code='P12312345678', kakao_user_id='asd123', medication_manage_flag=True, daily_medication_count=3, medication_noti_flag=True, medication_noti_time_1=datetime.time(hour=8), medication_noti_time_2=datetime.time(hour=10), medication_noti_time_3=datetime.time(hour=12), ) response = self.client.post(self.url, self.data, format='json') p.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(p.medication_results.last().get_status(), MedicationResult.STATUS.FAILED) self.assertEqual(p.medication_results.last().medication_time_num, 1) self.assertEqual(p.medication_results.last().medication_time, datetime.time(hour=8)) self.assertIn('다음 회차에는 꼭 복약하셔야합니다. ', message_in_response(response))
def test_restart_success(self): """ url에 ?restart=true가 붙은 경우 다른 응답 내려주기 """ p = Patient.objects.create(code='A00112345678', kakao_user_id='abc123', measurement_noti_flag=True, daily_measurement_count=3, measurement_noti_time_1=datetime.datetime(2019, 11, 1, 15, 00, 00).astimezone()) p.reset_measurement_noti_time() p.save() p.refresh_from_db() response = self.client.post(self.url + '?restart=true', self.data, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertIn('5dc709c38192ac0001c5d9cb', message_in_response(response))
def test_measurement_management_entrance_fail_404(self): """ Exception for 404 not found """ url = reverse('patient-measurement-entrance') data = { 'userRequest': {'user': {'id': 'unknown-user-id'}}, } response = self.client.post(self.url, data, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) # TODO mock.patch # with patch('core.api.views.measurement.PatientMeasurementEntrance.build_response_fallback_404' # ) as build_response_fallback_404: # build_response_fallback_404.assert_called() self.assertIn('계정을 먼저 등록해주셔야 해요. 계정을 등록하러 가볼까요?', message_in_response(response))
def test_restart_need_reset_time(self): """ 04-2 건강재설정_알림 설정 질문_시간대리셋필요 5dc72164ffa74800014107b7 detail_params에 reset_measurement_noti_time == true 인 경우. patient.reset_measurement_noti_time() """ p = Patient.objects.create(code='A00112345678', kakao_user_id='abc123', measurement_noti_flag=True, daily_measurement_count=1, measurement_noti_time_1=datetime.datetime(2019, 11, 1, 15, 00, 00).astimezone()) data = self.data.copy() data['action'] = {'detailParams': {'reset_measurement_noti_time': {'value': 'true'}}} response = self.client.post(self.url + '?restart=true', data, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertNotIn('이미 모든 회차 알림 설정을 마쳤습니다', message_in_response(response))
def test_fail_when_patient_not_set_next_visiting_date_time(self): """ Test failed response when patient.next_visiting_date_time does not exist. """ Patient.objects.create(code='A00112345678', kakao_user_id='abc123', visit_manage_flag=False, next_visiting_date_time=datetime.datetime( year=2019, month=11, day=7, hour=10, minute=10).astimezone()) response = self.client.post(self.url, self.data, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertIn('설정된 내원일이 없습니다', message_in_response(response))
def test_create_fail_when_patient_code_exists(self): h = Hospital.objects.create(code='A001', name='seobuk') Patient.objects.create(code='A00112345678', kakao_user_id='another-user', hospital=h) data = { 'userRequest': {'user': {'id': 'asd123'}}, 'action': { 'detailParams': { 'patient_code': {'value': 'A00112345678'}, 'nickname': {'value': '별님'} } } } response = self.client.post(self.url, data, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(Patient.objects.count(), 1) self.assertIn('이미 등록된 환자 코드입니다', message_in_response(response))
def test_success(self): """ Test successful response when patient exists and visit_manage_flag is True. Expect response.data has value of strfied next_visiting_date_time. """ Patient.objects.create(code='A00112345678', kakao_user_id='abc123', visit_manage_flag=True, next_visiting_date_time=datetime.datetime( year=2019, month=11, day=7, hour=10, minute=10).astimezone()) response = self.client.post(self.url, self.data, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertIn('내원 일정을 수정하시겠습니까', message_in_response(response))
def test_success_discharged(self): """ 퇴원 환자인 경우 """ p = Patient.objects.create(code='A00112345678', kakao_user_id='abc123', discharged_flag=True) data = { 'userRequest': { 'user': { 'id': 'abc123' } }, 'action': { 'params': {} } } response = self.client.post(self.url, data, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertIn('내원 관리를 시작하시겠습니까?', message_in_response(response))
def test_success_already_setup(self): """ 이미 내원일 설정한 경우 """ p = Patient.objects.create(code='A00112345678', kakao_user_id='abc123', visit_manage_flag=True, next_visiting_date_time=datetime.datetime( year=2019, month=11, day=7, hour=10, minute=10).astimezone()) data = { 'userRequest': { 'user': { 'id': 'abc123' } }, } response = self.client.post(self.url, data, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertIn('이미 내원일을 설정하신 적이 있어요', message_in_response(response))