Skip to content

Commit

Permalink
Merge branch 'master' into feature-1515-activity-streams
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hammond committed Jan 6, 2012
2 parents 3026499 + ce703d2 commit 4749d22
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
@@ -0,0 +1,3 @@
*.po -diff
*.mo -diff
*.pot -diff
9 changes: 8 additions & 1 deletion ckan/controllers/group.py
Expand Up @@ -14,6 +14,7 @@
from ckan.logic import check_access, get_action
from ckan.logic.schema import group_form_schema
from ckan.logic import tuplize_dict, clean_dict, parse_params
from ckan.lib.dictization.model_dictize import package_dictize
import ckan.forms

class GroupController(BaseController):
Expand Down Expand Up @@ -95,15 +96,21 @@ def read(self, id):
c.group_description_formatted = desc_formatted
c.group_admins = self.authorizer.get_admins(c.group)

context['return_query'] = True
results = get_action('group_package_show')(context, data_dict)

c.page = Page(
collection=results,
page=request.params.get('page', 1),
url=h.pager_url,
items_per_page=50
items_per_page=30
)

result = []
for pkg_rev in c.page.items:
result.append(package_dictize(pkg_rev, context))
c.page.items = result

return render('group/read.html')

def new(self, data=None, errors=None, error_summary=None):
Expand Down
3 changes: 3 additions & 0 deletions ckan/logic/action/get.py
Expand Up @@ -443,6 +443,9 @@ def group_package_show(context, data_dict):
if limit:
query = query.limit(limit)

if context.get('return_query'):
return query

result = []
for pkg_rev in query.all():
result.append(package_dictize(pkg_rev, context))
Expand Down
4 changes: 2 additions & 2 deletions ckan/migration/versions/047_rename_package_group_member.py
Expand Up @@ -78,8 +78,8 @@ def upgrade(migrate_engine):
update member set table_name = 'package', capacity = 'member';
update member_revision set table_name = 'package', capacity = 'member';
update "group" set type = 'dataset_group';
update group_revision set type = 'dataset_group';
update "group" set type = 'group';
update group_revision set type = 'group';
ALTER TABLE "member"
Expand Down
2 changes: 1 addition & 1 deletion ckan/model/group.py
Expand Up @@ -57,7 +57,7 @@ def related_packages(self):
class Group(vdm.sqlalchemy.RevisionedObjectMixin,
vdm.sqlalchemy.StatefulObjectMixin,
DomainObject):
def __init__(self, name=u'', title=u'', description=u'', type=u'dataset_group'):
def __init__(self, name=u'', title=u'', description=u'', type=u'group'):
self.name = name
self.title = title
self.description = description
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/layout_base.html
Expand Up @@ -156,7 +156,7 @@ <h3 class="widget-title">Sections</h3>
Tags
</a>
</li>
<li>
<li py:if="'stats' in config.get('ckan.plugins','').split(' ')">
<a href="${url('stats')}">
Statistics
</a>
Expand Down
4 changes: 1 addition & 3 deletions ckan/tests/functional/api/test_util.py
Expand Up @@ -124,7 +124,5 @@ def test_status(self):
assert_equal(res['locale_default'], 'en')

assert_equal(type(res['extensions']), list)
expected_extensions = set()
if not model.engine_is_sqlite():
expected_extensions.add('synchronous_search')
expected_extensions = set(('stats',))
assert_equal(set(res['extensions']), expected_extensions)
7 changes: 1 addition & 6 deletions ckan/tests/functional/test_cors.py
@@ -1,15 +1,10 @@
import webtest
from ckan.tests import TestController
from ckan.tests import is_search_supported

class TestCORS(TestController):

def test_options(self):
# need webtest as it has request method
self.ourapp = webtest.TestApp(self.wsgiapp)
out = self.ourapp.request('/', method='OPTIONS')
assert out.status_int == 200, out
print out
out = self.app._gen_request(method='OPTIONS', url='/', status=200)
assert len(str(out.body)) == 0, 'OPTIONS must return no content'

def test_headers(self):
Expand Down
8 changes: 5 additions & 3 deletions ckan/tests/functional/test_pagination.py
Expand Up @@ -34,11 +34,13 @@ def teardown_class(self):
def test_search(self):
res = self.app.get(url_for(controller='package', action='search', q='groups:group_00'))
assert 'href="/dataset?q=groups%3Agroup_00&amp;page=2"' in res
assert 'href="/dataset/package_19"' in res
assert 'href="/dataset/package_00"' in res, res
assert 'href="/dataset/package_19"' in res, res

res = self.app.get(url_for(controller='package', action='search', q='groups:group_00', page=2))
assert 'href="/dataset?q=groups%3Agroup_00&amp;page=1"' in res
assert 'href="/dataset/package_20"' in res
assert 'href="/dataset/package_39"' in res

def test_group_index(self):
res = self.app.get(url_for(controller='group', action='index'))
Expand All @@ -52,11 +54,11 @@ def test_group_index(self):
def test_group_read(self):
res = self.app.get(url_for(controller='group', action='read', id='group_00'))
assert 'href="/group/group_00?page=2' in res
assert 'href="/dataset/package_49"' in res
assert 'href="/dataset/package_29"' in res

res = self.app.get(url_for(controller='group', action='read', id='group_00', page=2))
assert 'href="/group/group_00?page=1' in res
assert 'href="/dataset/package_50"' in res
assert 'href="/dataset/package_30"' in res

