Skip to content

Commit

Permalink
Merge branch 'master' into 3196-common-url_for-tests
Browse files Browse the repository at this point in the history
Conflicts:
	ckan/config/middleware/flask_app.py
  • Loading branch information
amercader committed Aug 31, 2016
2 parents 9b9313f + eb86250 commit 00a9193
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 142 deletions.
2 changes: 0 additions & 2 deletions ckan/config/deployment.ini_tmpl
Expand Up @@ -78,8 +78,6 @@ ckan.auth.roles_that_cascade_to_sub_groups = admin
ckan.site_id = default
#solr_url = http://127.0.0.1:8983/solr

#ckan.simple_search = 1


## CORS Settings

Expand Down
6 changes: 6 additions & 0 deletions ckan/config/middleware/flask_app.py
Expand Up @@ -193,6 +193,12 @@ def hello_world_post():
}
app = Fanstatic(app, **fanstatic_config)

# Update the main CKAN config object with the Flask specific keys
# that were set here or autogenerated
flask_config_keys = set(flask_app.config.keys()) - set(config.keys())
for key in flask_config_keys:
config[key] = flask_app.config[key]

# Add a reference to the actual Flask app so it's easier to access
app._wsgi_app = flask_app

Expand Down
2 changes: 1 addition & 1 deletion ckan/config/routing.py
Expand Up @@ -9,10 +9,10 @@
"""
import re

from pylons import config
from routes.mapper import SubMapper, Mapper as _Mapper

import ckan.plugins as p
from ckan.common import config

named_routes = {}

Expand Down
21 changes: 14 additions & 7 deletions ckan/controllers/feed.py
Expand Up @@ -170,12 +170,17 @@ def _alternate_url(self, params, **kwargs):
def _group_or_organization(self, obj_dict, is_org):

data_dict, params = self._parse_url_params()
key = 'owner_org' if is_org else 'groups'
data_dict['fq'] = '%s:"%s"' % (key, obj_dict['id'],)
group_type = 'organization'
if not is_org:
if is_org:
key = 'owner_org'
value = obj_dict['id']
group_type = 'organization'
else:
key = 'groups'
value = obj_dict['name']
group_type = 'group'

data_dict['fq'] = '{0}:"{1}"'.format(key, value)

item_count, results = _package_search(data_dict)

navigation_urls = self._navigation_urls(params,
Expand Down Expand Up @@ -259,12 +264,14 @@ def tag(self, id):

alternate_url = self._alternate_url(params, tags=id)

site_title = config.get('ckan.site_title', 'CKAN')

return self.output_feed(results,
feed_title=u'%s - Tag: "%s"' %
(g.site_title, id),
(site_title, id),
feed_description=u'Recently created or '
'updated datasets on %s by tag: "%s"' %
(g.site_title, id),
(site_title, id),
feed_link=alternate_url,
feed_guid=_create_atom_id
(u'/feeds/tag/%s.atom' % id),
Expand Down Expand Up @@ -346,7 +353,7 @@ def custom(self):
feed_title=u'%s - Custom query' % site_title,
feed_description=u'Recently created or updated'
' datasets on %s. Custom query: \'%s\'' %
(g.site_title, q),
(site_title, q),
feed_link=alternate_url,
feed_guid=_create_atom_id(atom_url),
feed_url=feed_url,
Expand Down
2 changes: 1 addition & 1 deletion ckan/lib/render.py
Expand Up @@ -4,7 +4,7 @@
import re
import logging

from pylons import config
from ckan.common import config

log = logging.getLogger(__name__)

Expand Down
21 changes: 4 additions & 17 deletions ckan/lib/search/__init__.py
Expand Up @@ -7,7 +7,6 @@
import xml.dom.minidom
import urllib2

from ckan.common import config
from paste.deploy.converters import asbool

import ckan.model as model
Expand All @@ -23,7 +22,6 @@
log = logging.getLogger(__name__)



def text_traceback():
with warnings.catch_warnings():
warnings.simplefilter("ignore")
Expand All @@ -32,7 +30,6 @@ def text_traceback():
).strip()
return res

SIMPLE_SEARCH = asbool(config.get('ckan.simple_search', False))

SUPPORTED_SCHEMA_VERSIONS = ['2.3']

Expand Down Expand Up @@ -60,11 +57,6 @@ def text_traceback():

SOLR_SCHEMA_FILE_OFFSET = '/admin/file/?file=schema.xml'

if SIMPLE_SEARCH:
import sql as sql
_INDICES['package'] = NoopSearchIndex
_QUERIES['package'] = sql.PackageSearchQuery


def _normalize_type(_type):
if isinstance(_type, model.domain_object.DomainObject):
Expand Down Expand Up @@ -219,6 +211,7 @@ def commit():
package_index.commit()
log.info('Commited pending changes on the search index')


def check():
package_query = query_for(model.Package)

Expand Down Expand Up @@ -249,10 +242,9 @@ def clear(package_reference):


def clear_all():
if not SIMPLE_SEARCH:
package_index = index_for(model.Package)
log.debug("Clearing search index...")
package_index.clear()
package_index = index_for(model.Package)
log.debug("Clearing search index...")
package_index.clear()


def check_solr_schema_version(schema_file=None):
Expand All @@ -276,11 +268,6 @@ def check_solr_schema_version(schema_file=None):
be only used for testing purposes (Default is None)
'''


if SIMPLE_SEARCH:
# Not using the SOLR search backend
return False

if not is_available():
# Something is wrong with the SOLR server
log.warn('Problems were found while connecting to the SOLR server')
Expand Down
42 changes: 0 additions & 42 deletions ckan/lib/search/sql.py

This file was deleted.

50 changes: 50 additions & 0 deletions ckan/tests/controllers/test_feed.py
Expand Up @@ -8,6 +8,10 @@

class TestFeedNew(helpers.FunctionalTestBase):

@classmethod
def teardown_class(cls):
helpers.reset_db()

def test_atom_feed_page_zero_gives_error(self):
group = factories.Group()
offset = url_for(controller='feed', action='group',
Expand All @@ -31,3 +35,49 @@ def test_atom_feed_page_not_int_gives_error(self):
app = self._get_test_app()
res = app.get(offset, status=400)
assert '"page" parameter must be a positive integer' in res, res

def test_general_atom_feed_works(self):
dataset = factories.Dataset()
offset = url_for(controller='feed', action='general')
app = self._get_test_app()
res = app.get(offset)

assert '<title>{0}</title>'.format(dataset['title']) in res.body

def test_group_atom_feed_works(self):
group = factories.Group()
dataset = factories.Dataset(groups=[{'id': group['id']}])
offset = url_for(controller='feed', action='group',
id=group['name'])
app = self._get_test_app()
res = app.get(offset)

assert '<title>{0}</title>'.format(dataset['title']) in res.body

def test_organization_atom_feed_works(self):
group = factories.Organization()
dataset = factories.Dataset(owner_org=group['id'])
offset = url_for(controller='feed', action='organization',
id=group['name'])
app = self._get_test_app()
res = app.get(offset)

assert '<title>{0}</title>'.format(dataset['title']) in res.body

def test_custom_atom_feed_works(self):
dataset1 = factories.Dataset(
title='Test weekly',
extras=[{'key': 'frequency', 'value': 'weekly'}])
dataset2 = factories.Dataset(
title='Test daily',
extras=[{'key': 'frequency', 'value': 'daily'}])
offset = url_for(controller='feed', action='custom')
params = {
'q': 'frequency:weekly'
}
app = self._get_test_app()
res = app.get(offset, params=params)

assert '<title>{0}</title>'.format(dataset1['title']) in res.body

assert '<title>{0}</title>'.format(dataset2['title']) not in res.body
37 changes: 0 additions & 37 deletions ckan/tests/legacy/lib/test_simple_search.py

This file was deleted.

2 changes: 1 addition & 1 deletion ckanext/datapusher/cli.py
Expand Up @@ -60,7 +60,7 @@ def _confirm_or_abort(self):
sys.exit(0)

def _resubmit_all(self):
resources_ids = datastore_db.get_all_resources_ids_in_datastore()
resource_ids = datastore_db.get_all_resources_ids_in_datastore()
self._submit(resource_ids)

def _submit_all_packages(self):
Expand Down
2 changes: 1 addition & 1 deletion ckanext/example_theme/custom_config_setting/plugin.py
@@ -1,9 +1,9 @@
# encoding: utf-8

import pylons.config as config

import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit
from ckan.common import config


def show_most_popular_groups():
Expand Down
2 changes: 1 addition & 1 deletion ckanext/example_theme/custom_emails/tests.py
@@ -1,12 +1,12 @@
# encoding: utf-8

import os
from pylons import config
from ckan import plugins
import ckan.model as model
import ckan.lib.mailer as mailer
from ckan.tests import factories
from ckan.lib.base import render_jinja2
from ckan.common import config

from ckan.tests.lib.test_mailer import MailerBase
import ckan.tests.helpers as helpers
Expand Down
3 changes: 1 addition & 2 deletions ckanext/reclineview/plugin.py
Expand Up @@ -2,10 +2,9 @@

from logging import getLogger

from ckan.common import json
from ckan.common import json, config
import ckan.plugins as p
import ckan.plugins.toolkit as toolkit
from pylons import config

log = getLogger(__name__)
ignore_empty = p.toolkit.get_validator('ignore_empty')
Expand Down

0 comments on commit 00a9193

Please sign in to comment.