def test_required_properties(self): # request with required properties gets passed through fine PatientDetailsUpdater(self.domain, self._get_fake_request()) # Without the required property, raises an error with self.assertRaises(NinetyNineDotsException) as e: PatientDetailsUpdater(None, {'boop': 'barp'}) self.assertTrue(", ".join(self.spec.required_params) in str(e.exception))
def test_wrong_direction(self): fake_request = self._get_fake_request() fake_request['outbound_only'] = 'foo' with self.assertRaises(NinetyNineDotsException) as e: PatientDetailsUpdater(self.domain, fake_request).update_cases() self.assertEqual(str(e.exception), "outbound_only is not a valid parameter to update") fake_request = self._get_fake_request() fake_request['inbound_only'] = 'bar' # shouldn't throw an exception PatientDetailsUpdater(self.domain, fake_request).update_cases()
def test_invalid_choice(self): fake_request = self._get_fake_request() # A request with a valid choice passes through fine fake_request['has_choices'] = 'foo' PatientDetailsUpdater(None, fake_request) # A request with an invalid choice raises an error fake_request = self._get_fake_request() fake_request['has_choices'] = 'biff' with self.assertRaises(NinetyNineDotsException) as e: PatientDetailsUpdater(None, fake_request) self.assertEqual(str(e.exception), "biff is not a valid value for has_choices.")
def test_update_with_setter(self): fake_request = self._get_fake_request() fake_request['with_setter'] = 'foo' PatientDetailsUpdater(self.domain, fake_request).update_cases() person_case = CaseAccessors(self.domain).get_case(self.person_id) self.assertEqual(person_case.get_case_property('property_set_with_setter'), 'foo')
def test_unwrap_number(self): fake_request = self._get_fake_request() fake_request['unwrap_number'] = '+91123456789' PatientDetailsUpdater(self.domain, fake_request).update_cases() person_case = CaseAccessors(self.domain).get_case(self.person_id) self.assertEqual(person_case.get_case_property('foo'), '91123456789')
def test_split_name(self): fake_request = self._get_fake_request() fake_request['split_name'] = 'Arya Horseface Stark' PatientDetailsUpdater(self.domain, fake_request).update_cases() person_case = CaseAccessors(self.domain).get_case(self.person_id) self.assertEqual(person_case.get_case_property('foo'), 'Arya') self.assertEqual(person_case.get_case_property('bar'), 'Horseface Stark')
def test_case_update(self): fake_request = self._get_fake_request() fake_request['has_choices'] = 'foo' PatientDetailsUpdater(self.domain, fake_request).update_cases() person_case = CaseAccessors(self.domain).get_case(self.person_id) self.assertEqual(person_case.get_case_property('required_param'), '123') episode_case = CaseAccessors(self.domain).get_case(self.episode_id) self.assertEqual(episode_case.get_case_property('has_choices'), 'foo')
def update_patient_details(request, domain): try: request_json = json.loads(request.body) except ValueError: return json_response({"error": "Malformed JSON"}, status_code=400) try: PatientDetailsUpdater(domain, request_json).update_cases() except NinetyNineDotsException as e: return json_response({"error": six.text_type(e)}, status_code=400) return json_response({"success": "Patient details updated."})
def test_merm_params(self): fake_request = self._get_fake_request() fake_request['merm_params'] = { "IMEI": "1321", "daily_reminder_status": "1", "daily_reminder_time": "12:00", "refill_reminder_status": "1", "refill_reminder_datetime": "2017/12/12 15:54:00", "RT_hours": "1", } PatientDetailsUpdater(self.domain, fake_request).update_cases() person_case = CaseAccessors(self.domain).get_case(self.episode_id) self.assertEqual(person_case.get_case_property('merm_id'), '1321')
def test_patient_not_found(self): fake_request = self._get_fake_request() fake_request['beneficiary_id'] = '123' with self.assertRaises(NinetyNineDotsException) as e: PatientDetailsUpdater(None, fake_request) self.assertTrue(str(e.exception), "No patient exists with this beneficiary ID")
def test_private_only(self): fake_request = self._get_fake_request() fake_request['private_only'] = 'so private' with self.assertRaises(NinetyNineDotsException): PatientDetailsUpdater(self.domain, fake_request).update_cases()