def test_users_index(self):
# allow for 2 extra users shown on user listing, 'logged_in' and 'visitor'
Expand Down
12 changes: 8 additions & 4 deletions ckan/tests/functional/test_user.py
Expand Up @@ -168,12 +168,14 @@ def test_login(self):

# first get redirected to user/logged_in
assert_equal(res.status, 302)
assert res.header('Location').startswith('http://localhost/user/logged_in')
assert res.header('Location').startswith('http://localhost/user/logged_in') or \
res.header('Location').startswith('/user/logged_in')

# then get redirected to user page
res = res.follow()
assert_equal(res.status, 302)
assert_equal(res.header('Location'), 'http://localhost/user/testlogin')
assert res.header('Location') in ('http://localhost/user/testlogin',
'/user/testlogin')
res = res.follow()
assert_equal(res.status, 200)
assert 'testlogin is now logged in' in res.body
Expand Down Expand Up @@ -215,12 +217,14 @@ def test_login_wrong_password(self):

# first get redirected to logged_in
assert_equal(res.status, 302)
assert res.header('Location').startswith('http://localhost/user/logged_in')
assert res.header('Location').startswith('http://localhost/user/logged_in') or \
res.header('Location').startswith('/user/logged_in')

# then get redirected to login
res = res.follow()
assert_equal(res.status, 302)
assert res.header('Location').startswith('http://localhost/user/login')
assert res.header('Location').startswith('http://localhost/user/login') or \
res.header('Location').startswith('/user/login')
res = res.follow()
assert_equal(res.status, 200)
assert 'Login failed. Bad username or password.' in res.body
Expand Down
6 changes: 3 additions & 3 deletions ckan/tests/lib/test_dictization.py
Expand Up @@ -37,12 +37,12 @@ def setup_class(cls):
{'key': u'original media', 'state': u'active', 'value': u'"book"'}],
'groups': [{'description': u'These are books that David likes.',
'name': u'david',
'type': u'dataset_group',
'type': u'group',
'state': u'active',
'title': u"Dave's books"},
{'description': u'Roger likes these books.',
'name': u'roger',
'type': u'dataset_group',
'type': u'group',
'state': u'active',
'title': u"Roger's books"}],
'isopen': True,
Expand Down Expand Up @@ -903,7 +903,7 @@ def test_16_group_dictized(self):
'version': u'0.7a'}],
'state': u'active',
'title': u'help',
'type': u'dataset_group'}
'type': u'group'}

expected['packages'] = sorted(expected['packages'], key=lambda x: x['name'])

Expand Down
10 changes: 10 additions & 0 deletions doc/common-error-messages.rst
Expand Up @@ -101,3 +101,13 @@ This suggests that the config file specified with the paster ``--config`` parame
===========================================

This occurs when trying to ``import migrate.exceptions`` and is due to the version of sqlalchemy-migrate being used is too old - check the requires files for the version needed.

``ckan.plugins.core.PluginNotFoundException: stats``
====================================================

After the CKAN 1.5.1 release, the Stats extension was merged into the core CKAN code, and the ckanext namespace needs registering before the tests will run::

cd pyenv/src/ckan
python setup.py develop

Otherwise, this problem may be to enabling an extension which is not installed. See: :doc:`extensions`_.
7 changes: 7 additions & 0 deletions doc/test.rst
Expand Up @@ -99,6 +99,13 @@ By default, tests are run using the model defined in ``ckan/model``, but by usin
A common error when wanting to run tests against a particular database is to change ``sqlalchemy.url`` in ``test.ini`` or ``test-core.ini``. The problem is that these are versioned files and people have checked in these by mistake, creating problems for other developers and the CKAN buildbot. This is easily avoided by only changing ``sqlalchemy.url`` in your local ``development.ini`` and testing ``--with-pylons=test-core.ini``.
Testing Core Extensions
-----------------------

Some extensions are in the CKAN core codebase and have their own suite of tests. For example::

nosetests --ckan ckanext/stats/tests

Common error messages
---------------------

Expand Down
1 change: 1 addition & 0 deletions pip-requirements-test.txt
@@ -1,3 +1,4 @@
# These are packages that required when running ckan tests

nose
-e git+https://github.com/okfn/ckanclient#egg=ckanclient
4 changes: 3 additions & 1 deletion test-core.ini
Expand Up @@ -45,7 +45,7 @@ search_backend = sql
# Change API key HTTP header to something non-standard.
apikey_header_name = X-Non-Standard-CKAN-API-Key

# ckan.plugins = amqp_notifier
ckan.plugins = stats

# use <strong> so we can check that html is *not* escaped
ckan.template_head_end = <link rel="stylesheet" href="TEST_TEMPLATE_HEAD_END.css" type="text/css">
Expand All @@ -59,6 +59,8 @@ ckan.mail_from = info@test.ckan.net

ckan.locale_default = en

ckanext.stats.cache_enabled = 0

# Logging configuration
[loggers]
keys = root, ckan, sqlalchemy
Expand Down
3 changes: 0 additions & 3 deletions test.ini
Expand Up @@ -22,12 +22,9 @@ use = config:test-core.ini
# run fast.
faster_db_test_hacks = True
sqlalchemy.url = sqlite:///
ckan.plugins = stats
# NB: other test configuration should go in test-core.ini, which is
# what the postgres tests use.

ckanext.stats.cache_enabled = 0

# Logging configuration
[loggers]
keys = root, ckan, sqlalchemy
Expand Down

0 comments on commit 4749d22

Please sign in to comment.