bbangert / routes (http://routes.groovie.org/)
Routes is a Python URL recognition and generation system similar to the Rails routing system. Routes makes it easy to create pretty and concise URL's that are RESTful with little effort.
$ hg clone http://bitbucket.org/bbangert/routes/
| commit 526: | 1b5cbbde45ae |
| parent 525: | 84e0cbbb0b35 |
| branch: | trunk |
Changed (Δ1.1 KB):
CHANGELOG (1 lines added, 1 lines removed)
docs/manual.rst (5 lines added, 3 lines removed)
routes/mapper.py (2 lines added, 2 lines removed)
tests/test_functional/test_generation.py (25 lines added, 25 lines removed)
tests/test_functional/test_middleware.py (4 lines added, 4 lines removed)
tests/test_functional/test_nonminimization.py (4 lines added, 6 lines removed)
tests/test_functional/test_recognition.py (33 lines added, 33 lines removed)
tests/test_functional/test_submapper.py (2 lines added, 2 lines removed)
tests/test_functional/test_utils.py (11 lines added, 11 lines removed)
tests/test_units/test_environment.py (1 lines added, 1 lines removed)
| … | … | @@ -10,8 +10,8 @@ Release 1.12 (**tip**) |
10 |
10 |
* Make SubMapper objects nestable and add route-generation helpers. |
11 |
11 |
* Add SubMapper-based collections |
12 |
12 |
* Make the deprecated Mapper.minimization False (disabled) by default |
13 |
* Make Mapper.explicit True by default |
|
13 |
14 |
|
14 |
||
15 |
15 |
Release 1.11 (September 28, 2009) |
16 |
16 |
================================= |
17 |
17 |
* Extensive documentation rewrite. |
Up to file-list docs/manual.rst:
| … | … | @@ -466,7 +466,9 @@ Here's an example of route memory:: |
466 |
466 |
url.current(month=4) => "/archives/2005/4/4" |
467 |
467 |
url.current() => "/archives/2005/10/4" |
468 |
468 |
|
469 |
Route memory |
|
469 |
Route memory is now disabled by default; it can be enabled globally with |
|
470 |
``map.explicit = True`` or by providing the argument ``map.explicit=True`` |
|
471 |
when first creating the mapper. |
|
470 |
472 |
|
471 |
473 |
Generation-only routes (aka. static routes) |
472 |
474 |
------------------------------------------- |
| … | … | @@ -873,8 +875,8 @@ Minimization |
873 |
875 |
|
874 |
876 |
Minimization was a misfeature which was intended to save typing, but which |
875 |
877 |
often resulted in the wrong route being chosen. Old applications that still |
876 |
depend on it should enable it by putting ``map.minimization = True`` in their |
|
877 |
route definitions. |
|
878 |
depend on it must now enable it by putting ``map.minimization = True`` in |
|
879 |
their route definitions. |
|
878 |
880 |
|
879 |
881 |
Without minimization, the URL must contain values for all path variables in |
880 |
882 |
the route:: |
Up to file-list routes/mapper.py:
| … | … | @@ -289,7 +289,7 @@ class Mapper(SubMapperParent): |
289 |
289 |
|
290 |
290 |
""" |
291 |
291 |
def __init__(self, controller_scan=controller_scan, directory=None, |
292 |
always_scan=False, register=True, explicit= |
|
292 |
always_scan=False, register=True, explicit=True): |
|
293 |
293 |
"""Create a new Mapper instance |
294 |
294 |
|
295 |
295 |
All keyword arguments are optional. |
| … | … | @@ -436,7 +436,7 @@ class Mapper(SubMapperParent): |
436 |
436 |
>>> map.extend(routes, path_prefix='/subapp') |
437 |
437 |
>>> len(map.matchlist) == 3 |
438 |
438 |
True |
439 |
>>> map.matchlist[2].routepath == ' |
|
439 |
>>> map.matchlist[2].routepath == '/subapp/index.htm' |
|
440 |
440 |
True |
441 |
441 |
|
442 |
442 |
.. note:: |
Up to file-list tests/test_functional/test_generation.py:
| … | … | @@ -25,7 +25,7 @@ class TestGeneration(unittest.TestCase): |
25 |
25 |
|
26 |
26 |
def test_dynamic_with_default(self): |
27 |
27 |
for path in ['hi/:action', 'hi/:(action)']: |
28 |
m = Mapper( |
|
28 |
m = Mapper(explicit=False) |
|
29 |
29 |
m.minimization = True |
30 |
30 |
m.connect(path) |
31 |
31 |
|
| … | … | @@ -35,7 +35,7 @@ class TestGeneration(unittest.TestCase): |
35 |
35 |
eq_('/hi', m.generate()) |
36 |
36 |
|
37 |
37 |
def test_dynamic_with_false_equivs(self): |
38 |
m = Mapper( |
|
38 |
m = Mapper(explicit=False) |
|
39 |
39 |
m.minimization = True |
40 |
40 |
m.connect('article/:page', page=False) |
41 |
41 |
m.connect(':controller/:action/:id') |
| … | … | @@ -62,7 +62,7 @@ class TestGeneration(unittest.TestCase): |
62 |
62 |
eq_('/view/None/chicago', m.generate(home=None, area='chicago')) |
63 |
63 |
|
64 |
64 |
def test_dynamic_with_underscore_parts(self): |
65 |
m = Mapper( |
|
65 |
m = Mapper(explicit=False) |
|
66 |
66 |
m.minimization = True |
67 |
67 |
m.connect('article/:small_page', small_page=False) |
68 |
68 |
m.connect(':(controller)/:(action)/:(id)') |
| … | … | @@ -74,7 +74,7 @@ class TestGeneration(unittest.TestCase): |
74 |
74 |
eq_('/article/hobbes', m.generate(small_page='hobbes')) |
75 |
75 |
|
76 |
76 |
def test_dynamic_with_false_equivs_and_splits(self): |
77 |
m = Mapper( |
|
77 |
m = Mapper(explicit=False) |
|
78 |
78 |
m.minimization = True |
79 |
79 |
m.connect('article/:(page)', page=False) |
80 |
80 |
m.connect(':(controller)/:(action)/:(id)') |
| … | … | @@ -113,7 +113,7 @@ class TestGeneration(unittest.TestCase): |
113 |
113 |
|
114 |
114 |
def test_dynamic_with_default_and_regexp_condition(self): |
115 |
115 |
for path in ['hi/:action', 'hi/:(action)']: |
116 |
m = Mapper( |
|
116 |
m = Mapper(explicit=False) |
|
117 |
117 |
m.minimization = True |
118 |
118 |
m.connect(path, requirements = {'action':'[a-z]+'}) |
119 |
119 |
|
| … | … | @@ -166,7 +166,7 @@ class TestGeneration(unittest.TestCase): |
166 |
166 |
|
167 |
167 |
def test_standard_route(self): |
168 |
168 |
for path in [':controller/:action/:id', ':(controller)/:(action)/:(id)']: |
169 |
m = Mapper( |
|
169 |
m = Mapper(explicit=False) |
|
170 |
170 |
m.minimization = True |
171 |
171 |
m.connect(path) |
172 |
172 |
|
| … | … | @@ -179,7 +179,7 @@ class TestGeneration(unittest.TestCase): |
179 |
179 |
eq_('/admin/user/show/10', m.generate(controller='admin/user', action='show', id='10')) |
180 |
180 |
|
181 |
181 |
def test_multiroute(self): |
182 |
m = Mapper( |
|
182 |
m = Mapper(explicit=False) |
|
183 |
183 |
m.minimization = True |
184 |
184 |
m.connect('archive/:year/:month/:day', controller='blog', action='view', month=None, day=None, |
185 |
185 |
requirements={'month':'\d{1,2}','day':'\d{1,2}'}) |
| … | … | @@ -193,7 +193,7 @@ class TestGeneration(unittest.TestCase): |
193 |
193 |
eq_('/viewpost/3', m.generate(controller='post', action='view', id=3)) |
194 |
194 |
|
195 |
195 |
def test_multiroute_with_splits(self): |
196 |
m = Mapper( |
|
196 |
m = Mapper(explicit=False) |
|
197 |
197 |
m.minimization = True |
198 |
198 |
m.connect('archive/:(year)/:(month)/:(day)', controller='blog', action='view', month=None, day=None, |
199 |
199 |
requirements={'month':'\d{1,2}','day':'\d{1,2}'}) |
| … | … | @@ -207,7 +207,7 @@ class TestGeneration(unittest.TestCase): |
207 |
207 |
eq_('/viewpost/3', m.generate(controller='post', action='view', id=3)) |
208 |
208 |
|
209 |
209 |
def test_big_multiroute(self): |
210 |
m = Mapper( |
|
210 |
m = Mapper(explicit=False) |
|
211 |
211 |
m.minimization = True |
212 |
212 |
m.connect('', controller='articles', action='index') |
213 |
213 |
m.connect('admin', controller='admin/general', action='index') |
| … | … | @@ -250,7 +250,7 @@ class TestGeneration(unittest.TestCase): |
250 |
250 |
eq_(None, m.generate(controller='articles', action='find_by_date', year=2004)) |
251 |
251 |
|
252 |
252 |
def test_big_multiroute_with_splits(self): |
253 |
m = Mapper( |
|
253 |
m = Mapper(explicit=False) |
|
254 |
254 |
m.minimization = True |
255 |
255 |
m.connect('', controller='articles', action='index') |
256 |
256 |
m.connect('admin', controller='admin/general', action='index') |
| … | … | @@ -293,7 +293,7 @@ class TestGeneration(unittest.TestCase): |
293 |
293 |
eq_(None, m.generate(controller='articles', action='find_by_date', year=2004)) |
294 |
294 |
|
295 |
295 |
def test_big_multiroute_with_nomin(self): |
296 |
m = Mapper( |
|
296 |
m = Mapper(explicit=False) |
|
297 |
297 |
m.minimization = False |
298 |
298 |
m.connect('', controller='articles', action='index') |
299 |
299 |
m.connect('admin', controller='admin/general', action='index') |
| … | … | @@ -359,7 +359,7 @@ class TestGeneration(unittest.TestCase): |
359 |
359 |
eq_('/pages/joe', m.generate(controller='page', action='view', title='joe')) |
360 |
360 |
|
361 |
361 |
def test_extras(self): |
362 |
m = Mapper( |
|
362 |
m = Mapper(explicit=False) |
|
363 |
363 |
m.minimization = True |
364 |
364 |
m.connect('viewpost/:id', controller='post', action='view') |
365 |
365 |
m.connect(':controller/:action/:id') |
| … | … | @@ -369,7 +369,7 @@ class TestGeneration(unittest.TestCase): |
369 |
369 |
eq_('/viewpost/2?extra=3', m.generate(controller='post', action='view', id=2, extra=3)) |
370 |
370 |
|
371 |
371 |
def test_extras_with_splits(self): |
372 |
m = Mapper( |
|
372 |
m = Mapper(explicit=False) |
|
373 |
373 |
m.minimization = True |
374 |
374 |
m.connect('viewpost/:(id)', controller='post', action='view') |
375 |
375 |
m.connect(':(controller)/:(action)/:(id)') |
| … | … | @@ -422,7 +422,7 @@ class TestGeneration(unittest.TestCase): |
422 |
422 |
eq_('/content', m.generate(controller='content')) |
423 |
423 |
|
424 |
424 |
def test_route_with_fixnum_default(self): |
425 |
m = Mapper( |
|
425 |
m = Mapper(explicit=False) |
|
426 |
426 |
m.minimization = True |
427 |
427 |
m.connect('page/:id', controller='content', action='show_page', id=1) |
428 |
428 |
m.connect(':controller/:action/:id') |
| … | … | @@ -438,7 +438,7 @@ class TestGeneration(unittest.TestCase): |
438 |
438 |
eq_('/content/show', m.generate(controller='content', action='show')) |
439 |
439 |
|
440 |
440 |
def test_route_with_fixnum_default_with_splits(self): |
441 |
m = Mapper( |
|
441 |
m = Mapper(explicit=False) |
|
442 |
442 |
m.minimization = True |
443 |
443 |
m.connect('page/:(id)', controller='content', action='show_page', id =1) |
444 |
444 |
m.connect(':(controller)/:(action)/:(id)') |
| … | … | @@ -455,7 +455,7 @@ class TestGeneration(unittest.TestCase): |
455 |
455 |
|
456 |
456 |
def test_uppercase_recognition(self): |
457 |
457 |
for path in [':controller/:action/:id', ':(controller)/:(action)/:(id)']: |
458 |
m = Mapper( |
|
458 |
m = Mapper(explicit=False) |
|
459 |
459 |
m.minimization = True |
460 |
460 |
m.connect(path) |
461 |
461 |
|
| … | … | @@ -466,7 +466,7 @@ class TestGeneration(unittest.TestCase): |
466 |
466 |
eq_('/Admin/NewsFeed', m.generate(controller='Admin/NewsFeed', action='index')) |
467 |
467 |
|
468 |
468 |
def test_backwards(self): |
469 |
m = Mapper( |
|
469 |
m = Mapper(explicit=False) |
|
470 |
470 |
m.minimization = True |
471 |
471 |
m.connect('page/:id/:action', controller='pages', action='show') |
472 |
472 |
m.connect(':controller/:action/:id') |
| … | … | @@ -475,7 +475,7 @@ class TestGeneration(unittest.TestCase): |
475 |
475 |
eq_('/pages/boo', m.generate(controller='pages', action='boo')) |
476 |
476 |
|
477 |
477 |
def test_backwards_with_splits(self): |
478 |
m = Mapper( |
|
478 |
m = Mapper(explicit=False) |
|
479 |
479 |
m.minimization = True |
480 |
480 |
m.connect('page/:(id)/:(action)', controller='pages', action='show') |
481 |
481 |
m.connect(':(controller)/:(action)/:(id)') |
| … | … | @@ -511,7 +511,7 @@ class TestGeneration(unittest.TestCase): |
511 |
511 |
eq_('/', m.generate(controller='content')) |
512 |
512 |
|
513 |
513 |
def test_url_with_prefix(self): |
514 |
m = Mapper( |
|
514 |
m = Mapper(explicit=False) |
|
515 |
515 |
m.minimization = True |
516 |
516 |
m.prefix = '/blog' |
517 |
517 |
m.connect(':controller/:action/:id') |
| … | … | @@ -522,7 +522,7 @@ class TestGeneration(unittest.TestCase): |
522 |
522 |
eq_('/blog/admin/comments', m.generate(controller='admin/comments')) |
523 |
523 |
|
524 |
524 |
def test_url_with_prefix_deeper(self): |
525 |
m = Mapper( |
|
525 |
m = Mapper(explicit=False) |
|
526 |
526 |
m.minimization = True |
527 |
527 |
m.prefix = '/blog/phil' |
528 |
528 |
m.connect(':controller/:action/:id') |
| … | … | @@ -533,7 +533,7 @@ class TestGeneration(unittest.TestCase): |
533 |
533 |
eq_('/blog/phil/admin/comments', m.generate(controller='admin/comments')) |
534 |
534 |
|
535 |
535 |
def test_url_with_environ_empty(self): |
536 |
m = Mapper( |
|
536 |
m = Mapper(explicit=False) |
|
537 |
537 |
m.minimization = True |
538 |
538 |
m.environ = dict(SCRIPT_NAME='') |
539 |
539 |
m.connect(':controller/:action/:id') |
| … | … | @@ -544,7 +544,7 @@ class TestGeneration(unittest.TestCase): |
544 |
544 |
eq_('/admin/comments', m.generate(controller='admin/comments')) |
545 |
545 |
|
546 |
546 |
def test_url_with_environ(self): |
547 |
m = Mapper( |
|
547 |
m = Mapper(explicit=False) |
|
548 |
548 |
m.minimization = True |
549 |
549 |
m.environ = dict(SCRIPT_NAME='/blog') |
550 |
550 |
m.connect(':controller/:action/:id') |
| … | … | @@ -564,7 +564,7 @@ class TestGeneration(unittest.TestCase): |
564 |
564 |
|
565 |
565 |
|
566 |
566 |
def test_url_with_environ_and_absolute(self): |
567 |
m = Mapper( |
|
567 |
m = Mapper(explicit=False) |
|
568 |
568 |
m.minimization = True |
569 |
569 |
m.environ = dict(SCRIPT_NAME='/blog') |
570 |
570 |
m.connect('image', 'image/:name', _absolute=True) |
| … | … | @@ -578,7 +578,7 @@ class TestGeneration(unittest.TestCase): |
578 |
578 |
eq_('/image/topnav.jpg', url_for('image', name='topnav.jpg')) |
579 |
579 |
|
580 |
580 |
def test_route_with_odd_leftovers(self): |
581 |
m = Mapper( |
|
581 |
m = Mapper(explicit=False) |
|
582 |
582 |
m.minimization = True |
583 |
583 |
m.connect(':controller/:(action)-:(id)') |
584 |
584 |
m.create_regs(['content','blog','admin/comments']) |
| … | … | @@ -587,7 +587,7 @@ class TestGeneration(unittest.TestCase): |
587 |
587 |
eq_('/content/index-', m.generate(controller='content')) |
588 |
588 |
|
589 |
589 |
def test_route_with_end_extension(self): |
590 |
m = Mapper( |
|
590 |
m = Mapper(explicit=False) |
|
591 |
591 |
m.connect(':controller/:(action)-:(id).html') |
592 |
592 |
m.create_regs(['content','blog','admin/comments']) |
593 |
593 |
Up to file-list tests/test_functional/test_middleware.py:
| … | … | @@ -11,7 +11,7 @@ def simple_app(environ, start_response): |
11 |
11 |
return ['The matchdict items are %s and environ is %s' % (items, environ)] |
12 |
12 |
|
13 |
13 |
def test_basic(): |
14 |
map = Mapper( |
|
14 |
map = Mapper(explicit=False) |
|
15 |
15 |
map.minimization = True |
16 |
16 |
map.connect(':controller/:action/:id') |
17 |
17 |
map.create_regs(['content']) |
| … | … | @@ -23,7 +23,7 @@ def test_basic(): |
23 |
23 |
assert "matchdict items are [('action', 'index'), ('controller', u'content'), ('id', None)]" in res |
24 |
24 |
|
25 |
25 |
def test_path_info(): |
26 |
map = Mapper( |
|
26 |
map = Mapper(explicit=False) |
|
27 |
27 |
map.minimization = True |
28 |
28 |
map.connect('myapp/*path_info', controller='myapp') |
29 |
29 |
map.connect('project/*path_info', controller='myapp') |
| … | … | @@ -45,7 +45,7 @@ def test_path_info(): |
45 |
45 |
assert "'PATH_INFO': '/pylonshq/browser/pylons/templates/default_project/+package+/pylonshq/browser/pylons/templates/default_project/+package+/controllers'" in res |
46 |
46 |
|
47 |
47 |
def test_redirect_middleware(): |
48 |
map = Mapper( |
|
48 |
map = Mapper(explicit=False) |
|
49 |
49 |
map.minimization = True |
50 |
50 |
map.connect('myapp/*path_info', controller='myapp') |
51 |
51 |
map.redirect("faq/{section}", "/static/faq/{section}.html") |
| … | … | @@ -71,7 +71,7 @@ def test_redirect_middleware(): |
71 |
71 |
eq_(res.headers['Location'], '/') |
72 |
72 |
|
73 |
73 |
def test_method_conversion(): |
74 |
map = Mapper( |
|
74 |
map = Mapper(explicit=False) |
|
75 |
75 |
map.minimization = True |
76 |
76 |
map.connect('content/:type', conditions=dict(method='DELETE')) |
77 |
77 |
map.connect(':controller/:action/:id') |
Up to file-list tests/test_functional/test_nonminimization.py:
| … | … | @@ -8,7 +8,7 @@ from routes.mapper import Mapper |
8 |
8 |
|
9 |
9 |
|
10 |
10 |
def test_basic(): |
11 |
m = Mapper( |
|
11 |
m = Mapper(explicit=False) |
|
12 |
12 |
m.minimization = False |
13 |
13 |
m.connect('/:controller/:action/:id') |
14 |
14 |
m.create_regs(['content']) |
| … | … | @@ -28,7 +28,7 @@ def test_basic(): |
28 |
28 |
eq_('/content/view/3', m.generate(controller='content', action='view', id=3)) |
29 |
29 |
|
30 |
30 |
def test_full(): |
31 |
m = Mapper( |
|
31 |
m = Mapper(explicit=False) |
|
32 |
32 |
m.minimization = False |
33 |
33 |
m.connect('/:controller/:action/', id=None) |
34 |
34 |
m.connect('/:controller/:action/:id') |
| … | … | @@ -56,7 +56,6 @@ def test_full(): |
56 |
56 |
def test_action_required(): |
57 |
57 |
m = Mapper() |
58 |
58 |
m.minimization = False |
59 |
m.explicit = True |
|
60 |
59 |
m.connect('/:controller/index', action='index') |
61 |
60 |
m.create_regs(['content']) |
62 |
61 |
|
| … | … | @@ -67,7 +66,6 @@ def test_action_required(): |
67 |
66 |
def test_query_params(): |
68 |
67 |
m = Mapper() |
69 |
68 |
m.minimization = False |
70 |
m.explicit = True |
|
71 |
69 |
m.connect('/:controller/index', action='index') |
72 |
70 |
m.create_regs(['content']) |
73 |
71 |
|
| … | … | @@ -77,7 +75,7 @@ def test_query_params(): |
77 |
75 |
|
78 |
76 |
|
79 |
77 |
def test_syntax(): |
80 |
m = Mapper( |
|
78 |
m = Mapper(explicit=False) |
|
81 |
79 |
m.minimization = False |
82 |
80 |
m.connect('/{controller}/{action}/{id}') |
83 |
81 |
m.create_regs(['content']) |
| … | … | @@ -95,7 +93,7 @@ def test_syntax(): |
95 |
93 |
eq_('/content/view/3', m.generate(controller='content', action='view', id=3)) |
96 |
94 |
|
97 |
95 |
def test_regexp_syntax(): |
98 |
m = Mapper( |
|
96 |
m = Mapper(explicit=False) |
|
99 |
97 |
m.minimization = False |
100 |
98 |
m.connect('/{controller}/{action}/{id:\d\d}') |
101 |
99 |
m.create_regs(['content']) |
Up to file-list tests/test_functional/test_recognition.py:
| … | … | @@ -11,7 +11,7 @@ from routes.util import RoutesException |
11 |
11 |
class TestRecognition(unittest.TestCase): |
12 |
12 |
|
13 |
13 |
def test_regexp_char_escaping(self): |
14 |
m = Mapper( |
|
14 |
m = Mapper(explicit=False) |
|
15 |
15 |
m.minimization = True |
16 |
16 |
m.connect(':controller/:(action).:(id)') |
17 |
17 |
m.create_regs(['content']) |
| … | … | @@ -24,7 +24,7 @@ class TestRecognition(unittest.TestCase) |
24 |
24 |
eq_(None, m.match('/findzall/view')) |
25 |
25 |
|
26 |
26 |
def test_all_static(self): |
27 |
m = Mapper( |
|
27 |
m = Mapper(explicit=False) |
|
28 |
28 |
m.minimization = True |
29 |
29 |
m.connect('hello/world/how/are/you', controller='content', action='index') |
30 |
30 |
m.create_regs([]) |
| … | … | @@ -38,7 +38,7 @@ class TestRecognition(unittest.TestCase) |
38 |
38 |
def test_unicode(self): |
39 |
39 |
hoge = u'\u30c6\u30b9\u30c8' # the word test in Japanese |
40 |
40 |
hoge_enc = hoge.encode('utf-8') |
41 |
m = Mapper( |
|
41 |
m = Mapper(explicit=False) |
|
42 |
42 |
m.minimization = True |
43 |
43 |
m.connect(':hoge') |
44 |
44 |
eq_({'controller': 'content', 'action': 'index', 'hoge': hoge}, |
| … | … | @@ -47,7 +47,7 @@ class TestRecognition(unittest.TestCase) |
47 |
47 |
def test_disabling_unicode(self): |
48 |
48 |
hoge = u'\u30c6\u30b9\u30c8' # the word test in Japanese |
49 |
49 |
hoge_enc = urllib.quote(hoge.encode('utf-8')) |
50 |
m = Mapper( |
|
50 |
m = Mapper(explicit=False) |
|
51 |
51 |
m.minimization = True |
52 |
52 |
m.encoding = None |
53 |
53 |
m.connect(':hoge') |
| … | … | @@ -56,7 +56,7 @@ class TestRecognition(unittest.TestCase) |
56 |
56 |
|
57 |
57 |
def test_basic_dynamic(self): |
58 |
58 |
for path in ['hi/:name', 'hi/:(name)']: |
59 |
m = Mapper( |
|
59 |
m = Mapper(explicit=False) |
|
60 |
60 |
m.minimization = True |
61 |
61 |
m.connect(path, controller='content') |
62 |
62 |
m.create_regs([]) |
| … | … | @@ -70,7 +70,7 @@ class TestRecognition(unittest.TestCase) |
70 |
70 |
|
71 |
71 |
def test_basic_dynamic_backwards(self): |
72 |
72 |
for path in [':name/hi', ':(name)/hi']: |
73 |
m = Mapper( |
|
73 |
m = Mapper(explicit=False) |
|
74 |
74 |
m.minimization = True |
75 |
75 |
m.connect(path) |
76 |
76 |
m.create_regs([]) |
| … | … | @@ -84,7 +84,7 @@ class TestRecognition(unittest.TestCase) |
84 |
84 |
eq_({'name':'index', 'action':'index', 'controller':'content'}, m.match('/index/hi')) |
85 |
85 |
|
86 |
86 |
def test_dynamic_with_underscores(self): |
87 |
m = Mapper( |
|
87 |
m = Mapper(explicit=False) |
|
88 |
88 |
m.minimization = True |
89 |
89 |
m.connect('article/:small_page', small_page=False) |
90 |
90 |
m.connect(':(controller)/:(action)/:(id)') |
| … | … | @@ -95,7 +95,7 @@ class TestRecognition(unittest.TestCase) |
95 |
95 |
|
96 |
96 |
def test_dynamic_with_default(self): |
97 |
97 |
for path in ['hi/:action', 'hi/:(action)']: |
98 |
m = Mapper( |
|
98 |
m = Mapper(explicit=False) |
|
99 |
99 |
m.minimization = True |
100 |
100 |
m.connect(path, controller='content') |
101 |
101 |
m.create_regs([]) |
| … | … | @@ -109,7 +109,7 @@ class TestRecognition(unittest.TestCase) |
109 |
109 |
|
110 |
110 |
def test_dynamic_with_default_backwards(self): |
111 |
111 |
for path in [':action/hi', ':(action)/hi']: |
112 |
m = Mapper( |
|
112 |
m = Mapper(explicit=False) |
|
113 |
113 |
m.minimization = True |
114 |
114 |
m.connect(path, controller='content') |
115 |
115 |
m.create_regs([]) |
| … | … | @@ -124,7 +124,7 @@ class TestRecognition(unittest.TestCase) |
124 |
124 |
|
125 |
125 |
def test_dynamic_with_string_condition(self): |
126 |
126 |
for path in [':name/hi', ':(name)/hi']: |
127 |
m = Mapper( |
|
127 |
m = Mapper(explicit=False) |
|
128 |
128 |
m.minimization = True |
129 |
129 |
m.connect(path, controller='content', requirements={'name':'index'}) |
130 |
130 |
m.create_regs([]) |
| … | … | @@ -138,7 +138,7 @@ class TestRecognition(unittest.TestCase) |
138 |
138 |
|
139 |
139 |
def test_dynamic_with_string_condition_backwards(self): |
140 |
140 |
for path in ['hi/:name', 'hi/:(name)']: |
141 |
m = Mapper( |
|
141 |
m = Mapper(explicit=False) |
|
142 |
142 |
m.minimization = True |
143 |
143 |
m.connect(path, controller='content', requirements={'name':'index'}) |
144 |
144 |
m.create_regs([]) |
| … | … | @@ -152,7 +152,7 @@ class TestRecognition(unittest.TestCase) |
152 |
152 |
|
153 |
153 |
def test_dynamic_with_regexp_condition(self): |
154 |
154 |
for path in ['hi/:name', 'hi/:(name)']: |
155 |
m = Mapper( |
|
155 |
m = Mapper(explicit=False) |
|
156 |
156 |
m.minimization = True |
157 |
157 |
m.connect(path, controller='content', requirements={'name':'[a-z]+'}) |
158 |
158 |
m.create_regs([]) |
| … | … | @@ -170,7 +170,7 @@ class TestRecognition(unittest.TestCase) |
170 |
170 |
|
171 |
171 |
def test_dynamic_with_regexp_and_default(self): |
172 |
172 |
for path in ['hi/:action', 'hi/:(action)']: |
173 |
m = Mapper( |
|
173 |
m = Mapper(explicit=False) |
|
174 |
174 |
m.minimization = True |
175 |
175 |
m.connect(path, controller='content', requirements={'action':'[a-z]+'}) |
176 |
176 |
m.create_regs([]) |
| … | … | @@ -187,7 +187,7 @@ class TestRecognition(unittest.TestCase) |
187 |
187 |
|
188 |
188 |
def test_dynamic_with_default_and_string_condition_backwards(self): |
189 |
189 |
for path in [':action/hi', ':(action)/hi']: |
190 |
m = Mapper( |
|
190 |
m = Mapper(explicit=False) |
|
191 |
191 |
m.minimization = True |
192 |
192 |
m.connect(path) |
193 |
193 |
m.create_regs([]) |
| … | … | @@ -209,7 +209,7 @@ class TestRecognition(unittest.TestCase) |
209 |
209 |
|
210 |
210 |
|
211 |
211 |
def test_multiroute(self): |
212 |
m = Mapper( |
|
212 |
m = Mapper(explicit=False) |
|
213 |
213 |
m.minimization = True |
214 |
214 |
m.connect('archive/:year/:month/:day', controller='blog', action='view', month=None, day=None, |
215 |
215 |
requirements={'month':'\d{1,2}','day':'\d{1,2}'}) |
| … | … | @@ -245,7 +245,7 @@ class TestRecognition(unittest.TestCase) |
245 |
245 |
m.match('/archive/2004/10/23')) |
246 |
246 |
|
247 |
247 |
def test_multiroute_with_splits(self): |
248 |
m = Mapper( |
|
248 |
m = Mapper(explicit=False) |
|
249 |
249 |
m.minimization = True |
250 |
250 |
m.connect('archive/:(year)/:(month)/:(day)', controller='blog', action='view', month=None, day=None, |
251 |
251 |
requirements={'month':'\d{1,2}','day':'\d{1,2}'}) |
| … | … | @@ -323,7 +323,7 @@ class TestRecognition(unittest.TestCase) |
323 |
323 |
eq_({'controller':'admin/user','action':'view','id':'4'}, m.match('/view/4/admin/user/super')) |
324 |
324 |
|
325 |
325 |
def test_dynamic_with_trailing_non_keyword_strings(self): |
326 |
m = Mapper( |
|
326 |
m = Mapper(explicit=False) |
|
327 |
327 |
m.minimization = True |
328 |
328 |
m.connect('somewhere/:over/rainbow', controller='blog') |
329 |
329 |
m.connect('somewhere/:over', controller='post') |
| … | … | @@ -481,7 +481,7 @@ class TestRecognition(unittest.TestCase) |
481 |
481 |
eq_({'controller':'admin/user', 'action':'hi'}, m.match('/hi/admin/user')) |
482 |
482 |
|
483 |
483 |
def test_standard_route(self): |
484 |
m = Mapper( |
|
484 |
m = Mapper(explicit=False) |
|
485 |
485 |
m.minimization = True |
486 |
486 |
m.connect(':controller/:action/:id') |
487 |
487 |
m.create_regs(['content','admin/user']) |
| … | … | @@ -545,7 +545,7 @@ class TestRecognition(unittest.TestCase) |
545 |
545 |
eq_({'controller':'content','action':'index'}, m.match('/')) |
546 |
546 |
|
547 |
547 |
def test_dynamic_with_prefix(self): |
548 |
m = Mapper( |
|
548 |
m = Mapper(explicit=False) |
|
549 |
549 |
m.minimization = True |
550 |
550 |
m.prefix = '/blog' |
551 |
551 |
m.connect(':controller/:action/:id') |
| … | … | @@ -564,7 +564,7 @@ class TestRecognition(unittest.TestCase) |
564 |
564 |
eq_({'controller':'archive','action':'view', 'id':'4'}, m.match('/blog/archive/view/4')) |
565 |
565 |
|
566 |
566 |
def test_dynamic_with_multiple_and_prefix(self): |
567 |
m = Mapper( |
|
567 |
m = Mapper(explicit=False) |
|
568 |
568 |
m.minimization = True |
569 |
569 |
m.prefix = '/blog' |
570 |
570 |
m.connect(':controller/:action/:id') |
| … | … | @@ -648,7 +648,7 @@ class TestRecognition(unittest.TestCase) |
648 |
648 |
m.match('/group/view-5')) |
649 |
649 |
|
650 |
650 |
def test_splits_with_slashes_and_default(self): |
651 |
m = Mapper( |
|
651 |
m = Mapper(explicit=False) |
|
652 |
652 |
m.minimization = True |
653 |
653 |
m.connect(':name/:(action)-:(id)', controller='content') |
654 |
654 |
m.create_regs([]) |
| … | … | @@ -670,7 +670,7 @@ class TestRecognition(unittest.TestCase) |
670 |
670 |
assert_raises(RoutesException, call_func) |
671 |
671 |
|
672 |
672 |
def test_routematch(self): |
673 |
m = Mapper( |
|
673 |
m = Mapper(explicit=False) |
|
674 |
674 |
m.minimization = True |
675 |
675 |
m.connect(':controller/:action/:id') |
676 |
676 |
m.create_regs(['content']) |
| … | … | @@ -682,7 +682,7 @@ class TestRecognition(unittest.TestCase) |
682 |
682 |
eq_(None, m.routematch('/nowhere')) |
683 |
683 |
|
684 |
684 |
def test_routematch_debug(self): |
685 |
m = Mapper( |
|
685 |
m = Mapper(explicit=False) |
|
686 |
686 |
m.minimization = True |
687 |
687 |
m.connect(':controller/:action/:id') |
688 |
688 |
m.debug = True |
| … | … | @@ -698,7 +698,7 @@ class TestRecognition(unittest.TestCase) |
698 |
698 |
eq_(len(debug), 0) |
699 |
699 |
|
700 |
700 |
def test_match_debug(self): |
701 |
m = Mapper( |
|
701 |
m = Mapper(explicit=False) |
|
702 |
702 |
m.minimization = True |
703 |
703 |
m.connect('nowhere', 'http://nowhere.com/', _static=True) |
704 |
704 |
m.connect(':controller/:action/:id') |
| … | … | @@ -715,7 +715,7 @@ class TestRecognition(unittest.TestCase) |
715 |
715 |
eq_(len(debug), 0) |
716 |
716 |
|
717 |
717 |
def test_conditions(self): |
718 |
m = Mapper( |
|
718 |
m = Mapper(explicit=False) |
|
719 |
719 |
m.minimization = True |
720 |
720 |
m.connect('home/upload', controller='content', action='upload', conditions=dict(method=['POST'])) |
721 |
721 |
m.connect(':controller/:action/:id') |
| … | … | @@ -741,7 +741,7 @@ class TestRecognition(unittest.TestCase) |
741 |
741 |
eq_({'action':'upload','controller':'content'}, con.mapper_dict) |
742 |
742 |
|
743 |
743 |
def test_subdomains(self): |
744 |
m = Mapper( |
|
744 |
m = Mapper(explicit=False) |
|
745 |
745 |
m.minimization = True |
746 |
746 |
m.sub_domains = True |
747 |
747 |
m.connect(':controller/:action/:id') |
| … | … | @@ -771,7 +771,7 @@ class TestRecognition(unittest.TestCase) |
771 |
771 |
con.mapper_dict) |
772 |
772 |
|
773 |
773 |
def test_subdomains_with_conditions(self): |
774 |
m = Mapper( |
|
774 |
m = Mapper(explicit=False) |
|
775 |
775 |
m.minimization = True |
776 |
776 |
m.sub_domains = True |
777 |
777 |
m.connect(':controller/:action/:id') |
| … | … | @@ -835,7 +835,7 @@ class TestRecognition(unittest.TestCase) |
835 |
835 |
eq_({'action': 'view', 'controller':'admin', 'sub_domain': 'fred'}, con.mapper_dict) |
836 |
836 |
|
837 |
837 |
def test_subdomains_with_ignore(self): |
838 |
m = Mapper( |
|
838 |
m = Mapper(explicit=False) |
|
839 |
839 |
m.minimization = True |
840 |
840 |
m.sub_domains = True |
841 |
841 |
m.sub_domains_ignore = ['www'] |
| … | … | @@ -866,7 +866,7 @@ class TestRecognition(unittest.TestCase) |
866 |
866 |
con.mapper_dict) |
867 |
867 |
|
868 |
868 |
def test_other_special_chars(self): |
869 |
m = Mapper( |
|
869 |
m = Mapper(explicit=False) |
|
870 |
870 |
m.minimization = True |
871 |
871 |
m.connect('/:year/:(slug).:(format),:(locale)', format='html', locale='en') |
872 |
872 |
m.connect('/error/:action/:id', controller='error') |
| … | … | @@ -887,7 +887,7 @@ class TestRecognition(unittest.TestCase) |
887 |
887 |
'id': 'icon-16.png'}, m.match('/error/img/icon-16.png')) |
888 |
888 |
|
889 |
889 |
def test_various_periods(self): |
890 |
m = Mapper( |
|
890 |
m = Mapper(explicit=False) |
|
891 |
891 |
m.minimization = True |
892 |
892 |
m.connect('sites/:site/pages/:page') |
893 |
893 |
m.create_regs(['content']) |
| … | … | @@ -895,7 +895,7 @@ class TestRecognition(unittest.TestCase) |
895 |
895 |
eq_({'action': u'index', 'controller': u'content', |
896 |
896 |
'site': u'python.com', 'page': u'index.html'}, |
897 |
897 |
m.match('/sites/python.com/pages/index.html')) |
898 |
m = Mapper( |
|
898 |
m = Mapper(explicit=False) |
|
899 |
899 |
m.minimization = True |
900 |
900 |
m.connect('sites/:site/pages/:page.:format', format='html') |
901 |
901 |
m.create_regs(['content']) |
| … | … | @@ -905,7 +905,7 @@ class TestRecognition(unittest.TestCase) |
905 |
905 |
m.match('/sites/python.com/pages/index.html')) |
906 |
906 |
|
907 |
907 |
def test_empty_fails(self): |
908 |
m = Mapper( |
|
908 |
m = Mapper(explicit=False) |
|
909 |
909 |
m.minimization = True |
910 |
910 |
m.connect(':controller/:action/:id') |
911 |
911 |
m.connect('', controller='content', action='view', id=4) |
| … | … | @@ -918,7 +918,7 @@ class TestRecognition(unittest.TestCase) |
918 |
918 |
assert_raises(RoutesException, call_func) |
919 |
919 |
|
920 |
920 |
def test_home_noargs(self): |
921 |
m = Mapper(controller_scan=None, directory=None, |
|
921 |
m = Mapper(controller_scan=None, directory=None, always_scan=False) |
|
922 |
922 |
m.minimization = True |
923 |
923 |
m.connect('') |
924 |
924 |
m.create_regs([]) |
Up to file-list tests/test_functional/test_submapper.py:
| … | … | @@ -30,7 +30,7 @@ class TestSubmapper(unittest.TestCase): |
30 |
30 |
assert_raises(Exception, url_for, 'entry', id='foo') |
31 |
31 |
|
32 |
32 |
def test_submapper_action(self): |
33 |
m = Mapper( |
|
33 |
m = Mapper() |
|
34 |
34 |
c = m.submapper(path_prefix='/entries', controller='entry') |
35 |
35 |
|
36 |
36 |
c.action(name='entries', action='list') |
| … | … | @@ -43,7 +43,7 @@ class TestSubmapper(unittest.TestCase): |
43 |
43 |
assert_raises(Exception, url_for, 'entries', method='DELETE') |
44 |
44 |
|
45 |
45 |
def test_submapper_link(self): |
46 |
m = Mapper( |
|
46 |
m = Mapper() |
|
47 |
47 |
c = m.submapper(path_prefix='/entries', controller='entry') |
48 |
48 |
|
49 |
49 |
c.link(rel='new') |
Up to file-list tests/test_functional/test_utils.py:
| … | … | @@ -7,7 +7,7 @@ from routes import * |
7 |
7 |
|
8 |
8 |
class TestUtils(unittest.TestCase): |
9 |
9 |
def setUp(self): |
10 |
m = Mapper( |
|
10 |
m = Mapper(explicit=False) |
|
11 |
11 |
m.minimization = True |
12 |
12 |
m.connect('archive/:year/:month/:day', controller='blog', action='view', month=None, day=None, |
13 |
13 |
requirements={'month':'\d{1,2}','day':'\d{1,2}'}) |
| … | … | @@ -444,7 +444,7 @@ class TestUtils(unittest.TestCase): |
444 |
444 |
self.con.mapper_dict = {} |
445 |
445 |
self.con.environ = dict(SCRIPT_NAME='', HTTP_HOST='example.com') |
446 |
446 |
|
447 |
m = Mapper( |
|
447 |
m = Mapper(explicit=False) |
|
448 |
448 |
m.minimization = True |
449 |
449 |
m.connect(':controller/:(action)-:(id).html') |
450 |
450 |
m.connect('archives', 'archives/:year/:month/:day/:slug', controller='archives', action='view', |
| … | … | @@ -475,7 +475,7 @@ class TestUtils(unittest.TestCase): |
475 |
475 |
self.con.mapper_dict = {} |
476 |
476 |
self.con.environ = base_environ.copy() |
477 |
477 |
|
478 |
m = Mapper( |
|
478 |
m = Mapper(explicit=False) |
|
479 |
479 |
m.minimization = True |
480 |
480 |
m.connect(':controller/:action/:id') |
481 |
481 |
m.create_regs(['content','archives','admin/comments']) |
| … | … | @@ -510,7 +510,7 @@ class TestUtils(unittest.TestCase): |
510 |
510 |
self.con.environ = base_environ.copy() |
511 |
511 |
self.con.mapper_dict = {} |
512 |
512 |
|
513 |
m = Mapper( |
|
513 |
m = Mapper(explicit=False) |
|
514 |
514 |
m.minimization = True |
515 |
515 |
m.connect(':controller/:action/:id') |
516 |
516 |
m.create_regs(['content','archives','admin/comments']) |
| … | … | @@ -529,7 +529,7 @@ class TestUtils(unittest.TestCase): |
529 |
529 |
self.con.mapper_dict = {} |
530 |
530 |
self.con.environ = base_environ.copy() |
531 |
531 |
|
532 |
m = Mapper( |
|
532 |
m = Mapper(explicit=False) |
|
533 |
533 |
m.minimization = True |
534 |
534 |
m.sub_domains = True |
535 |
535 |
m.connect(':controller/:action/:id') |
| … | … | @@ -552,7 +552,7 @@ class TestUtils(unittest.TestCase): |
552 |
552 |
self.con.mapper_dict = {} |
553 |
553 |
self.con.environ = base_environ.copy() |
554 |
554 |
|
555 |
m = Mapper( |
|
555 |
m = Mapper(explicit=False) |
|
556 |
556 |
m.minimization = True |
557 |
557 |
m.sub_domains = True |
558 |
558 |
m.sub_domains_ignore = ['www'] |
| … | … | @@ -598,7 +598,7 @@ class TestUtils(unittest.TestCase): |
598 |
598 |
self.con.mapper_dict = {} |
599 |
599 |
self.con.environ = base_environ.copy() |
600 |
600 |
|
601 |
m = Mapper( |
|
601 |
m = Mapper(explicit=False) |
|
602 |
602 |
m.minimization = True |
603 |
603 |
m.sub_domains = True |
604 |
604 |
m.connect(':controller/:action/:id') |
| … | … | @@ -637,7 +637,7 @@ class TestUtils(unittest.TestCase): |
637 |
637 |
self.con.mapper_dict = {} |
638 |
638 |
self.con.environ = base_environ.copy() |
639 |
639 |
|
640 |
m = Mapper( |
|
640 |
m = Mapper(explicit=False) |
|
641 |
641 |
m.minimization = True |
642 |
642 |
m.sub_domains = True |
643 |
643 |
m.connect(':controller/:action/:id') |
| … | … | @@ -673,7 +673,7 @@ class TestUtils(unittest.TestCase): |
673 |
673 |
here_dir = os.path.dirname(__file__) |
674 |
674 |
controller_dir = os.path.join(os.path.dirname(here_dir), |
675 |
675 |
os.path.join('test_files', 'controller_files')) |
676 |
m = Mapper(directory=controller_dir |
|
676 |
m = Mapper(directory=controller_dir, explicit=False) |
|
677 |
677 |
m.minimization = True |
678 |
678 |
m.always_scan = True |
679 |
679 |
m.connect(':controller/:action/:id') |
| … | … | @@ -684,7 +684,7 @@ class TestUtils(unittest.TestCase): |
684 |
684 |
|
685 |
685 |
class TestUtilsWithExplicit(unittest.TestCase): |
686 |
686 |
def setUp(self): |
687 |
m = Mapper( |
|
687 |
m = Mapper() |
|
688 |
688 |
m.minimization = True |
689 |
689 |
m.connect('archive/:year/:month/:day', controller='blog', action='view', month=None, day=None, |
690 |
690 |
requirements={'month':'\d{1,2}','day':'\d{1,2}'}) |
| … | … | @@ -857,7 +857,7 @@ if __name__ == '__main__': |
857 |
857 |
unittest.main() |
858 |
858 |
else: |
859 |
859 |
def bench_gen(withcache = False): |
860 |
m = Mapper( |
|
860 |
m = Mapper(explicit=False) |
|
861 |
861 |
m.connect('', controller='articles', action='index') |
862 |
862 |
m.connect('admin', controller='admin/general', action='index') |
863 |
863 |
Up to file-list tests/test_units/test_environment.py:
| … | … | @@ -3,7 +3,7 @@ import routes |
3 |
3 |
|
4 |
4 |
class TestEnvironment(unittest.TestCase): |
5 |
5 |
def setUp(self): |
6 |
m = routes.Mapper( |
|
6 |
m = routes.Mapper(explicit=False) |
|
7 |
7 |
m.minimization = True |
8 |
8 |
m.connect('archive/:year/:month/:day', controller='blog', action='view', month=None, day=None, |
9 |
9 |
requirements={'month':'\d{1,2}','day':'\d{1,2}'}) |
