From c20698a0cb480e6d1545a3b93cbb67bc94c7553d Mon Sep 17 00:00:00 2001 From: Ross Jones Date: Thu, 14 Jun 2012 15:14:35 +0100 Subject: [PATCH] Failing test for 2293 Uses the WUI to edit and add a package to a group, then it renames the group before checking how many datasets it has. The call via sqlalchemy shows it has the correct number of datasets, but the index page shows the wrong number as we've changed the name without re-indexing the datasets --- ckan/tests/functional/test_group.py | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/ckan/tests/functional/test_group.py b/ckan/tests/functional/test_group.py index e71cd286b1e..a38873fc0d4 100644 --- a/ckan/tests/functional/test_group.py +++ b/ckan/tests/functional/test_group.py @@ -2,6 +2,7 @@ from nose.tools import assert_equal +from ckan.tests import setup_test_search_index from ckan.plugins import SingletonPlugin, implements, IGroupController from ckan import plugins import ckan.model as model @@ -156,6 +157,8 @@ def setup_class(self): model.Session.add(model.Package(name=self.packagename)) model.repo.commit_and_remove() + setup_test_search_index() + @classmethod def teardown_class(self): model.Session.remove() @@ -273,6 +276,54 @@ def test_edit_image_url(self): group = model.Group.by_name(self.groupname) assert group.image_url == image_url, group + def test_edit_change_name(self): + group = model.Group.by_name(self.groupname) + offset = url_for(controller='group', action='edit', id=self.groupname) + res = self.app.get(offset, status=200, + extra_environ={'REMOTE_USER': 'russianfan'}) + assert 'Edit: %s' % group.title in res, res + + def update_group(res, name, with_pkg=True): + form = res.forms['group-edit'] + titlefn = 'title' + descfn = 'description' + newtitle = 'xxxxxxx' + newdesc = '''### Lots of stuff here + + Ho ho ho + ''' + form[titlefn] = newtitle + form[descfn] = newdesc + form['name'] = name + if with_pkg: + pkg = model.Package.by_name(self.packagename) + form['packages__2__name'] = pkg.name + + res = form.submit('save', status=302, + extra_environ={'REMOTE_USER': 'russianfan'}) + update_group(res, self.groupname, True) + update_group(res, "newname", False) + + model.Session.remove() + group = model.Group.by_name('newname') + + # We have the datasets in the DB, but we should also see that many + # on the group read page. + assert len(group.active_packages().all()) == 3 + + offset = url_for(controller='group', action='read', id='newname') + res = self.app.get(offset, status=200, + extra_environ={'REMOTE_USER': 'russianfan'}) + + ds = res.body + ds = ds[ds.index('datasets')-10:ds.index('datasets')+10] + assert '3 datasets found' in res, ds + + # reset the group to how we found it + group.name = self.groupname + model.Session.add(group) + + def test_edit_non_existent(self): name = u'group_does_not_exist' offset = url_for(controller='group', action='edit', id=name)