Skip to content

Commit

Permalink
[1767][controllers][tests] fix issues with tag vocab test mock plugin…
Browse files Browse the repository at this point in the history
… interfering with other tests

update package controller register pluggable behaviour function to clear controller behaviour list and default behaviour at the start of each run
  • Loading branch information
johnglover committed Feb 15, 2012
1 parent 66993a2 commit 3c5e5a2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 31 deletions.
10 changes: 2 additions & 8 deletions ckan/controllers/package.py
Expand Up @@ -66,14 +66,9 @@ def register_pluggable_behaviour(map):
exception will be raised.
"""
global _default_controller_behaviour
_default_controller_behaviour = None
_controller_behaviour_for.clear()

# Check this method hasn't been invoked already.
# TODO: This method seems to be being invoked more than once during running of
# the tests. So I've disbabled this check until I figure out why.
#if _default_controller_behaviour is not None:
#raise ValueError, "Pluggable package controller behaviour is already defined "\
#"'%s'" % _default_controller_behaviour

# Create the mappings and register the fallback behaviour if one is found.
for plugin in PluginImplementations(IDatasetForm):
if plugin.is_fallback():
Expand All @@ -84,7 +79,6 @@ def register_pluggable_behaviour(map):

for package_type in plugin.package_types():
# Create a connection between the newly named type and the package controller
# but first we need to make sure we are not clobbering an existing domain
map.connect('/%s/new' % (package_type,), controller='package', action='new')
map.connect('%s_read' % (package_type,), '/%s/{id}' % (package_type,), controller='package', action='read')
map.connect('%s_action' % (package_type,),
Expand Down
50 changes: 27 additions & 23 deletions ckan/tests/functional/test_tag_vocab.py
Expand Up @@ -19,6 +19,8 @@ class MockVocabTagsPlugin(plugins.SingletonPlugin):
plugins.implements(plugins.IDatasetForm, inherit=True)
plugins.implements(plugins.IGenshiStreamFilter)

active = False

def is_fallback(self):
return False

Expand Down Expand Up @@ -49,27 +51,28 @@ def db_to_form_schema(self):
return schema

def filter(self, stream):
routes = request.environ.get('pylons.routes_dict')
if routes.get('controller') == 'package' \
and routes.get('action') == 'read':
# add vocab tags to the bottom of the page
tags = c.pkg_dict.get('tags', [])
for tag in tags:
if tag.get('vocabulary_id'):
stream = stream | Transformer('body')\
.append(HTML('<p>%s</p>' % tag.get('name')))
if routes.get('controller') == 'package' \
and routes.get('action') == 'edit':
# add vocabs tag select box to edit page
html = '<select id="vocab_tags" name="vocab_tags" size="60" multiple="multiple">'
selected_tags = c.pkg_dict.get('vocab_tags_selected', [])
for tag in c.vocab_tags:
if tag in selected_tags:
html += '<option selected="selected" value="%s">%s</option>' % (tag, tag)
else:
html += '<option value="%s">%s</option>' % (tag, tag)
html += '</select>'
stream = stream | Transformer('fieldset[@id="groups"]').append(HTML(html))
if self.active:
routes = request.environ.get('pylons.routes_dict')
if routes.get('controller') == 'package' \
and routes.get('action') == 'read':
# add vocab tags to the bottom of the page
tags = c.pkg_dict.get('tags', [])
for tag in tags:
if tag.get('vocabulary_id'):
stream = stream | Transformer('body')\
.append(HTML('<p>%s</p>' % tag.get('name')))
if routes.get('controller') == 'package' \
and routes.get('action') == 'edit':
# add vocabs tag select box to edit page
html = '<select id="vocab_tags" name="vocab_tags" size="60" multiple="multiple">'
selected_tags = c.pkg_dict.get('vocab_tags_selected', [])
for tag in c.vocab_tags:
if tag in selected_tags:
html += '<option selected="selected" value="%s">%s</option>' % (tag, tag)
else:
html += '<option value="%s">%s</option>' % (tag, tag)
html += '</select>'
stream = stream | Transformer('fieldset[@id="groups"]').append(HTML(html))
return stream


Expand Down Expand Up @@ -119,7 +122,7 @@ def value__set(self, value):
if not v in [option for (option, checked) in self.options]:
raise ValueError("Option %r not found (from %s)"
% (value, ', '.join(
[repr(o) for o, c in self.options]))
[repr(o) for o, checked in self.options]))
)

new_options = [(option, True) for (option, checked) in self.options if option in value]
Expand All @@ -132,7 +135,6 @@ def value__get(self):
value = property(value__get, value__set)



class TestWUI(WsgiAppCase):
@classmethod
def setup_class(cls):
Expand All @@ -144,6 +146,7 @@ def setup_class(cls):

cls.plugin = MockVocabTagsPlugin()
plugins.load(cls.plugin)
cls.plugin.active = True

# this is a hack so that the plugin is properly registered with
# the package controller class.
Expand Down Expand Up @@ -177,6 +180,7 @@ def setup_class(cls):
@classmethod
def teardown_class(cls):
plugins.unload(cls.plugin)
cls.plugin.active = False
from ckan.controllers import package as package_controller
package_controller._default_controller_behaviour = cls.old_default_controller
paste.fixture.Field.classes['select'] = cls.old_select
Expand Down

0 comments on commit 3c5e5a2

Please sign in to comment.