Skip to content

Commit

Permalink
Rename models to avoid naming conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
samamorgan committed Nov 3, 2023
1 parent 985bc41 commit d8ef8b6
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 34 deletions.
58 changes: 35 additions & 23 deletions test/test_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@

from welkin import Client
from welkin.exceptions import WelkinHTTPError
from welkin.models import Patient, Program, ProgramPhase, ProgramPhases, Programs
from welkin.models.formation import Program as FormationProgram
from welkin.models import (
Patient,
PatientProgram,
PatientPrograms,
ProgramPhase,
ProgramPhases,
)
from welkin.models.formation import Program


@pytest.mark.vcr
class TestProgram:
@pytest.fixture
def formation(self, client: Client) -> FormationProgram:
def formation(self, client: Client) -> Program:
return client.Formation().Programs().get()[0]

@pytest.fixture
Expand All @@ -23,14 +29,14 @@ def second_phase(self, formation) -> str:
return formation.phases[1]["name"]

@pytest.fixture
def program(
def patient_program(
self,
patient: Patient,
formation: FormationProgram,
formation: Program,
first_phase: str,
fixture_cassette,
) -> Program:
program = patient.Program(programName=formation.name)
) -> PatientProgram:
program = patient.PatientProgram(programName=formation.name)

with fixture_cassette():
try:
Expand All @@ -54,32 +60,38 @@ def program(
"programName",
],
)
def test_read(self, patient: Patient, program: Program, identifier: str):
prog = patient.Program(**{identifier: getattr(program, identifier)}).get()

assert isinstance(prog, Program)
def test_read(
self, patient: Patient, patient_program: PatientProgram, identifier: str
):
prog = patient.PatientProgram(
**{identifier: getattr(patient_program, identifier)}
).get()

assert isinstance(prog, PatientProgram)
assert isinstance(prog.currentPhase, ProgramPhase)
assert isinstance(prog.pathHistory, ProgramPhases)

assert prog.id == program.id
assert prog.id == patient_program.id

def test_read_no_id(self, client):
with pytest.raises(ValueError):
client.Patient(id="notarealid").Program().get()
client.Patient(id="notarealid").PatientProgram().get()

def test_update(self, patient: Patient, program: Program, second_phase: str):
assert program.currentPhase.name != second_phase
assert len(program.pathHistory) == 1
def test_update(
self, patient: Patient, patient_program: PatientProgram, second_phase: str
):
assert patient_program.currentPhase.name != second_phase
assert len(patient_program.pathHistory) == 1

prog = patient.Program(programName=program.programName).update(
prog = patient.PatientProgram(programName=patient_program.programName).update(
phaseName=second_phase
)
assert prog.currentPhase.name == second_phase
assert prog.currentPhase.name != program.currentPhase.name
assert prog.currentPhase.name != patient_program.currentPhase.name
assert len(prog.pathHistory) == 2

def test_delete(self, patient: Patient, program: Program):
prog = patient.Program(id=program.id)
def test_delete(self, patient: Patient, patient_program: PatientProgram):
prog = patient.PatientProgram(id=patient_program.id)
prog.delete()

with pytest.raises(WelkinHTTPError) as excinfo:
Expand All @@ -91,7 +103,7 @@ def test_delete(self, patient: Patient, program: Program):
@pytest.mark.vcr
class TestPrograms:
def test_read(self, patient):
programs = patient.Programs().get()
programs = patient.PatientPrograms().get()

assert isinstance(programs, Programs)
assert isinstance(programs[0], Program)
assert isinstance(programs, PatientPrograms)
assert isinstance(programs[0], PatientProgram)
4 changes: 2 additions & 2 deletions welkin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ class Client(Session):
Formation = models.Formation
Patient = models.Patient
Patients = models.Patients
Program = models.Program
PatientProgram = models.PatientProgram
ProgramPhase = models.ProgramPhase
ProgramPhases = models.ProgramPhases
Programs = models.Programs
PatientPrograms = models.PatientPrograms
Schedules = models.Schedules
SearchChats = models.SearchChats
SMS = models.SMS
Expand Down
11 changes: 8 additions & 3 deletions welkin/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
from welkin.models.encounter import Encounter, EncounterDisposition, Encounters
from welkin.models.formation import Formation
from welkin.models.patient import Patient, Patients
from welkin.models.program import Program, ProgramPhase, ProgramPhases, Programs
from welkin.models.program import (
PatientProgram,
PatientPrograms,
ProgramPhase,
ProgramPhases,
)
from welkin.models.sms import SMS, SMSes
from welkin.models.user import User, Users

Expand Down Expand Up @@ -49,10 +54,10 @@
"Formation",
"Patient",
"Patients",
"Program",
"PatientProgram",
"ProgramPhase",
"ProgramPhases",
"Programs",
"PatientPrograms",
"Schedules",
"SearchChats",
"SMS",
Expand Down
6 changes: 3 additions & 3 deletions welkin/models/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
)
from welkin.models.email import Email, Emails
from welkin.models.encounter import Encounter, Encounters
from welkin.models.program import Program, Programs
from welkin.models.program import PatientProgram, PatientPrograms
from welkin.models.sms import SMS, SMSes
from welkin.pagination import PageableIterator

Expand All @@ -31,8 +31,8 @@ class Patient(Resource):
Emails,
Encounter,
Encounters,
Program,
Programs,
PatientProgram,
PatientPrograms,
SearchChats,
SMS,
SMSes,
Expand Down
6 changes: 3 additions & 3 deletions welkin/models/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ProgramPhases(Collection):
resource = ProgramPhase


class Program(Resource):
class PatientProgram(Resource):
subresources = [ProgramPhase]
nested_objects = {
"phases": "ProgramPhase",
Expand Down Expand Up @@ -64,8 +64,8 @@ def delete(self, patient_id: str = None):
)


class Programs(Collection):
resource = Program
class PatientPrograms(Collection):
resource = PatientProgram
iterator = MetaInfoIterator

def get(
Expand Down

0 comments on commit d8ef8b6

Please sign in to comment.