def test_show_symptoms(self):
        patients = []
        for index in range(1, 6):
            patient = Patient(id=index, age_range=index)
            patient.save()

            if patient.age_range == 1:
                ClinicalState_28d(patient_id=index, dispneia=True).save()

            elif patient.age_range == 2:
                ClinicalState_29d_2m(patient_id=index, dispneia=True).save()

            elif patient.age_range == 3:
                ClinicalState_2m_3y(patient_id=index, dispneia=True).save()

            elif patient.age_range == 4:
                ClinicalState_3y_10y(patient_id=index, dispneia=True).save()

            elif patient.age_range == 5:
                ClinicalState_10yMore(patient_id=index, dispneia=True).save()

            patients.append(patient)

        show_symptoms(patients)
        assert patients[0].diseases == 'dispneia'
        assert patients[1].diseases == 'dispneia'
        assert patients[2].diseases == 'dispneia'
        assert patients[3].diseases == 'dispneia'
        assert patients[4].diseases == 'dispneia'
    def generate_all_age_patients(self):
        """
            generating one test patient for each age range
        """

        for x in range(1, 6):
            patient = Patient(id=x, age_range=x)
            patient.save()
    def create_history_content(self):
        for index in range(1, 6):
            patient_test = Patient(id=index,
                                   age_range=index,
                                   classification='1')
            patient_test.save()

        staff = Staff(name='Atendente', id_user='******')
        staff.save()
    def test_home_patient_list(self, client):
        self.create_user_and_login(client)

        patient_test = Patient(id='156498', birth_date='2016-11-03')
        patient_test.save()

        response = client.get('/home/')
        assert response.status_code == 200
        assert set(list(response.context['patients'])) == \
            set(list(Patient.objects.all()))
    def test_edit_patient_form(self, client):
        """
        Test edit patient form with a valid cpf
        """
        self.create_user_and_login(client)

        name = Patient(id='001002012', birth_date='2017-02-01')
        name.save()
        response = client.get('/patients/edit/001002012/')
        assert 'form' in response.context
        assert 'patient' in response.context
        assert response.context['form'] is not None
        assert isinstance(response.context['form'], EditPatientForm)
    def test_edit_patient_is_valid(self, client):
        self.create_user_and_login(client)

        patient_test = Patient(id='1', birth_date='2017-10-10', age_range='0')
        patient_test.save()

        client.post('/patients/edit/1/', {
            'name': 'New Name',
            'age_range': '1'
        })
        edited_patient = Patient.objects.get(id=1)

        assert edited_patient.name == 'New Name'
        assert edited_patient.age_range == 1
    def create_clinical_states(self):
        Patient(id='1', classification=1, birth_date='2016-11-03').save()
        Patient(id='2', classification=2, birth_date='2016-11-03').save()
        Patient(id='3', classification=3, birth_date='2016-11-03').save()
        Patient(id='4', classification=4, birth_date='2016-11-03').save()

        clinical_28 = ClinicalState_28d(patient_id='1', classifier_id=1234)
        clinical_29 = ClinicalState_29d_2m(patient_id='2', classifier_id=1234)
        clinical_2m = ClinicalState_2m_3y(patient_id='3', classifier_id=1234)
        clinical_3y = ClinicalState_3y_10y(patient_id='4', classifier_id=1234)
        clinical_10y = ClinicalState_10yMore(patient_id='4',
                                             classifier_id=1234)

        clinical_28.save()
        clinical_29.save()
        clinical_2m.save()
        clinical_3y.save()
        clinical_10y.save()
    def test_edit_patient_is_update_data(self, client):
        """
        Test if edit patient post method is actually updating
        """
        self.create_user_and_login(client)

        Patient(id='1', birth_date='2017-02-01', name='Victor').save()
        client.post('/patients/edit/1/', self.patient_data)
        assert Patient.objects.filter(id='1')[0].name == 'Victor'
    def test_registered_patient_view(self, client):
        self.create_user_and_login(client)

        patient1 = Patient(birth_date='2015-11-08')
        patient2 = Patient(birth_date='2014-10-08')
        patient1.save()
        patient2.save()
        all_patients = [patient1, patient2]
        response = client.get('/home/')
        assert response.status_code == 200
        assert list(response.context['patients']) == all_patients
    def test_edit_patient_post_valid_data(self, client):
        """
        Test edit patient post method with valid data
        """
        Staff.objects.create_superuser(**self.default_user_data())
        client.post('/', {
            'username': '******',
            'password': "******"
        })

        Patient(id='156498', birth_date='2017-02-01').save()

        response = client.post('/patients/edit/156498/', self.patient_data)
        assert response.status_code == 302
        assert Patient.objects.count() == 1
    def test_edit_patient_post_invalid_data(self, client):
        """
        Test edit patient post method with invalid data
        """
        self.create_user_and_login(client)

        invalid_patient_data = ({
            'name': 'nameTest',
            'guardian': 'guardianTeste',
            'birth_date': '2010-08-06',
            'cpf': 'cpferror'
        })

        Patient(id='156498', birth_date='2008-09-05', age_range='0').save()
        response = client.post('/patients/edit/156498/', invalid_patient_data)
        assert response.status_code == 400
 def test_gender_verbose(self):
     patient = Patient(age_range=1, gender=1)
     assert patient.gender_verbose() == 'Feminino'
 def test_age_range_verbose(self, age_range, expected_text):
     patient = Patient(age_range=int(age_range))
     assert patient.age_range_verbose() == expected_text