def test_import_encounter(self): """ Importing the given encounter should update the case's "height" property """ response = Mock() response.json.return_value = self.get_json('encounter') self.setUpRepeater() self.repeater.requests # Initialise cached value self.repeater.__dict__["requests"] = Mock() self.repeater.requests.get.return_value = response with patch('corehq.motech.openmrs.atom_feed.submit_case_blocks') as submit_case_blocks_patch, \ patch('corehq.motech.openmrs.atom_feed.importer_util') as importer_util_patch, \ patch('corehq.motech.openmrs.repeaters.get_one_commcare_user_at_location'): importer_util_patch.lookup_case.return_value = (self.case, None) import_encounter(self.repeater, 'c719b87f-d221-493b-bec7-c212aa813f5d') case_block_re = """ <case case_id="abcdef" » date_modified="[\\d\\-T\\:\\.Z]+" » xmlns="http://commcarehq.org/case/transaction/v2"> <update> <height>105</height> </update> </case>""" case_block_re = ''.join((l.strip() for l in case_block_re.split('\n'))).replace('»', '') ([case_block], domain), kwargs = submit_case_blocks_patch.call_args self.assertRegex(case_block, case_block_re) self.assertEqual(domain, 'test_domain') self.assertEqual(kwargs['device_id'], 'openmrs-atomfeed-123456') self.assertEqual(kwargs['xmlns'], 'http://commcarehq.org/openmrs-integration')
def test_import_encounter(self): """ Importing the given encounter should update the case's "height" property """ with patch('corehq.motech.openmrs.atom_feed.submit_case_blocks') as submit_case_blocks_patch, \ patch('corehq.motech.openmrs.atom_feed.importer_util') as importer_util_patch: importer_util_patch.lookup_case.return_value = (self.case, None) import_encounter(self.repeater, 'c719b87f-d221-493b-bec7-c212aa813f5d') case_block_re = """ <case case_id="abcdef" » date_modified="[\\d\\-T\\:\\.Z]+" » xmlns="http://commcarehq.org/case/transaction/v2"> <update> <height>105</height> </update> </case>""" case_block_re = ''.join( (l.strip() for l in case_block_re.split('\n'))).replace('»', '') ([case_block], domain), kwargs = submit_case_blocks_patch.call_args self.assertRegexpMatches(case_block.decode('utf-8'), case_block_re) self.assertEqual(domain, 'test_domain') self.assertEqual(kwargs['device_id'], 'openmrs-atomfeed-123456') self.assertEqual(kwargs['xmlns'], 'http://commcarehq.org/openmrs-integration')
def poll_openmrs_atom_feeds(domain_name): for repeater in OpenmrsRepeater.by_domain(domain_name): if repeater.atom_feed_enabled and not repeater.paused: patient_uuids = get_feed_updates(repeater, ATOM_FEED_NAME_PATIENT) encounter_uuids = get_feed_updates(repeater, ATOM_FEED_NAME_ENCOUNTER) for patient_uuid in patient_uuids: update_patient(repeater, patient_uuid) for encounter_uuid in encounter_uuids: import_encounter(repeater, encounter_uuid)
def poll_openmrs_atom_feeds(domain_name): for repeater in OpenmrsRepeater.by_domain(domain_name): if repeater.atom_feed_enabled and not repeater.paused: patient_uuids = get_feed_updates(repeater, ATOM_FEED_NAME_PATIENT) encounter_uuids = get_feed_updates(repeater, ATOM_FEED_NAME_ENCOUNTER) for patient_uuid in patient_uuids: update_patient(repeater, patient_uuid) for encounter_uuid in encounter_uuids: import_encounter(repeater, encounter_uuid)
def poll_openmrs_atom_feeds(domain_name): for repeater in OpenmrsRepeater.by_domain(domain_name): errors = [] if repeater.atom_feed_enabled and not repeater.paused: patient_uuids = get_feed_updates(repeater, ATOM_FEED_NAME_PATIENT) encounter_uuids = get_feed_updates(repeater, ATOM_FEED_NAME_ENCOUNTER) for patient_uuid in patient_uuids: try: update_patient(repeater, patient_uuid) except (ConfigurationError, OpenmrsException) as err: errors.append(str(err)) for encounter_uuid in encounter_uuids: try: import_encounter(repeater, encounter_uuid) except (ConfigurationError, OpenmrsException) as err: errors.append(str(err)) if errors: repeater.requests.notify_error( 'Errors importing from Atom feed:\n' + '\n'.join(errors)) if settings.UNIT_TESTING: assert False, errors
def test_import_encounter(self): """ Importing the given encounter should update the case's "height" property """ with patch('corehq.motech.openmrs.atom_feed.submit_case_blocks') as submit_case_blocks_patch, \ patch('corehq.motech.openmrs.atom_feed.importer_util') as importer_util_patch: importer_util_patch.lookup_case.return_value = (self.case, None) import_encounter(self.repeater, 'c719b87f-d221-493b-bec7-c212aa813f5d') case_block_re = """ <case case_id="abcdef" » date_modified="[\\d\\-T\\:\\.Z]+" » xmlns="http://commcarehq.org/case/transaction/v2"> <update> <height>105</height> </update> </case>""" case_block_re = ''.join((l.strip() for l in case_block_re.split('\n'))).replace('»', '') ([case_block], domain), kwargs = submit_case_blocks_patch.call_args self.assertRegexpMatches(case_block.decode('utf-8'), case_block_re) self.assertEqual(domain, 'test_domain') self.assertEqual(kwargs['device_id'], 'openmrs-atomfeed-123456') self.assertEqual(kwargs['xmlns'], 'http://commcarehq.org/openmrs-integration')