Ejemplo n.º 1
0
 def _create_datasets(self):
     """ create the required datasets to test """
     log.info('Creating datasets for testing collections')
     # create just one time
     if hasattr(self, 'org1'):
         return 
     reset_db  # TODO it's seems not working
     self.org1 = ckan_factories.Organization()
     log.info('Org1 created {}'.format(self.org1['id']))
     self.org2 = ckan_factories.Organization()
     log.info('Org2 created {}'.format(self.org2['id']))
     self.group1 = ckan_factories.Group()
     log.info('Group1 created {}'.format(self.group1['id']))
     self.group2 = ckan_factories.Group()
     log.info('Group2 created {}'.format(self.group2['id']))
     
     self.parent = ckan_factories.Dataset(owner_org=self.org1['id'],
                                          extras=[{'key': 'collection_metadata', 'value': 'true'}],
                                          title='The Father test_collections_unique',
                                          groups=[{'name': self.group1['name']}, {'name': self.group2['name']}])
     log.info('Parent created {}'.format(self.parent['id']))
     self.child1 = ckan_factories.Dataset(owner_org=self.org1['id'],
                                          extras=[{'key': 'collection_package_id', 'value': self.parent['id']}],
                                          title='The Child 2 test_collections_unique',
                                          groups=[{'name': self.group1['name']}])
     log.info('Child 1 created {}'.format(self.child1['id']))
     self.child2 = ckan_factories.Dataset(owner_org=self.org1['id'],
                                          extras=[{'key': 'collection_package_id', 'value': self.parent['id']}],
                                          title='The Child 2 test_collections_unique',
                                          groups=[{'name': self.group2['name']}])
     log.info('Child 2 created {}'.format(self.child2['id']))
Ejemplo n.º 2
0
    def _create_harvest_source_with_owner_org_and_job_if_not_existing(self):
        site_user = toolkit.get_action('get_site_user')({
            'model': model,
            'ignore_auth': True
        }, {})['name']

        context = {
            'user': site_user,
            'model': model,
            'session': model.Session,
            'ignore_auth': True,
        }

        test_org = ckan_factories.Organization(
            extras=[{
                'key': 'email_list',
                'value': '[email protected], [email protected]'
            }])
        test_other_org = ckan_factories.Organization()
        org_admin_user = ckan_factories.User()
        org_member_user = ckan_factories.User()

        toolkit.get_action('organization_member_create')(
            context.copy(), {
                'id': test_org['id'],
                'username': org_admin_user['name'],
                'role': 'admin'
            })

        toolkit.get_action('organization_member_create')(
            context.copy(), {
                'id': test_org['id'],
                'username': org_member_user['name'],
                'role': 'member'
            })

        source_dict = {
            'title': 'Test Source 01',
            'name': 'test-source-01',
            'url': 'basic_test',
            'source_type': 'ckan',
            'owner_org': test_org['id'],
            'run': True
        }

        harvest_source = toolkit.get_action('harvest_source_create')(
            context.copy(), source_dict)

        return context, harvest_source['id']
Ejemplo n.º 3
0
    def test_package_create_with_group_permission(self):
        user = factories.User(name='user2')
        owner_org = factories.Organization(users=[{
            'name': user['name'],
            'capacity': 'editor'
        }])
        group = factories.Group(name='economy',
                                users=[{
                                    'name': user['name'],
                                    'capacity': 'member'
                                }])

        context = {'user': user['name'], 'ignore_auth': False}
        params = {
            'name': 'test-dataset-2',
            'notes': 'This is a test',
            'tag_string': 'geography',
            'accessLevel': 'public',
            'contact_name': 'John Smith',
            'contact_email': '*****@*****.**',
            'rights': 'No restrictions on public use',
            'accrualPeriodicity': 'R/P1W',
            'owner_org': owner_org['id'],
            'group': 'economy'
        }
        dataset = helpers.call_action('package_create',
                                      context=context,
                                      **params)

        assert dataset['groups'][0]['name'] == 'economy'
Ejemplo n.º 4
0
    def test_organization_pages_index(self, app):
        user = factories.Sysadmin()
        env = {'REMOTE_USER': user['name'].encode('ascii')}
        org = factories.Organization()

        endpoint = 'pages.organization_pages_index' if ckan_29_or_higher else 'organization_pages_index'
        url = toolkit.url_for(endpoint, id=org['id'])
        response = app.get(url, status=200, extra_environ=env)
        assert '<h2>Pages</h2>' in response.body
        assert 'Add page</a>' in response.body
Ejemplo n.º 5
0
    def test_harvest_job_create_as_admin(self):
        # as if an admin user presses 'refresh'
        user = ckan_factories.User()
        user['capacity'] = 'admin'
        org = ckan_factories.Organization(users=[user])
        source_dict = dict(SOURCE_DICT.items() + [('publisher_id', org['id'])])
        source = factories.HarvestSource(**source_dict)

        data_dict = {'source_id': source['id'], 'run': True}
        job = toolkit.get_action('harvest_job_create')({
            'user': user['name']
        }, data_dict)

        assert_equal(job['source_id'], source['id'])
        assert_equal(job['status'], 'Running')
        assert_equal(job['gather_started'], None)
        assert_in('stats', job.keys())
Ejemplo n.º 6
0
    def test_harvest_job_create_as_admin(self):
        # as if an admin user presses 'refresh'
        user = ckan_factories.User()
        user['capacity'] = 'admin'
        org = ckan_factories.Organization(users=[user])
        source_dict = SOURCE_DICT.copy()
        source_dict['publisher_id'] = org['id']

        source = factories.HarvestSource(**source_dict)

        data_dict = {'source_id': source['id'], 'run': True}
        job = get_action('harvest_job_create')({
            'user': user['name']
        }, data_dict)

        assert job['source_id'] == source['id']
        assert job['status'] == 'Running'
        assert job['gather_started'] is None
        assert 'stats' in job.keys()
Ejemplo n.º 7
0
 def setup(self):
     uid = str(int(time.time()) + 2)
     name = "test_org" + uid
     organization = factories.Organization(name=name)
     group_1 = "test_group_1" + uid
     group_2 = "test_group_2" + uid
     self.group1 = factories.Group(name=group_1)
     self.group2 = factories.Group(name=group_2)
     dataset_1 = "test_dataset_1" + uid
     dataset_2 = "test_dataset_2" + uid
     self.dataset1 = factories.Dataset(name=dataset_1,
                                       owner_org=organization['id'],
                                       groups=[{
                                           "name": self.group1["name"]
                                       }])
     self.dataset2 = factories.Dataset(name=dataset_2,
                                       owner_org=organization['id'],
                                       groups=[{
                                           "name": self.group2["name"]
                                       }])
Ejemplo n.º 8
0
    def _create_harvest_source_with_owner_org_and_job_if_not_existing(self):
        site_user = toolkit.get_action('get_site_user')(
            {'model': model, 'ignore_auth': True}, {})['name']

        context = {
            'user': site_user,
            'model': model,
            'session': model.Session,
            'ignore_auth': True,
        }

        test_org = ckan_factories.Organization()
        test_other_org = ckan_factories.Organization()
        org_admin_user = ckan_factories.User()
        org_member_user = ckan_factories.User()
        other_org_admin_user = ckan_factories.User()

        toolkit.get_action('organization_member_create')(
            context.copy(),
            {
                'id': test_org['id'],
                'username': org_admin_user['name'],
                'role': 'admin'
            }
        )

        toolkit.get_action('organization_member_create')(
            context.copy(),
            {
                'id': test_org['id'],
                'username': org_member_user['name'],
                'role': 'member'
            }
        )

        toolkit.get_action('organization_member_create')(
            context.copy(),
            {
                'id': test_other_org['id'],
                'username': other_org_admin_user['name'],
                'role': 'admin'
            }
        )

        source_dict = {
            'title': 'Test Source',
            'name': 'test-source',
            'url': 'basic_test',
            'source_type': 'test-nose',
            'owner_org': test_org['id'],
            'run': True
        }

        try:
            harvest_source = toolkit.get_action('harvest_source_create')(
                context.copy(),
                source_dict
            )
        except toolkit.ValidationError:
            harvest_source = toolkit.get_action('harvest_source_show')(
                context.copy(),
                {'id': source_dict['name']}
            )
            pass

        try:
            job = toolkit.get_action('harvest_job_create')(context.copy(), {
                'source_id': harvest_source['id'], 'run': True})
        except HarvestJobExists:
            job = toolkit.get_action('harvest_job_show')(context.copy(), {
                'id': harvest_source['status']['last_job']['id']})
            pass

        toolkit.get_action('harvest_jobs_run')(context.copy(), {})
        toolkit.get_action('harvest_source_reindex')(context.copy(), {'id': harvest_source['id']})
        return context, harvest_source, job