def test_create_patient(self):
        """
        ValueSource instances with direction set to DIRECTION_IMPORT
        should not be exported.
        """
        requests = mock.Mock()
        requests.post.side_effect = RequestException()
        info = mock.Mock(
            updates={'sex': 'M', 'dob': '1918-07-18'},
            extra_fields={},
        )
        case_config = copy.deepcopy(CASE_CONFIG)
        case_config['patient_identifiers'] = {}
        case_config['person_preferred_name'] = {}
        case_config['person_preferred_address'] = {}
        case_config['person_attributes'] = {}

        case_config['person_properties']['gender']['direction'] = DIRECTION_IMPORT
        case_config['person_properties']['birthdate']['direction'] = DIRECTION_EXPORT
        case_config = OpenmrsCaseConfig(case_config)

        with self.assertRaises(RequestException):
            create_patient(requests, info, case_config)
        requests.post.assert_called_with(
            '/ws/rest/v1/patient/',
            json={'person': {'birthdate': '1918-07-18'}},
            raise_for_status=True,
        )
Beispiel #2
0
    def test_create_patient(self):
        """
        ValueSource instances with direction set to DIRECTION_IMPORT
        should not be exported.
        """
        requests = mock.Mock()
        requests.post.return_value.status_code = 500
        info = mock.Mock(
            updates={'sex': 'M', 'dob': '1918-07-18'},
            extra_fields={},
        )
        case_config = copy.deepcopy(CASE_CONFIG)
        case_config['patient_identifiers'] = {}
        case_config['person_preferred_name'] = {}
        case_config['person_preferred_address'] = {}
        case_config['person_attributes'] = {}

        case_config['person_properties']['gender']['direction'] = DIRECTION_IMPORT
        case_config['person_properties']['birthdate']['direction'] = DIRECTION_EXPORT
        case_config = OpenmrsCaseConfig(case_config)

        create_patient(requests, info, case_config)
        requests.post.assert_called_with(
            '/ws/rest/v1/patient/',
            json={'person': {'birthdate': '1918-07-18'}}
        )