Skip to content

Commit

Permalink
implemented cpf mismatch in std test
Browse files Browse the repository at this point in the history
  • Loading branch information
TanookiVerde committed Jan 19, 2024
1 parent e0118bc commit 7efae19
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 8 deletions.
51 changes: 45 additions & 6 deletions api/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def client():


@pytest.fixture(scope="session", autouse=True)
async def initialize_tests(patient_cpf: str):
async def initialize_tests(patient_cpf: str, other_patient_cpf:str):
await Tortoise.init(config=TORTOISE_ORM)
await Tortoise.generate_schemas()

Expand Down Expand Up @@ -124,6 +124,16 @@ async def initialize_tests(patient_cpf: str):
category="encounter-diagnosis",
date="2021-01-01"
)
await RawPatientRecord.create(
patient_cpf=other_patient_cpf,
data={"name": "Maria"},
data_source=datasource
)
await RawPatientCondition.create(
patient_cpf=other_patient_cpf,
data={"cid": "A001"},
data_source=datasource
)
yield
await Tortoise.close_connections()

Expand All @@ -146,6 +156,10 @@ async def password():
async def patient_cpf():
yield "38965996074"

@pytest.fixture(scope="session")
async def other_patient_cpf():
yield "74663240020"

@pytest.fixture(scope="session")
async def patient_invalid_cpf():
yield "11111111111"
Expand All @@ -160,19 +174,44 @@ async def token(client: AsyncClient, username: str, password: str):
yield response.json().get("access_token")

@pytest.fixture(scope="session")
async def patientrecord_raw_source():
async def patientrecord_raw_source(patient_cpf:str):
await Tortoise.init(config=TORTOISE_ORM)
await Tortoise.generate_schemas()

raw_patientrecord = await RawPatientRecord.first()
raw_patientrecord = await RawPatientRecord.get(
patient_cpf = patient_cpf
).first()

yield str(raw_patientrecord.id)

@pytest.fixture(scope="session")
async def patientcondition_raw_source():
async def patientcondition_raw_source(patient_cpf:str):
await Tortoise.init(config=TORTOISE_ORM)
await Tortoise.generate_schemas()

raw_patientcondition = await RawPatientCondition.first()

raw_patientcondition = await RawPatientCondition.get(
patient_cpf = patient_cpf
).first()
yield str(raw_patientcondition.id)

@pytest.fixture(scope="session")
async def other_patientrecord_raw_source(other_patient_cpf:str):
await Tortoise.init(config=TORTOISE_ORM)
await Tortoise.generate_schemas()

raw_patientrecord = await RawPatientRecord.get(
patient_cpf = other_patient_cpf
).first()

yield str(raw_patientrecord.id)

@pytest.fixture(scope="session")
async def other_patientcondition_raw_source(other_patient_cpf:str):
await Tortoise.init(config=TORTOISE_ORM)
await Tortoise.generate_schemas()

raw_patientcondition = await RawPatientCondition.get(
patient_cpf = other_patient_cpf
).first()

yield str(raw_patientcondition.id)
62 changes: 60 additions & 2 deletions api/tests/test_std.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,41 @@ async def test_create_stdpatientrecords_invalid_raw_source(

assert response.status_code == 404

@pytest.mark.anyio
@pytest.mark.run(order=10)
async def test_create_stdpatientrecords_cpf_mismatch(
client : AsyncClient,
token : str,
patient_cpf : str,
other_patientrecord_raw_source : str
):

response = await client.post(
"/std/patientrecords",
headers={"Authorization": f"Bearer {token}"},
json=[
{
"active": True,
"birth_city_cod": "00001",
"birth_state_cod": "00001",
"birth_country_cod": "00001",
"birth_date": "2000-01-11",
"patient_cpf": patient_cpf,
"gender": "male",
"mother_name": "Gabriela Marques da Cunha",
"name": "Fernando Marques Farias",
"nationality": "B",
"race": "parda",
"cns_list": [],
"address_list": [],
"telecom_list": [],
"raw_source_id": other_patientrecord_raw_source
}
]
)

assert response.status_code == 400


@pytest.mark.anyio
@pytest.mark.run(order=10)
Expand Down Expand Up @@ -186,7 +221,7 @@ async def test_create_stdpatientrecords_invalid_cpf(

@pytest.mark.anyio
@pytest.mark.run(order=11)
async def test_get_stdpatientrecords(
async def test_read_stdpatientrecords(
client : AsyncClient,
token : str,
patient_cpf : str
Expand Down Expand Up @@ -283,6 +318,29 @@ async def test_create_stdpatientcondition_invalid_raw_source(

assert response.status_code == 404

@pytest.mark.anyio
@pytest.mark.run(order=10)
async def test_create_stdpatientcondition_cpfmismatch(
client : AsyncClient,
token : str,
patient_cpf : str,
other_patientcondition_raw_source : str
):
response = await client.post(
"/std/patientconditions",
headers={"Authorization": f"Bearer {token}"},
json = [
{
"patient_cpf": patient_cpf,
"cid": "A001",
"date": "2024-01-11T16:20:09.832Z",
"raw_source_id": other_patientcondition_raw_source
}
]
)

assert response.status_code == 400


@pytest.mark.anyio
@pytest.mark.run(order=10)
Expand All @@ -309,7 +367,7 @@ async def test_create_stdpatientcondition_invalid_conditioncode(

@pytest.mark.anyio
@pytest.mark.run(order=11)
async def test_get_stdpatientconditions(
async def test_read_stdpatientconditions(
client : AsyncClient,
token : str,
patient_cpf : str
Expand Down

0 comments on commit 7efae19

Please sign in to comment.