From f0eb8e2ac40e2f869a61b200feccd5636c64e7ad Mon Sep 17 00:00:00 2001 From: Pedro Nascimento Date: Thu, 11 Jan 2024 13:49:37 -0300 Subject: [PATCH] test: simple pylint adjustments --- api/app/routers/entities.py | 59 +++++++++++++++++++------------------ api/tests/conftest.py | 10 +++++-- 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/api/app/routers/entities.py b/api/app/routers/entities.py index 98556edf..64516f1a 100644 --- a/api/app/routers/entities.py +++ b/api/app/routers/entities.py @@ -7,7 +7,8 @@ from app.dependencies import get_current_active_user from app.pydantic_models import PatientModel, PatientConditionListModel, CompletePatientModel from app.models import ( - User, DataSource, Patient, City, Race, Gender, Nationality, Address, Telecom, PatientCondition, ConditionCode + User, Patient, City, Race, Gender, Nationality, Address, + Telecom, PatientCondition, ConditionCode ) PatientOutput = pydantic_model_creator(Patient, name="PatientOutput") @@ -22,35 +23,35 @@ async def create_or_update_patient( _: Annotated[User, Depends(get_current_active_user)], patient: PatientModel, ) -> PatientOutput: - input = patient.dict() + patient_data = patient.dict() birth_city = await City.get_or_none( - code = input['birth_city'], - state__code = input['birth_state'], - state__country__code = input['birth_country'] + code = patient_data['birth_city'], + state__code = patient_data['birth_state'], + state__country__code = patient_data['birth_country'] ) new_data = { - 'patient_cpf' : input.get('patient_cpf'), - 'birth_date' : input.get('birth_date'), - 'active' : input.get('active'), - 'protected_person' : input.get('protected_person'), - 'deceased' : input.get('deceased'), - 'deceased_date' : input.get('deceased_date'), - 'name' : input.get('name'), - 'mother_name' : input.get('mother'), - 'father_name' : input.get('father'), - 'naturalization' : input.get('naturalization'), + 'patient_cpf' : patient_data.get('patient_cpf'), + 'birth_date' : patient_data.get('birth_date'), + 'active' : patient_data.get('active'), + 'protected_person' : patient_data.get('protected_person'), + 'deceased' : patient_data.get('deceased'), + 'deceased_date' : patient_data.get('deceased_date'), + 'name' : patient_data.get('name'), + 'mother_name' : patient_data.get('mother'), + 'father_name' : patient_data.get('father'), + 'naturalization' : patient_data.get('naturalization'), 'birth_city' : birth_city, - 'race' : await Race.get_or_none(slug = input['race']), - 'gender' : await Gender.get_or_none(slug = input['gender']), - 'nationality' : await Nationality.get_or_none(slug = input['nationality']), + 'race' : await Race.get_or_none(slug = patient_data['race']), + 'gender' : await Gender.get_or_none(slug = patient_data['gender']), + 'nationality' : await Nationality.get_or_none(slug = patient_data['nationality']), } patient = await Patient.get_or_none( - patient_cpf = input.get('patient_cpf') + patient_cpf = patient_data.get('patient_cpf') ).prefetch_related('address_patient_periods','telecom_patient_periods') - if patient != None: + if patient is not None: await patient.update_from_dict(new_data).save() else: patient = await Patient.create(**new_data) @@ -58,7 +59,7 @@ async def create_or_update_patient( # Reset de Address for instance in patient.address_patient_periods.related_objects: await instance.delete() - for address in input.get("address_list"): + for address in patient_data.get("address_list"): address_city = await City.get_or_none( code = address['city'], state__code = address['state'], @@ -71,7 +72,7 @@ async def create_or_update_patient( # Reset de Telecom for instance in patient.telecom_patient_periods.related_objects: await instance.delete() - for telecom in input.get("telecom_list"): + for telecom in patient_data.get("telecom_list"): telecom['patient'] = patient await Telecom.create(**telecom) @@ -83,13 +84,13 @@ async def create_or_update_patientcondition( _: Annotated[User, Depends(get_current_active_user)], patientcondition: PatientConditionListModel, ) -> list[PatientConditionOutput]: - input = patientcondition.dict() + patient_data = patientcondition.dict() patient = await Patient.get_or_none( - patient_cpf=input.get('patient_cpf') + patient_cpf=patient_data.get('patient_cpf') ).prefetch_related('patientconditions') - if patient == None: + if patient is None: raise HTTPException(status_code=400, detail="Patient don't exist") # Reset Patient Conditions @@ -97,11 +98,11 @@ async def create_or_update_patientcondition( await instance.delete() conditions = [] - for condition in input.get('conditions'): + for condition in patient_data.get('conditions'): condition_code = await ConditionCode.get_or_none( value=condition.get('code') ) - if condition_code == None: + if condition_code is None: raise HTTPException( status_code=400, detail=f"Condition Code {condition.get('code')} don't exist" @@ -116,7 +117,7 @@ async def create_or_update_patientcondition( @router.get("/patient/{patient_cpf}", response_model=CompletePatientModel) async def get_patient( patient_cpf : int, - current_user: Annotated[User, Depends(get_current_active_user)], + _: Annotated[User, Depends(get_current_active_user)], ) -> list[CompletePatientModel]: patient = await Patient.get_or_none(patient_cpf=patient_cpf).prefetch_related( @@ -163,4 +164,4 @@ async def get_patient( patient_data['condition_list'] = condition_list patient_data['cns_list'] = cns_list - return patient_data \ No newline at end of file + return patient_data diff --git a/api/tests/conftest.py b/api/tests/conftest.py index 1dc6bd42..dc38f758 100644 --- a/api/tests/conftest.py +++ b/api/tests/conftest.py @@ -30,8 +30,8 @@ def event_loop(): @pytest.fixture(scope="session") async def client(): - async with AsyncClient(app=app, base_url="http://test") as client: - yield client + async with AsyncClient(app=app, base_url="http://test") as client_object: + yield client_object @pytest.fixture(scope="session", autouse=True) @@ -54,7 +54,11 @@ async def initialize_tests(patient_cpf: str): await Address.all().delete() await Telecom.all().delete() - datasource = await DataSource.create(description="test_datasource", system="vitacare", cnes="1234567") + datasource = await DataSource.create( + description="test_datasource", + system="vitacare", + cnes="1234567" + ) country = await Country.create(name="Brasil", code="00001") state = await State.create(name="Rio de Janeiro", country=country, code="00001") city = await City.create(name="Rio de Janeiro", state=state, code="00001")