Ejemplo n.º 1
0
 def test_list_by_participant_empty(self):
     StudyFactory.create()
     StudyFactory.create()
     ParticipantFactory.create(doctor_ptr=self.other_doctor)
     self.authenticate_as_doctor(self.other_doctor)
     resp = self.client.get('/api/v1/study/', format='json')
     self.assertSuccessResponse(resp)
     self.assertEqual(len(resp.data), 0)
Ejemplo n.º 2
0
    def test_list_as_participant(self):
        participant = DoctorFactory.create(password='******')
        ParticipantFactory.create(doctor_ptr=participant)
        patient = PatientFactory.create(doctor=participant)
        self.authenticate_as_doctor(participant)

        resp = self.client.get('/api/v1/patient/')
        self.assertSuccessResponse(resp)
        self.assertEqual(len(resp.data), 1)
        self.assertEqual(resp.data[0]['pk'], patient.pk)
Ejemplo n.º 3
0
 def test_list_by_participant(self):
     study = StudyFactory.create()
     study2 = StudyFactory.create()
     ParticipantFactory.create(doctor_ptr=self.other_doctor)
     DoctorToPatient.objects.create(patient=self.patient,
                                    doctor=self.other_doctor,
                                    encrypted_key='123')
     StudyToPatient.objects.create(study=study, patient=self.patient)
     self.authenticate_as_doctor(self.other_doctor)
     resp = self.client.get('/api/v1/study/', format='json')
     self.assertSuccessResponse(resp)
     self.assertEqual(len(resp.data), 1)
     self.assertEqual(resp.data[0]['pk'], study.pk)
Ejemplo n.º 4
0
 def test_add_doctor_forbidden(self):
     study = StudyFactory.create(author=self.coordinator)
     doctor = DoctorFactory.create(my_coordinator=self.coordinator)
     patient = DoctorFactory.create()
     ParticipantFactory.create(doctor_ptr=patient)
     emails = [
         doctor.email, self.doctor.email, patient.email, '*****@*****.**'
     ]
     resp = self.client.post('/api/v1/study/{0}/add_doctor/'.format(
         study.pk), {
             'doctor_pk': doctor.pk,
             'emails': emails
         },
                             format='json')
     self.assertUnauthorized(resp)
Ejemplo n.º 5
0
    def test_add_doctor_invited_email(self):
        study = StudyFactory.create(author=self.coordinator)
        doctor = DoctorFactory.create(my_coordinator=self.coordinator)
        patient = DoctorFactory.create()
        ParticipantFactory.create(doctor_ptr=patient)
        self.authenticate_as_doctor()

        StudyInvitationFactory.create(email='*****@*****.**', study=study)
        emails = ['*****@*****.**']
        resp = self.client.post('/api/v1/study/{0}/add_doctor/'.format(
            study.pk), {
                'doctor_pk': doctor.pk,
                'emails': emails
            },
                                format='json')
        self.assertSuccessResponse(resp)
        self.assertSetEqual(set(resp.data['fail_emails']), {'*****@*****.**'})
Ejemplo n.º 6
0
 def test_add_doctor_bad_doctor_pk(self):
     study = StudyFactory.create(author=self.coordinator)
     doctor = DoctorFactory.create(my_coordinator=self.coordinator)
     patient = DoctorFactory.create()
     ParticipantFactory.create(doctor_ptr=patient)
     old_doc_count = study.doctors.count()
     self.authenticate_as_doctor()
     emails = [
         doctor.email, self.doctor.email, patient.email, '*****@*****.**'
     ]
     resp = self.client.post('/api/v1/study/{0}/add_doctor/'.format(
         study.pk), {
             'doctor_pk': 999999,
             'emails': emails
         },
                             format='json')
     self.assertNotFound(resp)
     study.refresh_from_db()
     self.assertEqual(old_doc_count, study.doctors.count())
Ejemplo n.º 7
0
 def test_add_doctor(self):
     study = StudyFactory.create(author=self.coordinator)
     doctor = DoctorFactory.create(my_coordinator=self.coordinator)
     patient = DoctorFactory.create()
     ParticipantFactory.create(doctor_ptr=patient)
     self.authenticate_as_doctor()
     emails = [
         doctor.email, self.doctor.email, patient.email, '*****@*****.**'
     ]
     resp = self.client.post('/api/v1/study/{0}/add_doctor/'.format(
         study.pk), {
             'doctor_pk': doctor.pk,
             'emails': emails
         },
                             format='json')
     self.assertSuccessResponse(resp)
     invitations = StudyInvitation.objects.all()
     self.assertEqual(len(invitations), 2)
     self.assertSetEqual(set(invitations.values_list('email', flat=True)),
                         {'*****@*****.**', patient.email})
     self.assertSetEqual(set(resp.data['fail_emails']),
                         {doctor.email, self.doctor.email})
Ejemplo n.º 8
0
    def test_update_consent_docs(self,
                                 mock_participant_notification,
                                 mock_doc_notification):
        self.assertTrue(self.study_to_patient.patient_consent.is_valid())

        # Make out doctor participant (self.doctor in doctors and in patients)
        ParticipantFactory.create(doctor_ptr=self.doctor)

        yesterday_date = timezone.now() - timedelta(days=1)
        with patch('django.utils.timezone.now') as mock_now:
            mock_now.return_value = yesterday_date

            with self.fake_media():
                new_doc = ConsentDocFactory.create(
                    file=self.get_sample_image_file())

            self.study.consent_docs.add(new_doc)
            self.study.save()
            self.study_to_patient.patient_consent.refresh_from_db()
            self.assertFalse(self.study_to_patient.patient_consent.is_valid())

        self.assertTrue(mock_doc_notification.called)
        self.assertTrue(mock_participant_notification.called)