Commit d9c81bb3 authored by David Read's avatar David Read
Browse files

Fix exception on home page

parent 392ef5ad
......@@ -84,6 +84,8 @@ class HierarchyDisplay(p.SingletonPlugin):
return search_params
except TypeError:
return search_params
except AttributeError:
return search_params
# e.g. search_params['q'] = u' owner_org:"id" include_children: "True"'
query = search_params.get('q')
......
from ckan.tests import factories
from ckan import model
def create_fixtures():
parent_org = factories.Organization(name='parent_org', title='Parent')
child_org = factories.Organization(name='child_org', title='child')
member = model.Member(
group=model.Group.get(child_org['id']),
table_id=parent_org['id'], table_name='group', capacity='parent')
model.Session.add(member)
model.Session.commit()
parent_dataset = factories.Dataset(name='parent', title='Parent',
owner_org=parent_org['id'])
child_dataset = factories.Dataset(name='child', title='Child',
owner_org=child_org['id'])
factories.Dataset(name='decoy', title='Decoy')
return parent_org, child_org, parent_dataset, child_dataset
import nose.tools
from bs4 import BeautifulSoup
from ckan.tests import helpers, factories
from ckan import model
from ckan.tests import helpers
from common import create_fixtures
eq = nose.tools.assert_equals
......@@ -50,38 +50,3 @@ def scrape_search_results(response):
for dataset_li in soup.find_all('li', class_='dataset-item'):
dataset_names.add(dataset_li.find('a')['href'].split('/')[-1])
return dataset_names
class TestSearchApi(object):
def setup(self):
helpers.reset_db()
def test_package_search_is_unaffected(self):
parent_org, child_org, parent_dataset, child_dataset = \
create_fixtures()
# package_search API is unaffected by ckanext-hierarchy (only searches
# via the front-end are affected)
package_search_result = helpers.call_action(
'package_search',
fq='owner_org:{}'.format(parent_org['id']))
search_results = \
[result['name'] for result in package_search_result['results']]
eq(set(search_results), set(('parent',)))
def create_fixtures():
parent_org = factories.Organization(name='parent_org', title='Parent')
child_org = factories.Organization(name='child_org', title='child')
member = model.Member(
group=model.Group.get(child_org['id']),
table_id=parent_org['id'], table_name='group', capacity='parent')
model.Session.add(member)
model.Session.commit()
parent_dataset = factories.Dataset(name='parent', title='Parent',
owner_org=parent_org['id'])
child_dataset = factories.Dataset(name='child', title='Child',
owner_org=child_org['id'])
factories.Dataset(name='decoy', title='Decoy')
return parent_org, child_org, parent_dataset, child_dataset
'''Tests that this extension doesn't break unrelated things'''
import nose.tools
from ckan.tests import helpers
from common import create_fixtures
eq = nose.tools.assert_equals
class TestSearchApi(object):
def setup(self):
helpers.reset_db()
def test_package_search_is_unaffected(self):
parent_org, child_org, parent_dataset, child_dataset = \
create_fixtures()
# package_search API is unaffected by ckanext-hierarchy (only searches
# via the front-end are affected)
package_search_result = helpers.call_action(
'package_search',
fq='owner_org:{}'.format(parent_org['id']))
search_results = \
[result['name'] for result in package_search_result['results']]
eq(set(search_results), set(('parent',)))
class TestPages(helpers.FunctionalTestBase):
def setup(self):
helpers.reset_db()
def test_home_page(self):
parent_org, child_org, parent_dataset, child_dataset = \
create_fixtures()
app = self._get_test_app()
app.get(url='/')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment