def test_default_groups(self):
        Group(id='group1-id', name='group1')
        Group(id='group2-id', name='group2')
        Group(id='group3-id', name='group3')

        config = {'default_groups': ['group2-id', 'group3'],
                  'remote_groups': 'only_local'}
        tmp_c = toolkit.c
        try:
            # c.user is used by the validation (annoying),
            # however patch doesn't work because it's a weird
            # StackedObjectProxy, so we swap it manually
            toolkit.c = MagicMock(user='')
            results_by_guid = run_harvest(
                url='http://localhost:%s' % mock_ckan.PORT,
                harvester=CKANHarvester(),
                config=json.dumps(config))
        finally:
            toolkit.c = tmp_c
        assert_equal(results_by_guid['dataset1-id']['errors'], [])
        groups = results_by_guid['dataset1-id']['dataset']['groups']
        group_names = set(group['name'] for group in groups)
        # group1 comes from the harvested dataset
        # group2 & 3 come from the default_groups
        assert_equal(group_names, set(('group1', 'group2', 'group3')))
    def test_group_displays_custom_fields(self):
        user = Sysadmin()
        Group(
            user=user,
            name='group-one',
            bookface='theoneandonly',
        )

        app = self._get_test_app()
        response = app.get(url='/group/about/group-one')
        assert_true('Bookface' in response.body)
Beispiel #3
0
    def test_default_groups_invalid(self):
        Group(id='group2-id', name='group2')

        # should be list of strings
        config = {'default_groups': [{'name': 'group2'}]}
        with pytest.raises(toolkit.ValidationError) as harvest_context:
            run_harvest(url='http://localhost:%s' % mock_ckan.PORT,
                        harvester=CKANHarvester(),
                        config=json.dumps(config))
        assert 'default_groups must be a list of group names/ids' in str(
            harvest_context.value)
    def test_remote_groups_only_local(self):
        # Create an existing group
        Group(id='group1-id', name='group1')

        config = {'remote_groups': 'only_local'}
        results_by_guid = run_harvest(
            url='http://localhost:%s' % mock_ckan.PORT,
            harvester=CKANHarvester(),
            config=json.dumps(config))
        assert 'dataset1-id' in results_by_guid

        # Check that the dataset was added to the existing local group
        dataset = call_action('package_show', {}, id=mock_ckan.DATASETS[0]['id'])
        assert_equal(dataset['groups'][0]['id'], mock_ckan.DATASETS[0]['groups'][0]['id'])

        # Check that the other remote group was not created locally
        assert_raises(toolkit.ObjectNotFound, call_action, 'group_show', {},
                      id='remote-group')
Beispiel #5
0
    def test_group_displays_custom_fields(self, app):
        user = Sysadmin()
        Group(user=user, name="group-one", bookface="theoneandonly")

        response = app.get("/group/about/group-one")
        assert "Bookface" in response.body