Skip to content

Commit

Permalink
Add a simple flask plugin for testing.
Browse files Browse the repository at this point in the history
A simple flask extension with a route guaranteed to come from Flask.
  • Loading branch information
brew committed Jun 14, 2016
1 parent eb72312 commit b37298b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions ckan/tests/helpers.py
Expand Up @@ -23,11 +23,13 @@
from pylons import config
import nose.tools
import mock
from flask import Blueprint

import ckan.lib.search as search
import ckan.config.middleware
import ckan.model as model
import ckan.logic as logic
import ckan.plugins as p


try:
Expand Down Expand Up @@ -459,3 +461,26 @@ def find_flask_app(test_app):
'a reference to the app they wrap?')
else:
return find_flask_app(app)


class SimpleFlaskPlugin(p.SingletonPlugin):

'''
A simple extension that implements the Flask IBlueprint interface.
This is useful to test a route that we know will be served by Flask.
'''

p.implements(p.IBlueprint)

def flask_plugin_view(self):
return 'Hello World, this is served from a simple Flask extension.'

def get_blueprint(self):
# Create Blueprint for plugin
blueprint = Blueprint(self.name, self.__module__)
# Add plugin url rule to Blueprint object
blueprint.add_url_rule('/simple_flask', 'flask_plugin_view',
self.flask_plugin_view)

return blueprint
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -165,6 +165,7 @@
'test_routing_plugin = ckan.tests.config.test_middleware:MockRoutingPlugin',
'test_flash_plugin = ckan.tests.config.test_sessions:FlashMessagePlugin',
'test_helpers_plugin = ckan.tests.lib.test_helpers:TestHelpersPlugin',
'test_simple_flask_plugin = ckan.tests.helpers:SimpleFlaskPlugin',
],
'babel.extractors': [
'ckan = ckan.lib.extract:extract_ckan',
Expand Down

0 comments on commit b37298b

Please sign in to comment.