def test_get_department_from_organisation(self):
        drupal_config = get_mock_drupal_config()
        client = DrupalClient()

        parent_org_id = client.get_department_from_organisation('2')
        assert_equal(parent_org_id, '7')
        parent_org_id = client.get_department_from_organisation(2)
        assert_equal(parent_org_id, '7')

        assert_raises(DrupalKeyError, client.get_department_from_organisation, '999')
        assert_raises(DrupalKeyError, client.get_department_from_organisation, '')
        assert_raises(DrupalKeyError, client.get_department_from_organisation, None)
    def test_get_department_from_organisation(self):
        drupal_config = get_mock_drupal_config()
        client = DrupalClient()

        parent_org_id = client.get_department_from_organisation('2')
        assert_equal(parent_org_id, '7')
        parent_org_id = client.get_department_from_organisation(2)
        assert_equal(parent_org_id, '7')

        assert_raises(DrupalKeyError, client.get_department_from_organisation,
                      '999')
        assert_raises(DrupalKeyError, client.get_department_from_organisation,
                      '')
        assert_raises(DrupalKeyError, client.get_department_from_organisation,
                      None)
Example #3
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'
Example #4
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'