def test_get_organisation(self): drupal_config = get_mock_drupal_config() client = DrupalClient() org_name = client.get_organisation_name('2') assert_equal(org_name, 'Ealing PCT') org_name = client.get_organisation_name(2) assert_equal(org_name, 'Ealing PCT') assert_raises(DrupalKeyError, client.get_organisation_name, '999') assert_raises(DrupalKeyError, client.get_organisation_name, '') assert_raises(DrupalKeyError, client.get_organisation_name, None)
def generate(cls, xmlrpc_settings): drupal = DrupalClient(xmlrpc_settings) orgs = {} has_errors = False orgs_to_lookup = set() orgs_to_lookup.add('Northern Ireland Executive') for org_name in orgs_to_lookup: org_name = canonise_organisation_name(org_name) org_id = drupal.match_organisation(org_name) if org_id == False: log.error('Could not find organisation %r', org_name) has_errors = True continue proper_org_name = drupal.get_organisation_name(org_id) parent_department_id = drupal.get_department_from_organisation(org_id) orgs[org_id] = {'name': proper_org_name, 'parent_department_id': parent_department_id} f = open(cls.lots_of_orgs_filepath, 'w') try: f.write(json.dumps(orgs)) finally: f.close() if has_errors: print 'Finished with ERRORS' sys.exit(1) else: print 'Finished with SUCCESS'
def department_or_agency_to_organisation(cls, dept_or_agency, include_id=True, organisation_cache=None, drupal_client_cache=None, ): '''Returns None if not found.''' if organisation_cache is None: organisation_cache = {} if not drupal_client_cache: drupal_client_cache = DrupalClient() if dept_or_agency not in organisation_cache: try: organisation_id = drupal_client_cache.match_organisation(dept_or_agency) except DrupalKeyError: name = canonise_organisation_name(dept_or_agency) try: organisation_id = drupal_client_cache.match_organisation(name) except DrupalKeyError: organisation_id = None if organisation_id: organisation_name = drupal_client_cache.get_organisation_name(organisation_id) organisation_cache[dept_or_agency] = (organisation_name, organisation_id) else: organisation_cache[dept_or_agency] = None if not organisation_cache[dept_or_agency]: return None if include_id: return '%s [%s]' % organisation_cache[dept_or_agency] else: return '%s' % organisation_cache[dept_or_agency][0]
def generate(cls, xmlrpc_settings): drupal = DrupalClient(xmlrpc_settings) orgs = {} has_errors = False orgs_to_lookup = set() orgs_to_lookup.add('Northern Ireland Executive') for org_name in orgs_to_lookup: org_name = canonise_organisation_name(org_name) org_id = drupal.match_organisation(org_name) if org_id == False: log.error('Could not find organisation %r', org_name) has_errors = True continue proper_org_name = drupal.get_organisation_name(org_id) parent_department_id = drupal.get_department_from_organisation( org_id) orgs[org_id] = { 'name': proper_org_name, 'parent_department_id': parent_department_id } f = open(cls.lots_of_orgs_filepath, 'w') try: f.write(json.dumps(orgs)) finally: f.close() if has_errors: print 'Finished with ERRORS' sys.exit(1) else: print 'Finished with SUCCESS'