Skip to content

Commit

Permalink
make the tests to actually test what they're supposed to, and make su…
Browse files Browse the repository at this point in the history
…re we work when a patient and/or episode isn't passed in
  • Loading branch information
fredkingham committed Jun 5, 2017
1 parent e53b009 commit 5da8f6b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
5 changes: 4 additions & 1 deletion pathway/api.py
Expand Up @@ -51,13 +51,16 @@ def create(self, request, **kwargs):
def retrieve(self, *args, **kwargs):
# gets the pathways
pathway_cls = Pathway.get(self.name)
episode = None
patient = None

if self.episode_id:
episode = Episode.objects.get(id=self.episode_id)

if self.patient_id:
patient = Patient.objects.get(id=self.patient_id)
pathway = pathway_cls()
is_modal = self.request.GET.get("is_modal", False)
is_modal = self.request.GET.get("is_modal", False) == "True"
serialised = json_response(
pathway.to_dict(
is_modal,
Expand Down
59 changes: 55 additions & 4 deletions pathway/tests/test_api.py
Expand Up @@ -67,15 +67,56 @@ class PathwayGetTestCase(OpalTestCase):
def setUp(self):
self.patient, self.episode = self.new_patient_and_episode_please()
self.fake_pathway_instance = MagicMock()
pp = test_pathways.PagePathwayExample()
self.fake_pathway_instance.to_dict.return_value = pp.to_dict(False)
self.fake_pathway = MagicMock(return_value=self.fake_pathway_instance)

def get_json(self, url):
return self.client.get(
url, content_type='application/json'
)

def test_retrieve_episode_no_patient(self, fake_pathway_get):
fake_pathway_get.return_value = self.fake_pathway
url = reverse("pathway", kwargs=dict(
name="dog_owner",
patient_id=self.patient.id,
))
self.assertTrue(
self.client.login(
username=self.user.username, password=self.PASSWORD
)
)
response = self.get_json(url)
self.assertEqual(response.status_code, 200)
self.fake_pathway_instance.to_dict.assert_called_once_with(
False,
user=self.user,
patient=self.patient,
episode=None
)

def test_retrieve_no_patient_or_episode(self, fake_pathway_get):
fake_pathway_get.return_value = self.fake_pathway
url = reverse("pathway", kwargs=dict(
name="dog_owner",
))
self.assertTrue(
self.client.login(
username=self.user.username, password=self.PASSWORD
)
)
response = self.get_json(url)
self.assertEqual(response.status_code, 200)
self.fake_pathway_instance.to_dict.assert_called_once_with(
False,
user=self.user,
patient=None,
episode=None
)

def test_retrieve_non_modal(self, fake_pathway_get):
fake_pathway_get.return_value = test_pathways.PagePathwayExample
fake_pathway_get.return_value = self.fake_pathway
url = reverse("pathway", kwargs=dict(
name="dog_owner",
patient_id=self.patient.id,
Expand All @@ -88,10 +129,15 @@ def test_retrieve_non_modal(self, fake_pathway_get):
)
response = self.get_json(url)
self.assertEqual(response.status_code, 200)
self.fake_pathway_instance.to_dict.called_once_with()
self.fake_pathway_instance.to_dict.assert_called_once_with(
False,
user=self.user,
patient=self.patient,
episode=self.episode
)

def test_retrieve_modal(self, fake_pathway_get):
fake_pathway_get.return_value = test_pathways.PagePathwayExample
fake_pathway_get.return_value = self.fake_pathway
url = reverse("pathway", kwargs=dict(
name="dog_owner",
patient_id=self.patient.id,
Expand All @@ -106,4 +152,9 @@ def test_retrieve_modal(self, fake_pathway_get):
)
response = self.get_json(url)
self.assertEqual(response.status_code, 200)
self.fake_pathway_instance.to_dict.called_once_with(True)
self.fake_pathway_instance.to_dict.assert_called_once_with(
True,
user=self.user,
episode=self.episode,
patient=self.patient
)

0 comments on commit 5da8f6b

Please sign in to comment.