Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#2673] Deleting routes. Test started, not complete.
- Loading branch information
David Read
committed
Oct 6, 2015
1 parent
85108d8
commit afb174e
Showing
6 changed files
with
146 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import ckan.lib.base as base | ||
|
||
render = base.render | ||
|
||
|
||
class DashboardController(base.BaseController): | ||
|
||
def main(self): | ||
return 'Main Dashboard' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from routes.mapper import SubMapper | ||
|
||
import ckan.plugins as plugins | ||
import ckan.plugins.toolkit as tk | ||
|
||
|
||
class ExampleIRoutesPlugin(plugins.SingletonPlugin): | ||
|
||
''' | ||
An example IRoutes plugin that shows: | ||
* Adding a route | ||
* Changing the path of a route | ||
''' | ||
|
||
plugins.implements(plugins.IRoutes, inherit=True) | ||
|
||
# IRoutes | ||
|
||
def before_map(self, map): | ||
controller = 'ckanext.example_iroutes.controller:DashboardController' | ||
|
||
# Adding a route | ||
with SubMapper(map, controller=controller) as m: | ||
m.connect('main_dash', | ||
'/dashboard/main', action='main', | ||
ckan_icon='dashboard'), | ||
m.connect('test1', | ||
'/dashboard/main', action='test', testid='1'), | ||
|
||
# Changing the path of a route | ||
tk._delete_routes_by_name(map, 'test1') | ||
|
||
return map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from nose.tools import assert_equal, assert_in | ||
|
||
import ckan.tests.helpers as helpers | ||
import ckan.plugins as plugins | ||
from plugins import toolkit as tk | ||
|
||
CONTROLLER = 'ckanext.example_iroutes.controller:DashboardController' | ||
|
||
|
||
class TestIRoutes(object): | ||
|
||
@classmethod | ||
def setup_class(cls): | ||
super(TestIRoutes, cls).setup_class() | ||
plugins.load('example_iroutes') | ||
|
||
@classmethod | ||
def teardown_class(cls): | ||
plugins.unload('example_iroutes') | ||
super(TestIRoutes, cls).teardown_class() | ||
|
||
def test_added_route(self): | ||
assert_equal(tk.url_for('main_dash'), '/dashboard/main') | ||
assert_equal(tk.url_for(controller=CONTROLLER, action='main'), | ||
'/dashboard/main') | ||
|
||
|
||
class TestIRoutesFunctional(helpers.FunctionalTestBase): | ||
|
||
@classmethod | ||
def setup_class(cls): | ||
super(TestIRoutesFunctional, cls).setup_class() | ||
plugins.load('example_iroutes') | ||
|
||
@classmethod | ||
def teardown_class(cls): | ||
plugins.unload('example_iroutes') | ||
super(TestIRoutesFunctional, cls).teardown_class() | ||
|
||
def test_added_route(self): | ||
app = self._get_test_app() | ||
response = app.get('/ckan-admin/myext_config_one', status=200) | ||
assert_in('Main Dashboard', response.body) | ||
|
please no double-underscore methods. Python's name munging is nasty when you do this