From 7dc42cdfaf58c5426661ccf7965e840885f901d5 Mon Sep 17 00:00:00 2001 From: Ken Dreyer Date: Mon, 2 Aug 2021 14:30:44 -0400 Subject: [PATCH] switch from nose to pytest Nose is deprecated. Use pytest for the test suite instead. --- setup.cfg | 12 - setup.py | 2 - tests/__init__.py | 0 tests/test_files/__init__.py | 0 tests/test_functional/test_explicit_use.py | 39 +- tests/test_functional/test_generation.py | 449 ++++++------ tests/test_functional/test_middleware.py | 11 +- tests/test_functional/test_nonminimization.py | 95 ++- tests/test_functional/test_recognition.py | 675 ++++++++--------- tests/test_functional/test_resources.py | 218 +++--- tests/test_functional/test_submapper.py | 148 ++-- tests/test_functional/test_utils.py | 692 ++++++++++-------- tests/test_units/__init__.py | 0 tox.ini | 8 +- 14 files changed, 1167 insertions(+), 1182 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/test_files/__init__.py create mode 100644 tests/test_units/__init__.py diff --git a/setup.cfg b/setup.cfg index a2122d3..b0b6391 100644 --- a/setup.cfg +++ b/setup.cfg @@ -8,15 +8,3 @@ universal = 1 [egg_info] tag_build = dev tag_date = 1 - -[nosetests] -verbose=True -verbosity=1 -detailed-errors=True -with-doctest=True -with-coverage=True -cover-erase=True -cover-html=True -cover-html-dir=html_coverage -#cover-tests=True -cover-package=routes diff --git a/setup.py b/setup.py index 18d886f..7db95e7 100644 --- a/setup.py +++ b/setup.py @@ -62,10 +62,8 @@ 'GitHub: repo': 'https://github.com/bbangert/routes', }, license="MIT", - test_suite="nose.collector", include_package_data=True, zip_safe=False, - tests_require=["soupsieve<2.0", 'nose', 'webtest', 'webob', 'coverage'], install_requires=[ "six", "repoze.lru>=0.3" diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_files/__init__.py b/tests/test_files/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_functional/test_explicit_use.py b/tests/test_functional/test_explicit_use.py index b1e1cd7..5232142 100644 --- a/tests/test_functional/test_explicit_use.py +++ b/tests/test_functional/test_explicit_use.py @@ -1,7 +1,7 @@ """test_explicit_use""" import os, sys, time, unittest -from nose.tools import eq_, assert_raises, assert_is_none +import pytest from routes import * from routes.route import Route from routes.util import GenerationException @@ -17,7 +17,7 @@ def test_route_dict_use(self): env = environ.copy() env['PATH_INFO'] = '/hi/george' - eq_({'fred': 'george'}, m.match(environ=env)) + assert m.match(environ=env) == {'fred': 'george'} def test_x_forwarded(self): m = Mapper() @@ -26,7 +26,7 @@ def test_x_forwarded(self): environ = {'HTTP_X_FORWARDED_HOST': 'localhost'} url = URLGenerator(m, environ) - eq_('http://localhost/hi/smith', url(fred='smith', qualified=True)) + assert url(fred='smith', qualified=True) == 'http://localhost/hi/smith' def test_server_port(self): m = Mapper() @@ -36,7 +36,7 @@ def test_server_port(self): environ = {'SERVER_NAME': 'localhost', 'wsgi.url_scheme': 'https', 'SERVER_PORT': '993'} url = URLGenerator(m, environ) - eq_('https://localhost:993/hi/smith', url(fred='smith', qualified=True)) + assert url(fred='smith', qualified=True) == 'https://localhost:993/hi/smith' def test_subdomain_screen(self): m = Mapper() @@ -46,22 +46,23 @@ def test_subdomain_screen(self): environ = {'HTTP_HOST': 'localhost.com'} url = URLGenerator(m, environ) - eq_('http://home.localhost.com/hi/smith', url(fred='smith', sub_domain=u'home', qualified=True)) + assert url(fred='smith', sub_domain=u'home', qualified=True) == 'http://home.localhost.com/hi/smith' environ = {'HTTP_HOST': 'here.localhost.com', 'PATH_INFO': '/hi/smith'} url = URLGenerator(m, environ.copy()) - assert_raises(GenerationException, lambda: url.current(qualified=True)) + with pytest.raises(GenerationException): + url.current(qualified=True) environ = {'HTTP_HOST': 'subdomain.localhost.com'} url = URLGenerator(m, environ.copy()) - eq_('http://sub.localhost.com/hi/smith', url(fred='smith', sub_domain='sub', qualified=True)) + assert url(fred='smith', sub_domain='sub', qualified=True) == 'http://sub.localhost.com/hi/smith' environ = {'HTTP_HOST': 'sub.sub.localhost.com'} url = URLGenerator(m, environ.copy()) - eq_('http://new.localhost.com/hi/smith', url(fred='smith', sub_domain='new', qualified=True)) + assert url(fred='smith', sub_domain='new', qualified=True) == 'http://new.localhost.com/hi/smith' url = URLGenerator(m, {}) - eq_('/hi/smith', url(fred='smith', sub_domain=u'home')) + assert url(fred='smith', sub_domain=u'home') == '/hi/smith' def test_anchor(self): m = Mapper() @@ -70,7 +71,7 @@ def test_anchor(self): environ = {'HTTP_HOST': 'localhost.com'} url = URLGenerator(m, environ) - eq_('/hi/smith#here', url(fred='smith', anchor='here')) + assert url(fred='smith', anchor='here') == '/hi/smith#here' def test_static_args(self): m = Mapper() @@ -79,7 +80,7 @@ def test_static_args(self): url = URLGenerator(m, {}) - eq_('/here?q=fred&q=here%20now', url('/here', q=[u'fred', 'here now'])) + assert url('/here', q=[u'fred', 'here now']) == '/here?q=fred&q=here%20now' def test_current(self): m = Mapper() @@ -90,7 +91,7 @@ def test_current(self): match = m.routematch(environ=environ)[0] environ['wsgiorg.routing_args'] = (None, match) url = URLGenerator(m, environ) - eq_('/hi/smith', url.current()) + assert url.current() == '/hi/smith' def test_add_routes(self): map = Mapper(explicit=True) @@ -99,7 +100,7 @@ def test_add_routes(self): Route('foo', '/foo',) ] map.extend(routes) - eq_(map.match('/foo'), {}) + assert map.match('/foo') == {} def test_add_routes_conditions_unmet(self): map = Mapper(explicit=True) @@ -113,7 +114,7 @@ def test_add_routes_conditions_unmet(self): 'REQUEST_METHOD': 'GET', } map.extend(routes) - assert_is_none(map.match('/foo', environ=environ)) + assert map.match('/foo', environ=environ) is None def test_add_routes_conditions_met(self): map = Mapper(explicit=True) @@ -127,7 +128,7 @@ def test_add_routes_conditions_met(self): 'REQUEST_METHOD': 'POST', } map.extend(routes) - eq_(map.match('/foo', environ=environ), {}) + assert map.match('/foo', environ=environ) == {} def test_using_func(self): def fred(view): @@ -141,7 +142,7 @@ def fred(view): match = m.routematch(environ=environ)[0] environ['wsgiorg.routing_args'] = (None, match) url = URLGenerator(m, environ) - eq_('/hi/smith', url.current()) + assert url.current() == '/hi/smith' def test_using_prefix(self): m = Mapper() @@ -154,8 +155,8 @@ def test_using_prefix(self): environ['wsgiorg.routing_args'] = (None, match) url = URLGenerator(m, environ) - eq_('/jones/content/index', url.current()) - eq_('/jones/smith/barney', url(first='smith', last='barney')) + assert url.current() == '/jones/content/index' + assert url(first='smith', last='barney') == '/jones/smith/barney' def test_with_host_param(self): m = Mapper() @@ -164,4 +165,4 @@ def test_with_host_param(self): environ = {'HTTP_HOST': 'localhost.com'} url = URLGenerator(m, environ) - eq_('/hi/smith?host=here', url(fred='smith', host_='here')) + assert url(fred='smith', host_='here') == '/hi/smith?host=here' diff --git a/tests/test_functional/test_generation.py b/tests/test_functional/test_generation.py index b461b5f..ff9effd 100644 --- a/tests/test_functional/test_generation.py +++ b/tests/test_functional/test_generation.py @@ -2,7 +2,6 @@ import sys, time, unittest from six.moves import urllib -from nose.tools import eq_, assert_raises from routes import * class TestGeneration(unittest.TestCase): @@ -11,17 +10,17 @@ def test_all_static_no_reqs(self): m = Mapper() m.connect('hello/world') - eq_('/hello/world', m.generate()) + assert m.generate() == '/hello/world' def test_basic_dynamic(self): for path in ['hi/:fred', 'hi/:(fred)']: m = Mapper() m.connect(path) - eq_('/hi/index', m.generate(fred='index')) - eq_('/hi/show', m.generate(fred='show')) - eq_('/hi/list%20people', m.generate(fred='list people')) - eq_(None, m.generate()) + assert m.generate(fred='index') == '/hi/index' + assert m.generate(fred='show') == '/hi/show' + assert m.generate(fred='list people') == '/hi/list%20people' + assert m.generate() is None def test_relative_url(self): m = Mapper(explicit=False) @@ -31,17 +30,17 @@ def test_relative_url(self): m.connect(':controller/:action/:id') m.create_regs(['content','blog','admin/comments']) - eq_('about', url('about')) - eq_('http://localhost/about', url('about', qualified=True)) + assert url('about') == 'about' + assert url('about', qualified=True) == 'http://localhost/about' def test_basic_dynamic_explicit_use(self): m = Mapper() m.connect('hi/{fred}') url = URLGenerator(m, {}) - eq_('/hi/index', url(fred='index')) - eq_('/hi/show', url(fred='show')) - eq_('/hi/list%20people', url(fred='list people')) + assert url(fred='index') == '/hi/index' + assert url(fred='show') == '/hi/show' + assert url(fred='list people') == '/hi/list%20people' def test_dynamic_with_default(self): for path in ['hi/:action', 'hi/:(action)']: @@ -49,10 +48,10 @@ def test_dynamic_with_default(self): m.minimization = True m.connect(path) - eq_('/hi', m.generate(action='index')) - eq_('/hi/show', m.generate(action='show')) - eq_('/hi/list%20people', m.generate(action='list people')) - eq_('/hi', m.generate()) + assert m.generate(action='index') == '/hi' + assert m.generate(action='show') == '/hi/show' + assert m.generate(action='list people') == '/hi/list%20people' + assert m.generate() == '/hi' def test_dynamic_with_false_equivs(self): m = Mapper(explicit=False) @@ -60,26 +59,26 @@ def test_dynamic_with_false_equivs(self): m.connect('article/:page', page=False) m.connect(':controller/:action/:id') - eq_('/blog/view/0', m.generate(controller="blog", action="view", id="0")) - eq_('/blog/view/0', m.generate(controller="blog", action="view", id=0)) - eq_('/blog/view/False', m.generate(controller="blog", action="view", id=False)) - eq_('/blog/view/False', m.generate(controller="blog", action="view", id='False')) - eq_('/blog/view', m.generate(controller="blog", action="view", id=None)) - eq_('/blog/view', m.generate(controller="blog", action="view", id='None')) - eq_('/article', m.generate(page=None)) + assert m.generate(controller="blog", action="view", id="0") == '/blog/view/0' + assert m.generate(controller="blog", action="view", id=0) == '/blog/view/0' + assert m.generate(controller="blog", action="view", id=False) == '/blog/view/False' + assert m.generate(controller="blog", action="view", id='False') == '/blog/view/False' + assert m.generate(controller="blog", action="view", id=None) == '/blog/view' + assert m.generate(controller="blog", action="view", id='None') == '/blog/view' + assert m.generate(page=None) == '/article' m = Mapper() m.minimization = True m.connect('view/:home/:area', home="austere", area=None) - eq_('/view/sumatra', m.generate(home='sumatra')) - eq_('/view/austere/chicago', m.generate(area='chicago')) + assert m.generate(home='sumatra') == '/view/sumatra' + assert m.generate(area='chicago') == '/view/austere/chicago' m = Mapper() m.minimization = True m.connect('view/:home/:area', home=None, area=None) - eq_('/view/None/chicago', m.generate(home=None, area='chicago')) + assert m.generate(home=None, area='chicago') == '/view/None/chicago' def test_dynamic_with_underscore_parts(self): m = Mapper(explicit=False) @@ -87,11 +86,11 @@ def test_dynamic_with_underscore_parts(self): m.connect('article/:small_page', small_page=False) m.connect(':(controller)/:(action)/:(id)') - eq_('/blog/view/0', m.generate(controller="blog", action="view", id="0")) - eq_('/blog/view/False', m.generate(controller="blog", action="view", id='False')) - eq_('/blog/view', m.generate(controller="blog", action="view", id='None')) - eq_('/article', m.generate(small_page=None)) - eq_('/article/hobbes', m.generate(small_page='hobbes')) + assert m.generate(controller="blog", action="view", id="0") == '/blog/view/0' + assert m.generate(controller="blog", action="view", id='False') == '/blog/view/False' + assert m.generate(controller="blog", action="view", id='None') == '/blog/view' + assert m.generate(small_page=None) == '/article' + assert m.generate(small_page='hobbes') == '/article/hobbes' def test_dynamic_with_false_equivs_and_splits(self): m = Mapper(explicit=False) @@ -99,37 +98,37 @@ def test_dynamic_with_false_equivs_and_splits(self): m.connect('article/:(page)', page=False) m.connect(':(controller)/:(action)/:(id)') - eq_('/blog/view/0', m.generate(controller="blog", action="view", id="0")) - eq_('/blog/view/0', m.generate(controller="blog", action="view", id=0)) - eq_('/blog/view/False', m.generate(controller="blog", action="view", id=False)) - eq_('/blog/view/False', m.generate(controller="blog", action="view", id='False')) - eq_('/blog/view', m.generate(controller="blog", action="view", id=None)) - eq_('/blog/view', m.generate(controller="blog", action="view", id='None')) - eq_('/article', m.generate(page=None)) + assert m.generate(controller="blog", action="view", id="0") == '/blog/view/0' + assert m.generate(controller="blog", action="view", id=0) == '/blog/view/0' + assert m.generate(controller="blog", action="view", id=False) == '/blog/view/False' + assert m.generate(controller="blog", action="view", id='False') == '/blog/view/False' + assert m.generate(controller="blog", action="view", id=None) == '/blog/view' + assert m.generate(controller="blog", action="view", id='None') == '/blog/view' + assert m.generate(page=None) == '/article' m = Mapper() m.minimization = True m.connect('view/:(home)/:(area)', home="austere", area=None) - eq_('/view/sumatra', m.generate(home='sumatra')) - eq_('/view/austere/chicago', m.generate(area='chicago')) + assert m.generate(home='sumatra') == '/view/sumatra' + assert m.generate(area='chicago') == '/view/austere/chicago' m = Mapper() m.minimization = True m.connect('view/:(home)/:(area)', home=None, area=None) - eq_('/view/None/chicago', m.generate(home=None, area='chicago')) + assert m.generate(home=None, area='chicago') == '/view/None/chicago' def test_dynamic_with_regexp_condition(self): for path in ['hi/:name', 'hi/:(name)']: m = Mapper() m.connect(path, requirements = {'name':'[a-z]+'}) - eq_('/hi/index', m.generate(name='index')) - eq_(None, m.generate(name='fox5')) - eq_(None, m.generate(name='something_is_up')) - eq_('/hi/abunchofcharacter', m.generate(name='abunchofcharacter')) - eq_(None, m.generate()) + assert m.generate(name='index') == '/hi/index' + assert m.generate(name='fox5') is None + assert m.generate(name='something_is_up') is None + assert m.generate(name='abunchofcharacter') == '/hi/abunchofcharacter' + assert m.generate() is None def test_dynamic_with_default_and_regexp_condition(self): for path in ['hi/:action', 'hi/:(action)']: @@ -137,12 +136,12 @@ def test_dynamic_with_default_and_regexp_condition(self): m.minimization = True m.connect(path, requirements = {'action':'[a-z]+'}) - eq_('/hi', m.generate(action='index')) - eq_(None, m.generate(action='fox5')) - eq_(None, m.generate(action='something_is_up')) - eq_(None, m.generate(action='list people')) - eq_('/hi/abunchofcharacter', m.generate(action='abunchofcharacter')) - eq_('/hi', m.generate()) + assert m.generate(action='index') == '/hi' + assert m.generate(action='fox5') is None + assert m.generate(action='something_is_up') is None + assert m.generate(action='list people') is None + assert m.generate(action='abunchofcharacter') == '/hi/abunchofcharacter' + assert m.generate() == '/hi' def test_path(self): for path in ['hi/*file', 'hi/*(file)']: @@ -150,10 +149,10 @@ def test_path(self): m.minimization = True m.connect(path) - eq_('/hi', m.generate(file=None)) - eq_('/hi/books/learning_python.pdf', m.generate(file='books/learning_python.pdf')) - eq_('/hi/books/development%26whatever/learning_python.pdf', - m.generate(file='books/development&whatever/learning_python.pdf')) + assert m.generate(file=None) == '/hi' + assert m.generate(file='books/learning_python.pdf') == '/hi/books/learning_python.pdf' + assert m.generate(file='books/development&whatever/learning_python.pdf') == \ + '/hi/books/development%26whatever/learning_python.pdf' def test_path_backwards(self): for path in ['*file/hi', '*(file)/hi']: @@ -161,18 +160,18 @@ def test_path_backwards(self): m.minimization = True m.connect(path) - eq_('/hi', m.generate(file=None)) - eq_('/books/learning_python.pdf/hi', m.generate(file='books/learning_python.pdf')) - eq_('/books/development%26whatever/learning_python.pdf/hi', - m.generate(file='books/development&whatever/learning_python.pdf')) + assert m.generate(file=None) == '/hi' + assert m.generate(file='books/learning_python.pdf') == '/books/learning_python.pdf/hi' + assert m.generate(file='books/development&whatever/learning_python.pdf') == \ + '/books/development%26whatever/learning_python.pdf/hi' def test_controller(self): for path in ['hi/:controller', 'hi/:(controller)']: m = Mapper() m.connect(path) - eq_('/hi/content', m.generate(controller='content')) - eq_('/hi/admin/user', m.generate(controller='admin/user')) + assert m.generate(controller='content') == '/hi/content' + assert m.generate(controller='admin/user') == '/hi/admin/user' def test_controller_with_static(self): for path in ['hi/:controller', 'hi/:(controller)']: @@ -180,9 +179,9 @@ def test_controller_with_static(self): m.connect(path) m.connect('google', 'http://www.google.com', _static=True) - eq_('/hi/content', m.generate(controller='content')) - eq_('/hi/admin/user', m.generate(controller='admin/user')) - eq_('http://www.google.com', url_for('google')) + assert m.generate(controller='content') == '/hi/content' + assert m.generate(controller='admin/user') == '/hi/admin/user' + assert url_for('google') == 'http://www.google.com' def test_standard_route(self): for path in [':controller/:action/:id', ':(controller)/:(action)/:(id)']: @@ -190,13 +189,13 @@ def test_standard_route(self): m.minimization = True m.connect(path) - eq_('/content', m.generate(controller='content', action='index')) - eq_('/content/list', m.generate(controller='content', action='list')) - eq_('/content/show/10', m.generate(controller='content', action='show', id ='10')) + '/content', m.generate(controller='content', action='index') + '/content/list', m.generate(controller='content', action='list') + '/content/show/10', m.generate(controller='content', action='show', id ='10') - eq_('/admin/user', m.generate(controller='admin/user', action='index')) - eq_('/admin/user/list', m.generate(controller='admin/user', action='list')) - eq_('/admin/user/show/10', m.generate(controller='admin/user', action='show', id='10')) + '/admin/user', m.generate(controller='admin/user', action='index') + '/admin/user/list', m.generate(controller='admin/user', action='list') + '/admin/user/show/10', m.generate(controller='admin/user', action='show', id='10') def test_multiroute(self): m = Mapper(explicit=False) @@ -208,10 +207,10 @@ def test_multiroute(self): url = m.generate(controller='blog', action='view', year=2004, month='blah') assert url == '/blog/view?year=2004&month=blah' or url == '/blog/view?month=blah&year=2004' - eq_('/archive/2004/11', m.generate(controller='blog', action='view', year=2004, month=11)) - eq_('/archive/2004/11', m.generate(controller='blog', action='view', year=2004, month='11')) - eq_('/archive/2004', m.generate(controller='blog', action='view', year=2004)) - eq_('/viewpost/3', m.generate(controller='post', action='view', id=3)) + assert m.generate(controller='blog', action='view', year=2004, month=11) == '/archive/2004/11' + assert m.generate(controller='blog', action='view', year=2004, month='11') == '/archive/2004/11' + assert m.generate(controller='blog', action='view', year=2004) == '/archive/2004' + assert m.generate(controller='post', action='view', id=3) == '/viewpost/3' def test_multiroute_with_splits(self): m = Mapper(explicit=False) @@ -223,10 +222,10 @@ def test_multiroute_with_splits(self): url = m.generate(controller='blog', action='view', year=2004, month='blah') assert url == '/blog/view?year=2004&month=blah' or url == '/blog/view?month=blah&year=2004' - eq_('/archive/2004/11', m.generate(controller='blog', action='view', year=2004, month=11)) - eq_('/archive/2004/11', m.generate(controller='blog', action='view', year=2004, month='11')) - eq_('/archive/2004', m.generate(controller='blog', action='view', year=2004)) - eq_('/viewpost/3', m.generate(controller='post', action='view', id=3)) + assert m.generate(controller='blog', action='view', year=2004, month=11) == '/archive/2004/11' + assert m.generate(controller='blog', action='view', year=2004, month='11') == '/archive/2004/11' + assert m.generate(controller='blog', action='view', year=2004) == '/archive/2004' + assert m.generate(controller='post', action='view', id=3) == '/viewpost/3' def test_big_multiroute(self): m = Mapper(explicit=False) @@ -251,25 +250,21 @@ def test_big_multiroute(self): m.connect('pages/*name', controller='articles', action='view_page') - eq_('/pages/the/idiot/has/spoken', - m.generate(controller='articles', action='view_page', name='the/idiot/has/spoken')) - eq_('/', m.generate(controller='articles', action='index')) - eq_('/xml/articlerss/4/feed.xml', m.generate(controller='xml', action='articlerss', id=4)) - eq_('/xml/rss/feed.xml', m.generate(controller='xml', action='rss')) - eq_('/admin/comments/article/4/view/2', - m.generate(controller='admin/comments', action='view', article_id=4, id=2)) - eq_('/admin', m.generate(controller='admin/general')) - eq_('/admin/comments/article/4/index', m.generate(controller='admin/comments', article_id=4)) - eq_('/admin/comments/article/4', - m.generate(controller='admin/comments', action=None, article_id=4)) - eq_('/articles/2004/2/20/page/1', - m.generate(controller='articles', action='find_by_date', year=2004, month=2, day=20, page=1)) - eq_('/articles/category', m.generate(controller='articles', action='category')) - eq_('/xml/index/feed.xml', m.generate(controller='xml')) - eq_('/xml/articlerss/feed.xml', m.generate(controller='xml', action='articlerss')) - - eq_(None, m.generate(controller='admin/comments', id=2)) - eq_(None, m.generate(controller='articles', action='find_by_date', year=2004)) + assert m.generate(controller='articles', action='view_page', name='the/idiot/has/spoken') == '/pages/the/idiot/has/spoken' + assert m.generate(controller='articles', action='index') == '/' + assert m.generate(controller='xml', action='articlerss', id=4) == '/xml/articlerss/4/feed.xml' + assert m.generate(controller='xml', action='rss') == '/xml/rss/feed.xml' + assert m.generate(controller='admin/comments', action='view', article_id=4, id=2) == '/admin/comments/article/4/view/2' + assert m.generate(controller='admin/general') == '/admin' + assert m.generate(controller='admin/comments', article_id=4) == '/admin/comments/article/4/index' + assert m.generate(controller='admin/comments', action=None, article_id=4) == '/admin/comments/article/4' + assert m.generate(controller='articles', action='find_by_date', year=2004, month=2, day=20, page=1) == '/articles/2004/2/20/page/1' + assert m.generate(controller='articles', action='category') == '/articles/category' + assert m.generate(controller='xml') == '/xml/index/feed.xml' + assert m.generate(controller='xml', action='articlerss') == '/xml/articlerss/feed.xml' + + assert m.generate(controller='admin/comments', id=2) is None + assert m.generate(controller='articles', action='find_by_date', year=2004) is None def test_big_multiroute_with_splits(self): m = Mapper(explicit=False) @@ -293,26 +288,22 @@ def test_big_multiroute_with_splits(self): m.connect('articles/category/:id', controller='articles', action='category') m.connect('pages/*name', controller='articles', action='view_page') + assert m.generate(controller='articles', action='view_page', name='the/idiot/has/spoken') == '/pages/the/idiot/has/spoken' + assert m.generate(controller='articles', action='index') == '/' + assert m.generate(controller='xml', action='articlerss', id=4) == '/xml/articlerss/4/feed.xml' + assert m.generate(controller='xml', action='rss') == '/xml/rss/feed.xml' + assert m.generate(controller='admin/comments', action='view', article_id=4, id=2) == '/admin/comments/article/4/view/2.html' + assert m.generate(controller='admin/general') == '/admin' + assert m.generate(controller='admin/comments', article_id=4, action='edit', id=3) == '/admin/comments/article/4/edit/3.html' + + assert m.generate(controller='admin/comments', action=None, article_id=4) is None + assert m.generate(controller='articles', action='find_by_date', year=2004, month=2, day=20, page=1) == '/articles/2004/2/20/page/1' + assert m.generate(controller='articles', action='category') == '/articles/category' + assert m.generate(controller='xml') == '/xml/index/feed.xml' + assert m.generate(controller='xml', action='articlerss') == '/xml/articlerss/feed.xml' - eq_('/pages/the/idiot/has/spoken', - m.generate(controller='articles', action='view_page', name='the/idiot/has/spoken')) - eq_('/', m.generate(controller='articles', action='index')) - eq_('/xml/articlerss/4/feed.xml', m.generate(controller='xml', action='articlerss', id=4)) - eq_('/xml/rss/feed.xml', m.generate(controller='xml', action='rss')) - eq_('/admin/comments/article/4/view/2.html', - m.generate(controller='admin/comments', action='view', article_id=4, id=2)) - eq_('/admin', m.generate(controller='admin/general')) - eq_('/admin/comments/article/4/edit/3.html', - m.generate(controller='admin/comments', article_id=4, action='edit', id=3)) - eq_(None, m.generate(controller='admin/comments', action=None, article_id=4)) - eq_('/articles/2004/2/20/page/1', - m.generate(controller='articles', action='find_by_date', year=2004, month=2, day=20, page=1)) - eq_('/articles/category', m.generate(controller='articles', action='category')) - eq_('/xml/index/feed.xml', m.generate(controller='xml')) - eq_('/xml/articlerss/feed.xml', m.generate(controller='xml', action='articlerss')) - - eq_(None, m.generate(controller='admin/comments', id=2)) - eq_(None, m.generate(controller='articles', action='find_by_date', year=2004)) + assert m.generate(controller='admin/comments', id=2) is None + assert m.generate(controller='articles', action='find_by_date', year=2004) is None def test_big_multiroute_with_nomin(self): m = Mapper(explicit=False) @@ -337,23 +328,20 @@ def test_big_multiroute_with_nomin(self): m.connect('pages/*name', controller='articles', action='view_page') - eq_('/pages/the/idiot/has/spoken', - m.generate(controller='articles', action='view_page', name='the/idiot/has/spoken')) - eq_('/', m.generate(controller='articles', action='index')) - eq_('/xml/articlerss/4/feed.xml', m.generate(controller='xml', action='articlerss', id=4)) - eq_('/xml/rss/feed.xml', m.generate(controller='xml', action='rss')) - eq_('/admin/comments/article/4/view/2', - m.generate(controller='admin/comments', action='view', article_id=4, id=2)) - eq_('/admin', m.generate(controller='admin/general')) - eq_('/articles/2004/2/20/page/1', - m.generate(controller='articles', action='find_by_date', year=2004, month=2, day=20, page=1)) - eq_(None, m.generate(controller='articles', action='category')) - eq_('/articles/category/4', m.generate(controller='articles', action='category', id=4)) - eq_('/xml/index/feed.xml', m.generate(controller='xml')) - eq_('/xml/articlerss/feed.xml', m.generate(controller='xml', action='articlerss')) - - eq_(None, m.generate(controller='admin/comments', id=2)) - eq_(None, m.generate(controller='articles', action='find_by_date', year=2004)) + assert m.generate(controller='articles', action='view_page', name='the/idiot/has/spoken') == '/pages/the/idiot/has/spoken' + assert m.generate(controller='articles', action='index') == '/' + assert m.generate(controller='xml', action='articlerss', id=4) == '/xml/articlerss/4/feed.xml' + assert m.generate(controller='xml', action='rss') == '/xml/rss/feed.xml' + assert m.generate(controller='admin/comments', action='view', article_id=4, id=2) == '/admin/comments/article/4/view/2' + assert m.generate(controller='admin/general') == '/admin' + assert m.generate(controller='articles', action='find_by_date', year=2004, month=2, day=20, page=1) == '/articles/2004/2/20/page/1' + assert m.generate(controller='articles', action='category') is None + assert m.generate(controller='articles', action='category', id=4) == '/articles/category/4' + assert m.generate(controller='xml') == '/xml/index/feed.xml' + assert m.generate(controller='xml', action='articlerss') == '/xml/articlerss/feed.xml' + + assert m.generate(controller='admin/comments', id=2) is None + assert m.generate(controller='articles', action='find_by_date', year=2004) is None def test_no_extras(self): m = Mapper() @@ -361,7 +349,7 @@ def test_no_extras(self): m.connect(':controller/:action/:id') m.connect('archive/:year/:month/:day', controller='blog', action='view', month=None, day=None) - eq_('/archive/2004', m.generate(controller='blog', action='view', year=2004)) + assert m.generate(controller='blog', action='view', year=2004) == '/archive/2004' def test_no_extras_with_splits(self): m = Mapper() @@ -369,7 +357,7 @@ def test_no_extras_with_splits(self): m.connect(':(controller)/:(action)/:(id)') m.connect('archive/:(year)/:(month)/:(day)', controller='blog', action='view', month=None, day=None) - eq_('/archive/2004', m.generate(controller='blog', action='view', year=2004)) + assert m.generate(controller='blog', action='view', year=2004) == '/archive/2004' def test_the_smallest_route(self): for path in ['pages/:title', 'pages/:(title)']: @@ -377,8 +365,8 @@ def test_the_smallest_route(self): m.connect('', controller='page', action='view', title='HomePage') m.connect(path, controller='page', action='view') - eq_('/', m.generate(controller='page', action='view', title='HomePage')) - eq_('/pages/joe', m.generate(controller='page', action='view', title='joe')) + assert m.generate(controller='page', action='view', title='HomePage') == '/' + assert m.generate(controller='page', action='view', title='joe') == '/pages/joe' def test_extras(self): m = Mapper(explicit=False) @@ -386,9 +374,9 @@ def test_extras(self): m.connect('viewpost/:id', controller='post', action='view') m.connect(':controller/:action/:id') - eq_('/viewpost/2?extra=x%2Fy', m.generate(controller='post', action='view', id=2, extra='x/y')) - eq_('/blog?extra=3', m.generate(controller='blog', action='index', extra=3)) - eq_('/viewpost/2?extra=3', m.generate(controller='post', action='view', id=2, extra=3)) + assert m.generate(controller='post', action='view', id=2, extra='x/y') == '/viewpost/2?extra=x%2Fy' + assert m.generate(controller='blog', action='index', extra=3) == '/blog?extra=3' + assert m.generate(controller='post', action='view', id=2, extra=3) == '/viewpost/2?extra=3' def test_extras_with_splits(self): m = Mapper(explicit=False) @@ -396,8 +384,8 @@ def test_extras_with_splits(self): m.connect('viewpost/:(id)', controller='post', action='view') m.connect(':(controller)/:(action)/:(id)') - eq_('/blog?extra=3', m.generate(controller='blog', action='index', extra=3)) - eq_('/viewpost/2?extra=3', m.generate(controller='post', action='view', id=2, extra=3)) + assert m.generate(controller='blog', action='index', extra=3) == '/blog?extra=3' + assert m.generate(controller='post', action='view', id=2, extra=3) == '/viewpost/2?extra=3' def test_extras_as_unicode(self): m = Mapper() @@ -405,7 +393,7 @@ def test_extras_as_unicode(self): thing = "whatever" euro = u"\u20ac" # Euro symbol - eq_("/%s?extra=%%E2%%82%%AC" % thing, m.generate(something=thing, extra=euro)) + assert m.generate(something=thing, extra=euro) == "/%s?extra=%%E2%%82%%AC" % thing def test_extras_as_list_of_unicodes(self): m = Mapper() @@ -413,18 +401,17 @@ def test_extras_as_list_of_unicodes(self): thing = "whatever" euro = [u"\u20ac", u"\xa3"] # Euro and Pound sterling symbols - eq_("/%s?extra=%%E2%%82%%AC&extra=%%C2%%A3" % thing, m.generate(something=thing, extra=euro)) + assert m.generate(something=thing, extra=euro) == "/%s?extra=%%E2%%82%%AC&extra=%%C2%%A3" % thing def test_static(self): m = Mapper() m.connect('hello/world',known='known_value',controller='content',action='index') - eq_('/hello/world', m.generate(controller='content',action= 'index',known ='known_value')) - eq_('/hello/world?extra=hi', - m.generate(controller='content',action='index',known='known_value',extra='hi')) + assert m.generate(controller='content',action= 'index',known ='known_value') == '/hello/world' + assert m.generate(controller='content',action='index',known='known_value',extra='hi') == '/hello/world?extra=hi' - eq_(None, m.generate(known='foo')) + assert m.generate(known='foo') is None def test_typical(self): for path in [':controller/:action/:id', ':(controller)/:(action)/:(id)']: @@ -433,15 +420,15 @@ def test_typical(self): m.minimization = True m.connect(path, action = 'index', id = None) - eq_('/content', m.generate(controller='content', action='index')) - eq_('/content/list', m.generate(controller='content', action='list')) - eq_('/content/show/10', m.generate(controller='content', action='show', id=10)) + assert m.generate(controller='content', action='index') == '/content' + assert m.generate(controller='content', action='list') == '/content/list' + assert m.generate(controller='content', action='show', id=10) == '/content/show/10' - eq_('/admin/user', m.generate(controller='admin/user', action='index')) - eq_('/admin/user', m.generate(controller='admin/user')) - eq_('/admin/user/show/10', m.generate(controller='admin/user', action='show', id=10)) + assert m.generate(controller='admin/user', action='index') == '/admin/user' + assert m.generate(controller='admin/user') == '/admin/user' + assert m.generate(controller='admin/user', action='show', id=10) == '/admin/user/show/10' - eq_('/content', m.generate(controller='content')) + assert m.generate(controller='content') == '/content' def test_route_with_fixnum_default(self): m = Mapper(explicit=False) @@ -449,15 +436,15 @@ def test_route_with_fixnum_default(self): m.connect('page/:id', controller='content', action='show_page', id=1) m.connect(':controller/:action/:id') - eq_('/page', m.generate(controller='content', action='show_page')) - eq_('/page', m.generate(controller='content', action='show_page', id=1)) - eq_('/page', m.generate(controller='content', action='show_page', id='1')) - eq_('/page/10', m.generate(controller='content', action='show_page', id=10)) + assert m.generate(controller='content', action='show_page') == '/page' + assert m.generate(controller='content', action='show_page', id=1) == '/page' + assert m.generate(controller='content', action='show_page', id='1') == '/page' + assert m.generate(controller='content', action='show_page', id=10) == '/page/10' - eq_('/blog/show/4', m.generate(controller='blog', action='show', id=4)) - eq_('/page', m.generate(controller='content', action='show_page')) - eq_('/page/4', m.generate(controller='content', action='show_page',id=4)) - eq_('/content/show', m.generate(controller='content', action='show')) + assert m.generate(controller='blog', action='show', id=4) == '/blog/show/4' + assert m.generate(controller='content', action='show_page') == '/page' + assert m.generate(controller='content', action='show_page',id=4) == '/page/4' + assert m.generate(controller='content', action='show') == '/content/show' def test_route_with_fixnum_default_with_splits(self): m = Mapper(explicit=False) @@ -465,15 +452,15 @@ def test_route_with_fixnum_default_with_splits(self): m.connect('page/:(id)', controller='content', action='show_page', id =1) m.connect(':(controller)/:(action)/:(id)') - eq_('/page', m.generate(controller='content', action='show_page')) - eq_('/page', m.generate(controller='content', action='show_page', id=1)) - eq_('/page', m.generate(controller='content', action='show_page', id='1')) - eq_('/page/10', m.generate(controller='content', action='show_page', id=10)) + assert m.generate(controller='content', action='show_page') == '/page' + assert m.generate(controller='content', action='show_page', id=1) == '/page' + assert m.generate(controller='content', action='show_page', id='1') == '/page' + assert m.generate(controller='content', action='show_page', id=10) == '/page/10' - eq_('/blog/show/4', m.generate(controller='blog', action='show', id=4)) - eq_('/page', m.generate(controller='content', action='show_page')) - eq_('/page/4', m.generate(controller='content', action='show_page',id=4)) - eq_('/content/show', m.generate(controller='content', action='show')) + assert m.generate(controller='blog', action='show', id=4) == '/blog/show/4' + assert m.generate(controller='content', action='show_page') == '/page' + assert m.generate(controller='content', action='show_page',id=4) == '/page/4' + assert m.generate(controller='content', action='show') == '/content/show' def test_uppercase_recognition(self): for path in [':controller/:action/:id', ':(controller)/:(action)/:(id)']: @@ -481,11 +468,10 @@ def test_uppercase_recognition(self): m.minimization = True m.connect(path) - eq_('/Content', m.generate(controller='Content', action='index')) - eq_('/Content/list', m.generate(controller='Content', action='list')) - eq_('/Content/show/10', m.generate(controller='Content', action='show', id='10')) - - eq_('/Admin/NewsFeed', m.generate(controller='Admin/NewsFeed', action='index')) + assert m.generate(controller='Content', action='index') == '/Content' + assert m.generate(controller='Content', action='list') == '/Content/list' + assert m.generate(controller='Content', action='show', id='10') == '/Content/show/10' + assert m.generate(controller='Admin/NewsFeed', action='index') == '/Admin/NewsFeed' def test_backwards(self): m = Mapper(explicit=False) @@ -493,8 +479,8 @@ def test_backwards(self): m.connect('page/:id/:action', controller='pages', action='show') m.connect(':controller/:action/:id') - eq_('/page/20', m.generate(controller='pages', action='show', id=20)) - eq_('/pages/boo', m.generate(controller='pages', action='boo')) + assert m.generate(controller='pages', action='show', id=20) == '/page/20' + assert m.generate(controller='pages', action='boo') == '/pages/boo' def test_backwards_with_splits(self): m = Mapper(explicit=False) @@ -502,16 +488,16 @@ def test_backwards_with_splits(self): m.connect('page/:(id)/:(action)', controller='pages', action='show') m.connect(':(controller)/:(action)/:(id)') - eq_('/page/20', m.generate(controller='pages', action='show', id=20)) - eq_('/pages/boo', m.generate(controller='pages', action='boo')) + assert m.generate(controller='pages', action='show', id=20) == '/page/20' + assert m.generate(controller='pages', action='boo') == '/pages/boo' def test_both_requirement_and_optional(self): m = Mapper() m.minimization = True m.connect('test/:year', controller='post', action='show', year=None, requirements = {'year':'\d{4}'}) - eq_('/test', m.generate(controller='post', action='show')) - eq_('/test', m.generate(controller='post', action='show', year=None)) + assert m.generate(controller='post', action='show') == '/test' + assert m.generate(controller='post', action='show', year=None) == '/test' def test_set_to_nil_forgets(self): m = Mapper() @@ -519,18 +505,17 @@ def test_set_to_nil_forgets(self): m.connect('pages/:year/:month/:day', controller='content', action='list_pages', month=None, day=None) m.connect(':controller/:action/:id') - eq_('/pages/2005', m.generate(controller='content', action='list_pages', year=2005)) - eq_('/pages/2005/6', m.generate(controller='content', action='list_pages', year=2005, month=6)) - eq_('/pages/2005/6/12', - m.generate(controller='content', action='list_pages', year=2005, month=6, day=12)) + assert m.generate(controller='content', action='list_pages', year=2005) == '/pages/2005' + assert m.generate(controller='content', action='list_pages', year=2005, month=6) == '/pages/2005/6' + assert m.generate(controller='content', action='list_pages', year=2005, month=6, day=12) == '/pages/2005/6/12' def test_url_with_no_action_specified(self): m = Mapper() m.connect('', controller='content') m.connect(':controller/:action/:id') - eq_('/', m.generate(controller='content', action='index')) - eq_('/', m.generate(controller='content')) + assert m.generate(controller='content', action='index') == '/' + assert m.generate(controller='content') == '/' def test_url_with_prefix(self): m = Mapper(explicit=False) @@ -539,9 +524,9 @@ def test_url_with_prefix(self): m.connect(':controller/:action/:id') m.create_regs(['content','blog','admin/comments']) - eq_('/blog/content/view', m.generate(controller='content', action='view')) - eq_('/blog/content', m.generate(controller='content')) - eq_('/blog/admin/comments', m.generate(controller='admin/comments')) + assert m.generate(controller='content', action='view') == '/blog/content/view' + assert m.generate(controller='content') == '/blog/content' + assert m.generate(controller='admin/comments') == '/blog/admin/comments' def test_url_with_prefix_deeper(self): m = Mapper(explicit=False) @@ -550,9 +535,9 @@ def test_url_with_prefix_deeper(self): m.connect(':controller/:action/:id') m.create_regs(['content','blog','admin/comments']) - eq_('/blog/phil/content/view', m.generate(controller='content', action='view')) - eq_('/blog/phil/content', m.generate(controller='content')) - eq_('/blog/phil/admin/comments', m.generate(controller='admin/comments')) + assert m.generate(controller='content', action='view') == '/blog/phil/content/view' + assert m.generate(controller='content') == '/blog/phil/content' + assert m.generate(controller='admin/comments') == '/blog/phil/admin/comments' def test_url_with_environ_empty(self): m = Mapper(explicit=False) @@ -561,9 +546,9 @@ def test_url_with_environ_empty(self): m.connect(':controller/:action/:id') m.create_regs(['content','blog','admin/comments']) - eq_('/content/view', m.generate(controller='content', action='view')) - eq_('/content', m.generate(controller='content')) - eq_('/admin/comments', m.generate(controller='admin/comments')) + assert m.generate(controller='content', action='view') == '/content/view' + assert m.generate(controller='content') == '/content' + assert m.generate(controller='admin/comments') == '/admin/comments' def test_url_with_environ(self): m = Mapper(explicit=False) @@ -572,25 +557,25 @@ def test_url_with_environ(self): m.connect(':controller/:action/:id') m.create_regs(['content','blog','admin/comments']) - eq_('/blog/content/view', m.generate(controller='content', action='view')) - eq_('/blog/content', m.generate(controller='content')) - eq_('/blog/content', m.generate(controller='content')) - eq_('/blog/admin/comments', m.generate(controller='admin/comments')) + assert m.generate(controller='content', action='view') == '/blog/content/view' + assert m.generate(controller='content') == '/blog/content' + assert m.generate(controller='content') == '/blog/content' + assert m.generate(controller='admin/comments') == '/blog/admin/comments' m.environ = dict(SCRIPT_NAME='/notblog') - eq_('/notblog/content/view', m.generate(controller='content', action='view')) - eq_('/notblog/content', m.generate(controller='content')) - eq_('/notblog/content', m.generate(controller='content')) - eq_('/notblog/admin/comments', m.generate(controller='admin/comments')) + assert m.generate(controller='content', action='view') == '/notblog/content/view' + assert m.generate(controller='content') == '/notblog/content' + assert m.generate(controller='content') == '/notblog/content' + assert m.generate(controller='admin/comments') == '/notblog/admin/comments' def test_url_with_environ_and_caching(self): m = Mapper() m.connect("foo", "/", controller="main", action="index") - eq_('/', m.generate(controller='main', action='index')) - eq_('/bar/', m.generate(controller='main', action='index', _environ=dict(SCRIPT_NAME='/bar'))) - eq_('/', m.generate(controller='main', action='index')) + assert m.generate(controller='main', action='index') == '/' + assert m.generate(controller='main', action='index', _environ=dict(SCRIPT_NAME='/bar')) == '/bar/' + assert m.generate(controller='main', action='index') == '/' def test_url_with_environ_and_absolute(self): m = Mapper(explicit=False) @@ -600,11 +585,11 @@ def test_url_with_environ_and_absolute(self): m.connect(':controller/:action/:id') m.create_regs(['content','blog','admin/comments']) - eq_('/blog/content/view', m.generate(controller='content', action='view')) - eq_('/blog/content', m.generate(controller='content')) - eq_('/blog/content', m.generate(controller='content')) - eq_('/blog/admin/comments', m.generate(controller='admin/comments')) - eq_('/image/topnav.jpg', url_for('image', name='topnav.jpg')) + assert m.generate(controller='content', action='view') == '/blog/content/view' + assert m.generate(controller='content') == '/blog/content' + assert m.generate(controller='content') == '/blog/content' + assert m.generate(controller='admin/comments') == '/blog/admin/comments' + assert url_for('image', name='topnav.jpg') == '/image/topnav.jpg' def test_route_with_odd_leftovers(self): m = Mapper(explicit=False) @@ -612,27 +597,27 @@ def test_route_with_odd_leftovers(self): m.connect(':controller/:(action)-:(id)') m.create_regs(['content','blog','admin/comments']) - eq_('/content/view-', m.generate(controller='content', action='view')) - eq_('/content/index-', m.generate(controller='content')) + assert m.generate(controller='content', action='view') == '/content/view-' + assert m.generate(controller='content') == '/content/index-' def test_route_with_end_extension(self): m = Mapper(explicit=False) m.connect(':controller/:(action)-:(id).html') m.create_regs(['content','blog','admin/comments']) - eq_(None, m.generate(controller='content', action='view')) - eq_(None, m.generate(controller='content')) + assert m.generate(controller='content', action='view') is None + assert m.generate(controller='content') is None - eq_('/content/view-3.html', m.generate(controller='content', action='view', id=3)) - eq_('/content/index-2.html', m.generate(controller='content', id=2)) + assert m.generate(controller='content', action='view', id=3) == '/content/view-3.html' + assert m.generate(controller='content', id=2) == '/content/index-2.html' def test_unicode(self): hoge = u'\u30c6\u30b9\u30c8' # the word test in Japanese hoge_enc = urllib.parse.quote(hoge.encode('utf-8')) m = Mapper() m.connect(':hoge') - eq_("/%s" % hoge_enc, m.generate(hoge=hoge)) - self.assert_(isinstance(m.generate(hoge=hoge), str)) + assert m.generate(hoge=hoge) == "/%s" % hoge_enc + assert isinstance(m.generate(hoge=hoge), str) def test_unicode_static(self): hoge = u'\u30c6\u30b9\u30c8' # the word test in Japanese @@ -641,8 +626,8 @@ def test_unicode_static(self): m.minimization = True m.connect('google-jp', 'http://www.google.co.jp/search', _static=True) m.create_regs(['messages']) - eq_("http://www.google.co.jp/search?q=" + hoge_enc, url_for('google-jp', q=hoge)) - self.assert_(isinstance(url_for('google-jp', q=hoge), str)) + assert url_for('google-jp', q=hoge) == "http://www.google.co.jp/search?q=" + hoge_enc + assert isinstance(url_for('google-jp', q=hoge), str) def test_other_special_chars(self): m = Mapper() @@ -650,10 +635,10 @@ def test_other_special_chars(self): m.connect('/:year/:(slug).:(format),:(locale)', locale='en', format='html') m.create_regs(['content']) - eq_('/2007/test', m.generate(year=2007, slug='test')) - eq_('/2007/test.xml', m.generate(year=2007, slug='test', format='xml')) - eq_('/2007/test.xml,ja', m.generate(year=2007, slug='test', format='xml', locale='ja')) - eq_(None, m.generate(year=2007, format='html')) + assert m.generate(year=2007, slug='test') == '/2007/test' + assert m.generate(year=2007, slug='test', format='xml') == '/2007/test.xml' + assert m.generate(year=2007, slug='test', format='xml', locale='ja') == '/2007/test.xml,ja' + assert m.generate(year=2007, format='html') is None def test_dot_format_args(self): for minimization in [False, True]: @@ -662,11 +647,11 @@ def test_dot_format_args(self): m.connect('/songs/{title}{.format}') m.connect('/stories/{slug}{.format:pdf}') - eq_('/songs/my-way', m.generate(title='my-way')) - eq_('/songs/my-way.mp3', m.generate(title='my-way', format='mp3')) - eq_('/stories/frist-post', m.generate(slug='frist-post')) - eq_('/stories/frist-post.pdf', m.generate(slug='frist-post', format='pdf')) - eq_(None, m.generate(slug='frist-post', format='doc')) + assert m.generate(title='my-way') == '/songs/my-way' + assert m.generate(title='my-way', format='mp3') == '/songs/my-way.mp3' + assert m.generate(slug='frist-post') == '/stories/frist-post' + assert m.generate(slug='frist-post', format='pdf') == '/stories/frist-post.pdf' + assert m.generate(slug='frist-post', format='doc') is None if __name__ == '__main__': unittest.main() diff --git a/tests/test_functional/test_middleware.py b/tests/test_functional/test_middleware.py index 882df9e..5182d17 100644 --- a/tests/test_functional/test_middleware.py +++ b/tests/test_functional/test_middleware.py @@ -1,7 +1,10 @@ from routes import Mapper from routes.middleware import RoutesMiddleware from webtest import TestApp -from nose.tools import eq_ + +# Prevent pytest from trying to collect webtest's TestApp as tests: +TestApp.__test__ = False + def simple_app(environ, start_response): route_dict = environ['wsgiorg.routing_args'][1] @@ -111,8 +114,8 @@ def test_redirect_middleware(): assert 'matchdict items are []' in res res = app.get('/faq/home') - eq_('302 Found', res.status) - eq_(res.headers['Location'], '/static/faq/home.html') + assert res.status == '302 Found' + assert res.headers['Location'] == '/static/faq/home.html' res = app.get('/myapp/some/other/url') print(res) @@ -124,7 +127,7 @@ def test_redirect_middleware(): res = app.get('/home/index') assert '301 Moved Permanently' in res.status - eq_(res.headers['Location'], '/') + assert res.headers['Location'] == '/' def test_method_conversion(): map = Mapper(explicit=False) diff --git a/tests/test_functional/test_nonminimization.py b/tests/test_functional/test_nonminimization.py index 1b152c4..744a879 100644 --- a/tests/test_functional/test_nonminimization.py +++ b/tests/test_functional/test_nonminimization.py @@ -1,8 +1,6 @@ """Test non-minimization recognition""" from six.moves import urllib -from nose.tools import eq_ - from routes import url_for from routes.mapper import Mapper @@ -14,18 +12,16 @@ def test_basic(): m.create_regs(['content']) # Recognize - eq_(None, m.match('/content')) - eq_(None, m.match('/content/index')) - eq_(None, m.match('/content/index/')) - eq_({'controller':'content','action':'index','id':'4'}, - m.match('/content/index/4')) - eq_({'controller':'content','action':'view','id':'4.html'}, - m.match('/content/view/4.html')) + assert m.match('/content') is None + assert m.match('/content/index') is None + assert m.match('/content/index/') is None + assert m.match('/content/index/4') == {'controller':'content','action':'index','id':'4'} + assert m.match('/content/view/4.html') == {'controller':'content','action':'view','id':'4.html'} # Generate - eq_(None, m.generate(controller='content')) - eq_('/content/index/4', m.generate(controller='content', id=4)) - eq_('/content/view/3', m.generate(controller='content', action='view', id=3)) + assert m.generate(controller='content') is None + assert m.generate(controller='content', id=4) == '/content/index/4' + assert m.generate(controller='content', action='view', id=3) == '/content/view/3' def test_full(): m = Mapper(explicit=False) @@ -35,23 +31,20 @@ def test_full(): m.create_regs(['content']) # Recognize - eq_(None, m.match('/content')) - eq_(None, m.match('/content/index')) - eq_({'controller':'content','action':'index','id':None}, - m.match('/content/index/')) - eq_({'controller':'content','action':'index','id':'4'}, - m.match('/content/index/4')) - eq_({'controller':'content','action':'view','id':'4.html'}, - m.match('/content/view/4.html')) + assert m.match('/content') is None + assert m.match('/content/index') is None + assert m.match('/content/index/') == {'controller':'content','action':'index','id':None} + assert m.match('/content/index/4') == {'controller':'content','action':'index','id':'4'} + assert m.match('/content/view/4.html') == {'controller':'content','action':'view','id':'4.html'} # Generate - eq_(None, m.generate(controller='content')) + assert m.generate(controller='content') is None # Looks odd, but only controller/action are set with non-explicit, so we # do need the id to match - eq_('/content/index/', m.generate(controller='content', id=None)) - eq_('/content/index/4', m.generate(controller='content', id=4)) - eq_('/content/view/3', m.generate(controller='content', action='view', id=3)) + assert m.generate(controller='content', id=None) == '/content/index/' + assert m.generate(controller='content', id=4) == '/content/index/4' + assert m.generate(controller='content', action='view', id=3) == '/content/view/3' def test_action_required(): m = Mapper() @@ -60,9 +53,9 @@ def test_action_required(): m.connect('/:controller/index', action='index') m.create_regs(['content']) - eq_(None, m.generate(controller='content')) - eq_(None, m.generate(controller='content', action='fred')) - eq_('/content/index', m.generate(controller='content', action='index')) + assert m.generate(controller='content') is None + assert m.generate(controller='content', action='fred') is None + assert m.generate(controller='content', action='index') == '/content/index' def test_query_params(): m = Mapper() @@ -71,9 +64,8 @@ def test_query_params(): m.connect('/:controller/index', action='index') m.create_regs(['content']) - eq_(None, m.generate(controller='content')) - eq_('/content/index?test=sample', - m.generate(controller='content', action='index', test='sample')) + assert m.generate(controller='content') is None + assert m.generate(controller='content', action='index', test='sample') == '/content/index?test=sample' def test_syntax(): @@ -83,16 +75,15 @@ def test_syntax(): m.create_regs(['content']) # Recognize - eq_(None, m.match('/content')) - eq_(None, m.match('/content/index')) - eq_(None, m.match('/content/index/')) - eq_({'controller':'content','action':'index','id':'4'}, - m.match('/content/index/4')) + assert m.match('/content') is None + assert m.match('/content/index') is None + assert m.match('/content/index/') is None + assert m.match('/content/index/4') == {'controller':'content','action':'index','id':'4'} # Generate - eq_(None, m.generate(controller='content')) - eq_('/content/index/4', m.generate(controller='content', id=4)) - eq_('/content/view/3', m.generate(controller='content', action='view', id=3)) + assert m.generate(controller='content') is None + assert m.generate(controller='content', id=4) == '/content/index/4' + assert m.generate(controller='content', action='view', id=3) == '/content/view/3' def test_regexp_syntax(): m = Mapper(explicit=False) @@ -101,18 +92,17 @@ def test_regexp_syntax(): m.create_regs(['content']) # Recognize - eq_(None, m.match('/content')) - eq_(None, m.match('/content/index')) - eq_(None, m.match('/content/index/')) - eq_(None, m.match('/content/index/3')) - eq_({'controller':'content','action':'index','id':'44'}, - m.match('/content/index/44')) + assert m.match('/content') is None + assert m.match('/content/index') is None + assert m.match('/content/index/') is None + assert m.match('/content/index/3') is None + assert m.match('/content/index/44') == {'controller':'content','action':'index','id':'44'} # Generate - eq_(None, m.generate(controller='content')) - eq_(None, m.generate(controller='content', id=4)) - eq_('/content/index/43', m.generate(controller='content', id=43)) - eq_('/content/view/31', m.generate(controller='content', action='view', id=31)) + assert m.generate(controller='content') is None + assert m.generate(controller='content', id=4) is None + assert m.generate(controller='content', id=43) == '/content/index/43' + assert m.generate(controller='content', action='view', id=31) == '/content/view/31' def test_unicode(): hoge = u'\u30c6\u30b9\u30c8' # the word test in Japanese @@ -120,7 +110,7 @@ def test_unicode(): m = Mapper() m.minimization = False m.connect(':hoge') - eq_("/%s" % hoge_enc, m.generate(hoge=hoge)) + assert m.generate(hoge=hoge) == "/%s" % hoge_enc assert isinstance(m.generate(hoge=hoge), str) def test_unicode_static(): @@ -130,8 +120,7 @@ def test_unicode_static(): m.minimization = False m.connect('google-jp', 'http://www.google.co.jp/search', _static=True) m.create_regs(['messages']) - eq_("http://www.google.co.jp/search?q=" + hoge_enc, - url_for('google-jp', q=hoge)) + assert url_for('google-jp', q=hoge) == "http://www.google.co.jp/search?q=" + hoge_enc assert isinstance(url_for('google-jp', q=hoge), str) def test_other_special_chars(): @@ -140,5 +129,5 @@ def test_other_special_chars(): m.connect('/:year/:(slug).:(format),:(locale)', locale='en', format='html') m.create_regs(['content']) - eq_('/2007/test.xml,ja', m.generate(year=2007, slug='test', format='xml', locale='ja')) - eq_(None, m.generate(year=2007, format='html')) + assert m.generate(year=2007, slug='test', format='xml', locale='ja') == '/2007/test.xml,ja' + assert m.generate(year=2007, format='html') is None diff --git a/tests/test_functional/test_recognition.py b/tests/test_functional/test_recognition.py index 03fe6a7..cf60554 100644 --- a/tests/test_functional/test_recognition.py +++ b/tests/test_functional/test_recognition.py @@ -3,8 +3,8 @@ import sys import time import unittest +import pytest from six.moves import urllib -from nose.tools import eq_, assert_raises from routes import * from routes.util import RoutesException @@ -16,12 +16,12 @@ def test_regexp_char_escaping(self): m.connect(':controller/:(action).:(id)') m.create_regs(['content']) - eq_({'action':'view','controller':'content','id':'2'}, m.match('/content/view.2')) + assert m.match('/content/view.2') == {'action':'view','controller':'content','id':'2'} m.connect(':controller/:action/:id') m.create_regs(['content', 'find.all']) - eq_({'action':'view','controller':'find.all','id':None}, m.match('/find.all/view')) - eq_(None, m.match('/findzall/view')) + assert m.match('/find.all/view') == {'action':'view','controller':'find.all','id':None} + assert m.match('/findzall/view') is None def test_all_static(self): m = Mapper(explicit=False) @@ -29,19 +29,18 @@ def test_all_static(self): m.connect('hello/world/how/are/you', controller='content', action='index') m.create_regs([]) - eq_(None, m.match('/x')) - eq_(None, m.match('/hello/world/how')) - eq_(None, m.match('/hello/world/how/are')) - eq_(None, m.match('/hello/world/how/are/you/today')) - eq_({'controller':'content','action':'index'}, m.match('/hello/world/how/are/you')) + assert m.match('/x') is None + assert m.match('/hello/world/how') is None + assert m.match('/hello/world/how/are') is None + assert m.match('/hello/world/how/are/you/today') is None + assert m.match('/hello/world/how/are/you') == {'controller':'content','action':'index'} def test_unicode(self): hoge = u'\u30c6\u30b9\u30c8' # the word test in Japanese m = Mapper(explicit=False) m.minimization = True m.connect(':hoge') - eq_({'controller': 'content', 'action': 'index', 'hoge': hoge}, - m.match('/' + hoge)) + assert m.match('/' + hoge) == {'controller': 'content', 'action': 'index', 'hoge': hoge} def test_disabling_unicode(self): hoge = u'\u30c6\u30b9\u30c8' # the word test in Japanese @@ -50,8 +49,7 @@ def test_disabling_unicode(self): m.minimization = True m.encoding = None m.connect(':hoge') - eq_({'controller': 'content', 'action': 'index', 'hoge': hoge_enc}, - m.match('/' + hoge_enc)) + assert m.match('/' + hoge_enc) == {'controller': 'content', 'action': 'index', 'hoge': hoge_enc} def test_basic_dynamic(self): for path in ['hi/:name', 'hi/:(name)']: @@ -60,12 +58,12 @@ def test_basic_dynamic(self): m.connect(path, controller='content') m.create_regs([]) - eq_(None, m.match('/boo')) - eq_(None, m.match('/boo/blah')) - eq_(None, m.match('/hi')) - eq_(None, m.match('/hi/dude/what')) - eq_({'controller':'content','name':'dude','action':'index'}, m.match('/hi/dude')) - eq_({'controller':'content','name':'dude','action':'index'}, m.match('/hi/dude/')) + assert m.match('/boo') is None + assert m.match('/boo/blah') is None + assert m.match('/hi') is None + assert m.match('/hi/dude/what') is None + assert m.match('/hi/dude') == {'controller':'content','name':'dude','action':'index'} + assert m.match('/hi/dude/') == {'controller':'content','name':'dude','action':'index'} def test_basic_dynamic_backwards(self): for path in [':name/hi', ':(name)/hi']: @@ -74,13 +72,13 @@ def test_basic_dynamic_backwards(self): m.connect(path) m.create_regs([]) - eq_(None, m.match('/')) - eq_(None, m.match('/hi')) - eq_(None, m.match('/boo')) - eq_(None, m.match('/boo/blah')) - eq_(None, m.match('/shop/wallmart/hi')) - eq_({'name':'fred', 'action':'index', 'controller':'content'}, m.match('/fred/hi')) - eq_({'name':'index', 'action':'index', 'controller':'content'}, m.match('/index/hi')) + assert m.match('/') is None + assert m.match('/hi') is None + assert m.match('/boo') is None + assert m.match('/boo/blah') is None + assert m.match('/shop/wallmart/hi') is None + assert m.match('/fred/hi') == {'name':'fred','action':'index', 'controller':'content'} + assert m.match('/index/hi') == {'name':'index','action':'index', 'controller':'content'} def test_dynamic_with_underscores(self): m = Mapper(explicit=False) @@ -89,8 +87,8 @@ def test_dynamic_with_underscores(self): m.connect(':(controller)/:(action)/:(id)') m.create_regs(['article', 'blog']) - eq_({'controller':'blog','action':'view','id':'0'}, m.match('/blog/view/0')) - eq_({'controller':'blog','action':'view','id':None}, m.match('/blog/view')) + assert m.match('/blog/view/0') == {'controller':'blog','action':'view','id':'0'} + assert m.match('/blog/view') == {'controller':'blog','action':'view','id':None} def test_dynamic_with_default(self): for path in ['hi/:action', 'hi/:(action)']: @@ -99,12 +97,12 @@ def test_dynamic_with_default(self): m.connect(path, controller='content') m.create_regs([]) - eq_(None, m.match('/boo')) - eq_(None, m.match('/boo/blah')) - eq_(None, m.match('/hi/dude/what')) - eq_({'controller':'content','action':'index'}, m.match('/hi')) - eq_({'controller':'content','action':'index'}, m.match('/hi/index')) - eq_({'controller':'content','action':'dude'}, m.match('/hi/dude')) + assert m.match('/boo') is None + assert m.match('/boo/blah') is None + assert m.match('/hi/dude/what') is None + assert m.match('/hi') == {'controller':'content','action':'index'} + assert m.match('/hi/index') == {'controller':'content','action':'index'} + assert m.match('/hi/dude') == {'controller':'content','action':'dude'} def test_dynamic_with_default_backwards(self): for path in [':action/hi', ':(action)/hi']: @@ -113,13 +111,13 @@ def test_dynamic_with_default_backwards(self): m.connect(path, controller='content') m.create_regs([]) - eq_(None, m.match('/')) - eq_(None, m.match('/boo')) - eq_(None, m.match('/boo/blah')) - eq_(None, m.match('/hi')) - eq_({'controller':'content','action':'index'}, m.match('/index/hi')) - eq_({'controller':'content','action':'index'}, m.match('/index/hi/')) - eq_({'controller':'content','action':'dude'}, m.match('/dude/hi')) + assert m.match('/') is None + assert m.match('/boo') is None + assert m.match('/boo/blah') is None + assert m.match('/hi') is None + assert m.match('/index/hi') == {'controller':'content','action':'index'} + assert m.match('/index/hi/') == {'controller':'content','action':'index'} + assert m.match('/dude/hi') == {'controller':'content','action':'dude'} def test_dynamic_with_string_condition(self): for path in [':name/hi', ':(name)/hi']: @@ -128,12 +126,12 @@ def test_dynamic_with_string_condition(self): m.connect(path, controller='content', requirements={'name':'index'}) m.create_regs([]) - eq_(None, m.match('/boo')) - eq_(None, m.match('/boo/blah')) - eq_(None, m.match('/hi')) - eq_(None, m.match('/dude/what/hi')) - eq_({'controller':'content','name':'index','action':'index'}, m.match('/index/hi')) - eq_(None, m.match('/dude/hi')) + assert m.match('/boo') is None + assert m.match('/boo/blah') is None + assert m.match('/hi') is None + assert m.match('/dude/what/hi') is None + assert m.match('/index/hi') == {'controller':'content','name':'index','action':'index'} + assert m.match('/dude/hi') is None def test_dynamic_with_string_condition_backwards(self): for path in ['hi/:name', 'hi/:(name)']: @@ -142,12 +140,12 @@ def test_dynamic_with_string_condition_backwards(self): m.connect(path, controller='content', requirements={'name':'index'}) m.create_regs([]) - eq_(None, m.match('/boo')) - eq_(None, m.match('/boo/blah')) - eq_(None, m.match('/hi')) - eq_(None, m.match('/hi/dude/what')) - eq_({'controller':'content','name':'index','action':'index'}, m.match('/hi/index')) - eq_(None, m.match('/hi/dude')) + assert m.match('/boo') is None + assert m.match('/boo/blah') is None + assert m.match('/hi') is None + assert m.match('/hi/dude/what') is None + assert m.match('/hi/index') == {'controller':'content','name':'index','action':'index'} + assert m.match('/hi/dude') is None def test_dynamic_with_regexp_condition(self): for path in ['hi/:name', 'hi/:(name)']: @@ -156,16 +154,16 @@ def test_dynamic_with_regexp_condition(self): m.connect(path, controller='content', requirements={'name':'[a-z]+'}) m.create_regs([]) - eq_(None, m.match('/boo')) - eq_(None, m.match('/boo/blah')) - eq_(None, m.match('/hi')) - eq_(None, m.match('/hi/FOXY')) - eq_(None, m.match('/hi/138708jkhdf')) - eq_(None, m.match('/hi/dkjfl8792343dfsf')) - eq_(None, m.match('/hi/dude/what')) - eq_(None, m.match('/hi/dude/what/')) - eq_({'controller':'content','name':'index','action':'index'}, m.match('/hi/index')) - eq_({'controller':'content','name':'dude','action':'index'}, m.match('/hi/dude')) + assert m.match('/boo') is None + assert m.match('/boo/blah') is None + assert m.match('/hi') is None + assert m.match('/hi/FOXY') is None + assert m.match('/hi/138708jkhdf') is None + assert m.match('/hi/dkjfl8792343dfsf') is None + assert m.match('/hi/dude/what') is None + assert m.match('/hi/dude/what/') is None + assert m.match('/hi/index') == {'controller':'content','name':'index','action':'index'} + assert m.match('/hi/dude') == {'controller':'content','name':'dude','action':'index'} def test_dynamic_with_regexp_and_default(self): for path in ['hi/:action', 'hi/:(action)']: @@ -174,15 +172,15 @@ def test_dynamic_with_regexp_and_default(self): m.connect(path, controller='content', requirements={'action':'[a-z]+'}) m.create_regs([]) - eq_(None, m.match('/boo')) - eq_(None, m.match('/boo/blah')) - eq_(None, m.match('/hi/FOXY')) - eq_(None, m.match('/hi/138708jkhdf')) - eq_(None, m.match('/hi/dkjfl8792343dfsf')) - eq_(None, m.match('/hi/dude/what/')) - eq_({'controller':'content','action':'index'}, m.match('/hi')) - eq_({'controller':'content','action':'index'}, m.match('/hi/index')) - eq_({'controller':'content','action':'dude'}, m.match('/hi/dude')) + assert m.match('/boo') is None + assert m.match('/boo/blah') is None + assert m.match('/hi/FOXY') is None + assert m.match('/hi/138708jkhdf') is None + assert m.match('/hi/dkjfl8792343dfsf') is None + assert m.match('/hi/dude/what/') is None + assert m.match('/hi') == {'controller':'content','action':'index'} + assert m.match('/hi/index') == {'controller':'content','action':'index'} + assert m.match('/hi/dude') == {'controller':'content','action':'dude'} def test_dynamic_with_default_and_string_condition_backwards(self): for path in [':action/hi', ':(action)/hi']: @@ -191,11 +189,11 @@ def test_dynamic_with_default_and_string_condition_backwards(self): m.connect(path) m.create_regs([]) - eq_(None, m.match('/')) - eq_(None, m.match('/boo')) - eq_(None, m.match('/boo/blah')) - eq_(None, m.match('/hi')) - eq_({'action':'index', 'controller':'content'}, m.match('/index/hi')) + assert m.match('/') is None + assert m.match('/boo') is None + assert m.match('/boo/blah') is None + assert m.match('/hi') is None + assert m.match('/index/hi') == {'action':'index', 'controller':'content'} def test_dynamic_and_controller_with_string_and_default_backwards(self): for path in [':controller/:action/hi', ':(controller)/:(action)/hi']: @@ -203,8 +201,8 @@ def test_dynamic_and_controller_with_string_and_default_backwards(self): m.connect(path, controller='content') m.create_regs(['content','admin/user']) - eq_(None, m.match('/')) - eq_(None, m.match('/fred')) + assert m.match('/') is None + assert m.match('/fred') is None def test_multiroute(self): @@ -216,14 +214,12 @@ def test_multiroute(self): m.connect(':controller/:action/:id') m.create_regs(['post','blog','admin/user']) - eq_(None, m.match('/')) - eq_(None, m.match('/archive')) - eq_(None, m.match('/archive/2004/ab')) - eq_({'controller':'blog','action':'view','id':None}, m.match('/blog/view')) - eq_({'controller':'blog','action':'view','month':None,'day':None,'year':'2004'}, - m.match('/archive/2004')) - eq_({'controller':'blog','action':'view', 'month':'4', 'day':None,'year':'2004'}, - m.match('/archive/2004/4')) + assert m.match('/') is None + assert m.match('/archive') is None + assert m.match('/archive/2004/ab') is None + assert m.match('/blog/view') == {'controller':'blog','action':'view','id':None} + assert m.match('/archive/2004') == {'controller':'blog','action':'view','month':None,'day':None,'year':'2004'} + assert m.match('/archive/2004/4') == {'controller':'blog','action':'view', 'month':'4', 'day':None,'year':'2004'} def test_multiroute_with_nomin(self): m = Mapper() @@ -234,14 +230,13 @@ def test_multiroute_with_nomin(self): m.connect('/:controller/:action/:id') m.create_regs(['post','blog','admin/user']) - eq_(None, m.match('/')) - eq_(None, m.match('/archive')) - eq_(None, m.match('/archive/2004/ab')) - eq_(None, m.match('/archive/2004/4')) - eq_(None, m.match('/archive/2004')) - eq_({'controller':'blog','action':'view','id':'3'}, m.match('/blog/view/3')) - eq_({'controller':'blog','action':'view','month':'10','day':'23','year':'2004'}, - m.match('/archive/2004/10/23')) + assert m.match('/') is None + assert m.match('/archive') is None + assert m.match('/archive/2004/ab') is None + assert m.match('/archive/2004/4') is None + assert m.match('/archive/2004') is None + assert m.match('/blog/view/3') == {'controller':'blog','action':'view','id':'3'} + assert m.match('/archive/2004/10/23') == {'controller':'blog','action':'view','month':'10','day':'23','year':'2004'} def test_multiroute_with_splits(self): m = Mapper(explicit=False) @@ -252,14 +247,12 @@ def test_multiroute_with_splits(self): m.connect(':(controller)/:(action)/:(id)') m.create_regs(['post','blog','admin/user']) - eq_(None, m.match('/')) - eq_(None, m.match('/archive')) - eq_(None, m.match('/archive/2004/ab')) - eq_({'controller':'blog','action':'view','id':None}, m.match('/blog/view')) - eq_({'controller':'blog','action':'view','month':None,'day':None,'year':'2004'}, - m.match('/archive/2004')) - eq_({'controller':'blog','action':'view', 'month':'4', 'day':None,'year':'2004'}, - m.match('/archive/2004/4')) + assert m.match('/') is None + assert m.match('/archive') is None + assert m.match('/archive/2004/ab') is None + assert m.match('/blog/view') == {'controller':'blog','action':'view','id':None} + assert m.match('/archive/2004') == {'controller':'blog','action':'view','month':None,'day':None,'year':'2004'} + assert m.match('/archive/2004/4') == {'controller':'blog','action':'view', 'month':'4', 'day':None,'year':'2004'} def test_dynamic_with_regexp_defaults_and_gaps(self): m = Mapper() @@ -269,12 +262,12 @@ def test_dynamic_with_regexp_defaults_and_gaps(self): m.connect('view/:id/:controller', controller='blog', id=2, action='view', requirements={'id':'\d{1,2}'}) m.create_regs(['post','blog','admin/user']) - eq_(None, m.match('/')) - eq_(None, m.match('/archive')) - eq_(None, m.match('/archive/2004/haha')) - eq_(None, m.match('/view/blog')) - eq_({'controller':'blog', 'action':'view', 'id':'2'}, m.match('/view')) - eq_({'controller':'blog','action':'view','month':None,'day':None,'year':'2004'}, m.match('/archive/2004')) + assert m.match('/') is None + assert m.match('/archive') is None + assert m.match('/archive/2004/haha') is None + assert m.match('/view/blog') is None + assert m.match('/view') == {'controller':'blog', 'action':'view', 'id':'2'} + assert m.match('/archive/2004') == {'controller':'blog','action':'view','month':None,'day':None,'year':'2004'} def test_dynamic_with_regexp_defaults_and_gaps_and_splits(self): m = Mapper() @@ -284,12 +277,12 @@ def test_dynamic_with_regexp_defaults_and_gaps_and_splits(self): m.connect('view/:(id)/:(controller)', controller='blog', id=2, action='view', requirements={'id':'\d{1,2}'}) m.create_regs(['post','blog','admin/user']) - eq_(None, m.match('/')) - eq_(None, m.match('/archive')) - eq_(None, m.match('/archive/2004/haha')) - eq_(None, m.match('/view/blog')) - eq_({'controller':'blog', 'action':'view', 'id':'2'}, m.match('/view')) - eq_({'controller':'blog','action':'view','month':None,'day':None,'year':'2004'}, m.match('/archive/2004')) + assert m.match('/') is None + assert m.match('/archive') is None + assert m.match('/archive/2004/haha') is None + assert m.match('/view/blog') is None + assert m.match('/view') == {'controller':'blog', 'action':'view', 'id':'2'} + assert m.match('/archive/2004') == {'controller':'blog','action':'view','month':None,'day':None,'year':'2004'} def test_dynamic_with_regexp_gaps_controllers(self): for path in ['view/:id/:controller', 'view/:(id)/:(controller)']: @@ -298,12 +291,12 @@ def test_dynamic_with_regexp_gaps_controllers(self): m.connect(path, id=2, action='view', requirements={'id':'\d{1,2}'}) m.create_regs(['post','blog','admin/user']) - eq_(None, m.match('/')) - eq_(None, m.match('/view')) - eq_(None, m.match('/view/blog')) - eq_(None, m.match('/view/3')) - eq_(None, m.match('/view/4/honker')) - eq_({'controller':'blog','action':'view','id':'2'}, m.match('/view/2/blog')) + assert m.match('/') is None + assert m.match('/view') is None + assert m.match('/view/blog') is None + assert m.match('/view/3') is None + assert m.match('/view/4/honker') is None + assert m.match('/view/2/blog') == {'controller':'blog','action':'view','id':'2'} def test_dynamic_with_trailing_strings(self): for path in ['view/:id/:controller/super', 'view/:(id)/:(controller)/super']: @@ -312,14 +305,14 @@ def test_dynamic_with_trailing_strings(self): m.connect(path, controller='blog', id=2, action='view', requirements={'id':'\d{1,2}'}) m.create_regs(['post','blog','admin/user']) - eq_(None, m.match('/')) - eq_(None, m.match('/view')) - eq_(None, m.match('/view/blah/blog/super')) - eq_(None, m.match('/view/ha/super')) - eq_(None, m.match('/view/super')) - eq_(None, m.match('/view/4/super')) - eq_({'controller':'blog','action':'view','id':'2'}, m.match('/view/2/blog/super')) - eq_({'controller':'admin/user','action':'view','id':'4'}, m.match('/view/4/admin/user/super')) + assert m.match('/') is None + assert m.match('/view') is None + assert m.match('/view/blah/blog/super') is None + assert m.match('/view/ha/super') is None + assert m.match('/view/super') is None + assert m.match('/view/4/super') is None + assert m.match('/view/2/blog/super') == {'controller':'blog','action':'view','id':'2'} + assert m.match('/view/4/admin/user/super') == {'controller':'admin/user','action':'view','id':'4'} def test_dynamic_with_trailing_non_keyword_strings(self): m = Mapper(explicit=False) @@ -328,10 +321,10 @@ def test_dynamic_with_trailing_non_keyword_strings(self): m.connect('somewhere/:over', controller='post') m.create_regs(['post','blog','admin/user']) - eq_(None, m.match('/')) - eq_(None, m.match('/somewhere')) - eq_({'controller':'blog','action':'index','over':'near'}, m.match('/somewhere/near/rainbow')) - eq_({'controller':'post','action':'index','over':'tomorrow'}, m.match('/somewhere/tomorrow')) + assert m.match('/') is None + assert m.match('/somewhere') is None + assert m.match('/somewhere/near/rainbow') == {'controller':'blog','action':'index','over':'near'} + assert m.match('/somewhere/tomorrow') == {'controller':'post','action':'index','over':'tomorrow'} def test_dynamic_with_trailing_dyanmic_defaults(self): for path in ['archives/:action/:article', 'archives/:(action)/:(article)']: @@ -340,16 +333,14 @@ def test_dynamic_with_trailing_dyanmic_defaults(self): m.connect(path, controller='blog') m.create_regs(['blog']) - eq_(None, m.match('/')) - eq_(None, m.match('/archives')) - eq_(None, m.match('/archives/introduction')) - eq_(None, m.match('/archives/sample')) - eq_(None, m.match('/view/super')) - eq_(None, m.match('/view/4/super')) - eq_({'controller':'blog','action':'view','article':'introduction'}, - m.match('/archives/view/introduction')) - eq_({'controller':'blog','action':'edit','article':'recipes'}, - m.match('/archives/edit/recipes')) + assert m.match('/') is None + assert m.match('/archives') is None + assert m.match('/archives/introduction') is None + assert m.match('/archives/sample') is None + assert m.match('/view/super') is None + assert m.match('/view/4/super') is None + assert m.match('/archives/view/introduction') == {'controller':'blog','action':'view','article':'introduction'} + assert m.match('/archives/edit/recipes') == {'controller':'blog','action':'edit','article':'recipes'} def test_path(self): for path in ['hi/*file', 'hi/*(file)']: @@ -358,12 +349,12 @@ def test_path(self): m.connect(path, controller='content', action='download') m.create_regs([]) - eq_(None, m.match('/boo')) - eq_(None, m.match('/boo/blah')) - eq_(None, m.match('/hi')) - eq_({'controller':'content','action':'download','file':'books/learning_python.pdf'}, m.match('/hi/books/learning_python.pdf')) - eq_({'controller':'content','action':'download','file':'dude'}, m.match('/hi/dude')) - eq_({'controller':'content','action':'download','file':'dude/what'}, m.match('/hi/dude/what')) + assert m.match('/boo') is None + assert m.match('/boo/blah') is None + assert m.match('/hi') is None + assert m.match('/hi/books/learning_python.pdf') == {'controller':'content','action':'download','file':'books/learning_python.pdf'} + assert m.match('/hi/dude') == {'controller':'content','action':'download','file':'dude'} + assert m.match('/hi/dude/what') == {'controller':'content','action':'download','file':'dude/what'} def test_path_with_dynamic(self): for path in [':controller/:action/*url', ':(controller)/:(action)/*(url)']: @@ -372,14 +363,14 @@ def test_path_with_dynamic(self): m.connect(path) m.create_regs(['content','admin/user']) - eq_(None, m.match('/')) - eq_(None, m.match('/blog')) - eq_(None, m.match('/content')) - eq_(None, m.match('/content/view')) - eq_({'controller':'content','action':'view','url':'blob'}, m.match('/content/view/blob')) - eq_(None, m.match('/admin/user')) - eq_(None, m.match('/admin/user/view')) - eq_({'controller':'admin/user','action':'view','url':'blob/check'}, m.match('/admin/user/view/blob/check')) + assert m.match('/') is None + assert m.match('/blog') is None + assert m.match('/content') is None + assert m.match('/content/view') is None + assert m.match('/content/view/blob') == {'controller':'content','action':'view','url':'blob'} + assert m.match('/admin/user') is None + assert m.match('/admin/user/view') is None + assert m.match('/admin/user/view/blob/check') == {'controller':'admin/user','action':'view','url':'blob/check'} def test_path_with_dyanmic_and_default(self): @@ -389,14 +380,14 @@ def test_path_with_dyanmic_and_default(self): m.connect(path, controller='content', action='view', url=None) m.create_regs(['content','admin/user']) - eq_(None, m.match('/goober/view/here')) - eq_({'controller':'content','action':'view','url':None}, m.match('/')) - eq_({'controller':'content','action':'view','url':None}, m.match('/content')) - eq_({'controller':'content','action':'view','url':None}, m.match('/content/')) - eq_({'controller':'content','action':'view','url':None}, m.match('/content/view')) - eq_({'controller':'content','action':'view','url':'fred'}, m.match('/content/view/fred')) - eq_({'controller':'admin/user','action':'view','url':None}, m.match('/admin/user')) - eq_({'controller':'admin/user','action':'view','url':None}, m.match('/admin/user/view')) + assert m.match('/goober/view/here') is None + assert m.match('/') == {'controller':'content','action':'view','url':None} + assert m.match('/content') == {'controller':'content','action':'view','url':None} + assert m.match('/content/') == {'controller':'content','action':'view','url':None} + assert m.match('/content/view') == {'controller':'content','action':'view','url':None} + assert m.match('/content/view/fred') == {'controller':'content','action':'view','url':'fred'} + assert m.match('/admin/user') == {'controller':'admin/user','action':'view','url':None} + assert m.match('/admin/user/view') == {'controller':'admin/user','action':'view','url':None} def test_path_with_dynamic_and_default_backwards(self): for path in ['*file/login', '*(file)/login']: @@ -405,12 +396,12 @@ def test_path_with_dynamic_and_default_backwards(self): m.connect(path, controller='content', action='download', file=None) m.create_regs([]) - eq_(None, m.match('/boo')) - eq_(None, m.match('/boo/blah')) - eq_({'controller':'content','action':'download','file':''}, m.match('//login')) - eq_({'controller':'content','action':'download','file':'books/learning_python.pdf'}, m.match('/books/learning_python.pdf/login')) - eq_({'controller':'content','action':'download','file':'dude'}, m.match('/dude/login')) - eq_({'controller':'content','action':'download','file':'dude/what'}, m.match('/dude/what/login')) + assert m.match('/boo') is None + assert m.match('/boo/blah') is None + assert m.match('//login') == {'controller':'content','action':'download','file':''} + assert m.match('/books/learning_python.pdf/login') == {'controller':'content','action':'download','file':'books/learning_python.pdf'} + assert m.match('/dude/login') == {'controller':'content','action':'download','file':'dude'} + assert m.match('/dude/what/login') == {'controller':'content','action':'download','file':'dude/what'} def test_path_backwards(self): for path in ['*file/login', '*(file)/login']: @@ -419,12 +410,12 @@ def test_path_backwards(self): m.connect(path, controller='content', action='download') m.create_regs([]) - eq_(None, m.match('/boo')) - eq_(None, m.match('/boo/blah')) - eq_(None, m.match('/login')) - eq_({'controller':'content','action':'download','file':'books/learning_python.pdf'}, m.match('/books/learning_python.pdf/login')) - eq_({'controller':'content','action':'download','file':'dude'}, m.match('/dude/login')) - eq_({'controller':'content','action':'download','file':'dude/what'}, m.match('/dude/what/login')) + assert m.match('/boo') is None + assert m.match('/boo/blah') is None + assert m.match('/login') is None + assert m.match('/books/learning_python.pdf/login') == {'controller':'content','action':'download','file':'books/learning_python.pdf'} + assert m.match('/dude/login') == {'controller':'content','action':'download','file':'dude'} + assert m.match('/dude/what/login') == {'controller':'content','action':'download','file':'dude/what'} def test_path_backwards_with_controller(self): m = Mapper() @@ -433,17 +424,17 @@ def test_path_backwards_with_controller(self): m.connect('*url/:controller', action='view') m.create_regs(['content', 'admin/user']) - eq_(None, m.match('/boo')) - eq_(None, m.match('/boo/blah')) - eq_(None, m.match('/login')) - eq_({'controller':'content','action':'check_access','url':'books/learning_python.pdf'}, m.match('/books/learning_python.pdf/login')) - eq_({'controller':'content','action':'check_access','url':'dude'}, m.match('/dude/login')) - eq_({'controller':'content','action':'check_access','url':'dude/what'}, m.match('/dude/what/login')) + assert m.match('/boo') is None + assert m.match('/boo/blah') is None + assert m.match('/login') is None + assert m.match('/books/learning_python.pdf/login') == {'controller':'content','action':'check_access','url':'books/learning_python.pdf'} + assert m.match('/dude/login') == {'controller':'content','action':'check_access','url':'dude'} + assert m.match('/dude/what/login') == {'controller':'content','action':'check_access','url':'dude/what'} - eq_(None, m.match('/admin/user')) - eq_({'controller':'admin/user','action':'view','url':'books/learning_python.pdf'}, m.match('/books/learning_python.pdf/admin/user')) - eq_({'controller':'admin/user','action':'view','url':'dude'}, m.match('/dude/admin/user')) - eq_({'controller':'admin/user','action':'view','url':'dude/what'}, m.match('/dude/what/admin/user')) + assert m.match('/admin/user') is None + assert m.match('/books/learning_python.pdf/admin/user') == {'controller':'admin/user','action':'view','url':'books/learning_python.pdf'} + assert m.match('/dude/admin/user') == {'controller':'admin/user','action':'view','url':'dude'} + assert m.match('/dude/what/admin/user') == {'controller':'admin/user','action':'view','url':'dude/what'} def test_path_backwards_with_controller_and_splits(self): m = Mapper() @@ -452,17 +443,17 @@ def test_path_backwards_with_controller_and_splits(self): m.connect('*(url)/:(controller)', action='view') m.create_regs(['content', 'admin/user']) - eq_(None, m.match('/boo')) - eq_(None, m.match('/boo/blah')) - eq_(None, m.match('/login')) - eq_({'controller':'content','action':'check_access','url':'books/learning_python.pdf'}, m.match('/books/learning_python.pdf/login')) - eq_({'controller':'content','action':'check_access','url':'dude'}, m.match('/dude/login')) - eq_({'controller':'content','action':'check_access','url':'dude/what'}, m.match('/dude/what/login')) + assert m.match('/boo') is None + assert m.match('/boo/blah') is None + assert m.match('/login') is None + assert m.match('/books/learning_python.pdf/login') == {'controller':'content','action':'check_access','url':'books/learning_python.pdf'} + assert m.match('/dude/login') == {'controller':'content','action':'check_access','url':'dude'} + assert m.match('/dude/what/login') == {'controller':'content','action':'check_access','url':'dude/what'} - eq_(None, m.match('/admin/user')) - eq_({'controller':'admin/user','action':'view','url':'books/learning_python.pdf'}, m.match('/books/learning_python.pdf/admin/user')) - eq_({'controller':'admin/user','action':'view','url':'dude'}, m.match('/dude/admin/user')) - eq_({'controller':'admin/user','action':'view','url':'dude/what'}, m.match('/dude/what/admin/user')) + assert m.match('/admin/user') is None + assert m.match('/books/learning_python.pdf/admin/user') == {'controller':'admin/user','action':'view','url':'books/learning_python.pdf'} + assert m.match('/dude/admin/user') == {'controller':'admin/user','action':'view','url':'dude'} + assert m.match('/dude/what/admin/user') == {'controller':'admin/user','action':'view','url':'dude/what'} def test_controller(self): m = Mapper() @@ -470,14 +461,14 @@ def test_controller(self): m.connect('hi/:controller', action='hi') m.create_regs(['content','admin/user']) - eq_(None, m.match('/boo')) - eq_(None, m.match('/boo/blah')) - eq_(None, m.match('/hi/13870948')) - eq_(None, m.match('/hi/content/dog')) - eq_(None, m.match('/hi/admin/user/foo')) - eq_(None, m.match('/hi/admin/user/foo/')) - eq_({'controller':'content','action':'hi'}, m.match('/hi/content')) - eq_({'controller':'admin/user', 'action':'hi'}, m.match('/hi/admin/user')) + assert m.match('/boo') is None + assert m.match('/boo/blah') is None + assert m.match('/hi/13870948') is None + assert m.match('/hi/content/dog') is None + assert m.match('/hi/admin/user/foo') is None + assert m.match('/hi/admin/user/foo/') is None + assert m.match('/hi/content') == {'controller': 'content', 'action': 'hi'} + assert m.match('/hi/admin/user') == {'controller': 'admin/user', 'action': 'hi'} def test_standard_route(self): m = Mapper(explicit=False) @@ -485,16 +476,16 @@ def test_standard_route(self): m.connect(':controller/:action/:id') m.create_regs(['content','admin/user']) - eq_({'controller':'content','action':'index', 'id': None}, m.match('/content')) - eq_({'controller':'content','action':'list', 'id':None}, m.match('/content/list')) - eq_({'controller':'content','action':'show','id':'10'}, m.match('/content/show/10')) + assert m.match('/content') == {'controller':'content','action':'index', 'id': None} + assert m.match('/content/list') == {'controller':'content','action':'list', 'id':None} + assert m.match('/content/show/10') == {'controller':'content','action':'show','id':'10'} - eq_({'controller':'admin/user','action':'index', 'id': None}, m.match('/admin/user')) - eq_({'controller':'admin/user','action':'list', 'id':None}, m.match('/admin/user/list')) - eq_({'controller':'admin/user','action':'show','id':'bbangert'}, m.match('/admin/user/show/bbangert')) + assert m.match('/admin/user') == {'controller':'admin/user','action':'index', 'id': None} + assert m.match('/admin/user/list') == {'controller':'admin/user','action':'list', 'id':None} + assert m.match('/admin/user/show/bbangert') == {'controller':'admin/user','action':'show','id':'bbangert'} - eq_(None, m.match('/content/show/10/20')) - eq_(None, m.match('/food')) + assert m.match('/content/show/10/20') is None + assert m.match('/food') is None def test_standard_route_with_gaps(self): m = Mapper() @@ -502,9 +493,9 @@ def test_standard_route_with_gaps(self): m.connect(':controller/:action/:(id).py') m.create_regs(['content','admin/user']) - eq_({'controller':'content','action':'index', 'id': 'None'}, m.match('/content/index/None.py')) - eq_({'controller':'content','action':'list', 'id':'None'}, m.match('/content/list/None.py')) - eq_({'controller':'content','action':'show','id':'10'}, m.match('/content/show/10.py')) + assert m.match('/content/index/None.py') == {'controller':'content','action':'index', 'id': 'None'} + assert m.match('/content/list/None.py') == {'controller':'content','action':'list', 'id':'None'} + assert m.match('/content/show/10.py') == {'controller':'content','action':'show','id':'10'} def test_standard_route_with_gaps_and_domains(self): m = Mapper() @@ -513,14 +504,14 @@ def test_standard_route_with_gaps_and_domains(self): m.connect(':controller/:action/:id') m.create_regs(['content','admin/user']) - eq_({'controller':'content','action':'index', 'id': 'None.py'}, m.match('/content/index/None.py')) - eq_({'controller':'content','action':'list', 'id':'None.py'}, m.match('/content/list/None.py')) - eq_({'controller':'content','action':'show','id':'10.py'}, m.match('/content/show/10.py')) - eq_({'controller':'content','action':'show.all','id':'10.py'}, m.match('/content/show.all/10.py')) - eq_({'controller':'content','action':'show','id':'www.groovie.org'}, m.match('/content/show/www.groovie.org')) + assert m.match('/content/index/None.py') == {'controller':'content','action':'index', 'id': 'None.py'} + assert m.match('/content/list/None.py') == {'controller':'content','action':'list', 'id':'None.py'} + assert m.match('/content/show/10.py') == {'controller':'content','action':'show','id':'10.py'} + assert m.match('/content/show.all/10.py') == {'controller':'content','action':'show.all','id':'10.py'} + assert m.match('/content/show/www.groovie.org') == {'controller':'content','action':'show','id':'www.groovie.org'} - eq_({'controller':'admin/user','action':'view', 'ext': 'html', 'domain': 'groovie'}, m.match('/manage/groovie')) - eq_({'controller':'admin/user','action':'view', 'ext': 'xml', 'domain': 'groovie'}, m.match('/manage/groovie.xml')) + assert m.match('/manage/groovie') == {'controller':'admin/user','action':'view', 'ext': 'html', 'domain': 'groovie'} + assert m.match('/manage/groovie.xml') == {'controller':'admin/user','action':'view', 'ext': 'xml', 'domain': 'groovie'} def test_standard_with_domains(self): m = Mapper() @@ -528,7 +519,7 @@ def test_standard_with_domains(self): m.connect('manage/:domain', controller='domains', action='view') m.create_regs(['domains']) - eq_({'controller':'domains','action':'view','domain':'www.groovie.org'}, m.match('/manage/www.groovie.org')) + assert m.match('/manage/www.groovie.org') == {'controller':'domains','action':'view','domain':'www.groovie.org'} def test_default_route(self): m = Mapper() @@ -536,12 +527,12 @@ def test_default_route(self): m.connect('',controller='content',action='index') m.create_regs(['content']) - eq_(None, m.match('/x')) - eq_(None, m.match('/hello/world')) - eq_(None, m.match('/hello/world/how/are')) - eq_(None, m.match('/hello/world/how/are/you/today')) + assert m.match('/x') is None + assert m.match('/hello/world') is None + assert m.match('/hello/world/how/are') is None + assert m.match('/hello/world/how/are/you/today') is None - eq_({'controller':'content','action':'index'}, m.match('/')) + assert m.match('/') == {'controller':'content','action':'index'} def test_dynamic_with_prefix(self): m = Mapper(explicit=False) @@ -551,16 +542,16 @@ def test_dynamic_with_prefix(self): m.connect('', controller='content', action='index') m.create_regs(['content', 'archive', 'admin/comments']) - eq_(None, m.match('/x')) - eq_(None, m.match('/admin/comments')) - eq_(None, m.match('/content/view')) - eq_(None, m.match('/archive/view/4')) + assert m.match('/x') is None + assert m.match('/admin/comments') is None + assert m.match('/content/view') is None + assert m.match('/archive/view/4') is None - eq_({'controller':'content','action':'index'}, m.match('/blog')) - eq_({'controller':'content','action':'index','id':None}, m.match('/blog/content')) - eq_({'controller':'admin/comments','action':'view','id':None}, m.match('/blog/admin/comments/view')) - eq_({'controller':'archive','action':'index','id':None}, m.match('/blog/archive')) - eq_({'controller':'archive','action':'view', 'id':'4'}, m.match('/blog/archive/view/4')) + assert m.match('/blog') == {'controller':'content','action':'index'} + assert m.match('/blog/content') == {'controller':'content','action':'index','id':None} + assert m.match('/blog/admin/comments/view') == {'controller':'admin/comments','action':'view','id':None} + assert m.match('/blog/archive') == {'controller':'archive','action':'index','id':None} + assert m.match('/blog/archive/view/4') == {'controller':'archive','action':'view', 'id':'4'} def test_dynamic_with_multiple_and_prefix(self): m = Mapper(explicit=False) @@ -571,17 +562,17 @@ def test_dynamic_with_multiple_and_prefix(self): m.connect('', controller='content') m.create_regs(['content', 'archive', 'admin/comments']) - eq_(None, m.match('/x')) - eq_(None, m.match('/admin/comments')) - eq_(None, m.match('/content/view')) - eq_(None, m.match('/archive/view/4')) + assert m.match('/x') is None + assert m.match('/admin/comments') is None + assert m.match('/content/view') is None + assert m.match('/archive/view/4') is None - eq_({'controller':'content', 'action':'index'}, m.match('/blog/')) - eq_({'controller':'archive', 'action':'view'}, m.match('/blog/home/view')) - eq_({'controller':'content','action':'index','id':None}, m.match('/blog/content')) - eq_({'controller':'admin/comments','action':'view','id':None}, m.match('/blog/admin/comments/view')) - eq_({'controller':'archive','action':'index','id':None}, m.match('/blog/archive')) - eq_({'controller':'archive','action':'view', 'id':'4'}, m.match('/blog/archive/view/4')) + assert m.match('/blog/') == {'controller': 'content', 'action': 'index'} + assert m.match('/blog/home/view') == {'controller': 'archive', 'action': 'view'} + assert m.match('/blog/content') == {'controller': 'content', 'action': 'index', 'id':None} + assert m.match('/blog/admin/comments/view') == {'controller': 'admin/comments', 'action': 'view', 'id':None} + assert m.match('/blog/archive') == {'controller': 'archive', 'action': 'index', 'id':None} + assert m.match('/blog/archive/view/4') == {'controller': 'archive', 'action': 'view', 'id': '4'} def test_splits_with_extension(self): @@ -590,12 +581,12 @@ def test_splits_with_extension(self): m.connect('hi/:(action).html', controller='content') m.create_regs([]) - eq_(None, m.match('/boo')) - eq_(None, m.match('/boo/blah')) - eq_(None, m.match('/hi/dude/what')) - eq_(None, m.match('/hi')) - eq_({'controller':'content','action':'index'}, m.match('/hi/index.html')) - eq_({'controller':'content','action':'dude'}, m.match('/hi/dude.html')) + assert m.match('/boo') is None + assert m.match('/boo/blah') is None + assert m.match('/hi/dude/what') is None + assert m.match('/hi') is None + assert m.match('/hi/index.html') == {'controller':'content','action':'index'} + assert m.match('/hi/dude.html') == {'controller':'content','action':'dude'} def test_splits_with_dashes(self): m = Mapper() @@ -603,15 +594,12 @@ def test_splits_with_dashes(self): m.connect('archives/:(year)-:(month)-:(day).html', controller='archives', action='view') m.create_regs([]) - eq_(None, m.match('/boo')) - eq_(None, m.match('/archives')) + assert m.match('/boo') is None + assert m.match('/archives') is None - eq_({'controller':'archives','action':'view','year':'2004','month':'12','day':'4'}, - m.match('/archives/2004-12-4.html')) - eq_({'controller':'archives','action':'view','year':'04','month':'10','day':'4'}, - m.match('/archives/04-10-4.html')) - eq_({'controller':'archives','action':'view','year':'04','month':'1','day':'1'}, - m.match('/archives/04-1-1.html')) + assert m.match('/archives/2004-12-4.html') == {'controller':'archives','action':'view','year':'2004','month':'12','day':'4'} + assert m.match('/archives/04-10-4.html') == {'controller':'archives','action':'view','year':'04','month':'10','day':'4'} + assert m.match('/archives/04-1-1.html') == {'controller':'archives','action':'view','year':'04','month':'1','day':'1'} def test_splits_packed_with_regexps(self): m = Mapper() @@ -620,17 +608,14 @@ def test_splits_packed_with_regexps(self): requirements=dict(year=r'\d{4}',month=r'\d{2}',day=r'\d{2}')) m.create_regs([]) - eq_(None, m.match('/boo')) - eq_(None, m.match('/archives')) - eq_(None, m.match('/archives/2004020.html')) - eq_(None, m.match('/archives/200502.html')) + assert m.match('/boo') is None + assert m.match('/archives') is None + assert m.match('/archives/2004020.html') is None + assert m.match('/archives/200502.html') is None - eq_({'controller':'archives','action':'view','year':'2004','month':'12','day':'04'}, - m.match('/archives/20041204.html')) - eq_({'controller':'archives','action':'view','year':'2005','month':'10','day':'04'}, - m.match('/archives/20051004.html')) - eq_({'controller':'archives','action':'view','year':'2006','month':'01','day':'01'}, - m.match('/archives/20060101.html')) + assert m.match('/archives/20041204.html') == {'controller':'archives','action':'view','year':'2004','month':'12','day':'04'} + assert m.match('/archives/20051004.html') == {'controller':'archives','action':'view','year':'2005','month':'10','day':'04'} + assert m.match('/archives/20060101.html') == {'controller':'archives','action':'view','year':'2006','month':'01','day':'01'} def test_splits_with_slashes(self): m = Mapper() @@ -638,13 +623,11 @@ def test_splits_with_slashes(self): m.connect(':name/:(action)-:(day)', controller='content') m.create_regs([]) - eq_(None, m.match('/something')) - eq_(None, m.match('/something/is-')) + assert m.match('/something') is None + assert m.match('/something/is-') is None - eq_({'controller':'content','action':'view','day':'3','name':'group'}, - m.match('/group/view-3')) - eq_({'controller':'content','action':'view','day':'5','name':'group'}, - m.match('/group/view-5')) + assert m.match('/group/view-3') == {'controller':'content','action':'view','day':'3','name':'group'} + assert m.match('/group/view-5') == {'controller':'content','action':'view','day':'5','name':'group'} def test_splits_with_slashes_and_default(self): m = Mapper(explicit=False) @@ -652,13 +635,11 @@ def test_splits_with_slashes_and_default(self): m.connect(':name/:(action)-:(id)', controller='content') m.create_regs([]) - eq_(None, m.match('/something')) - eq_(None, m.match('/something/is')) + assert m.match('/something') is None + assert m.match('/something/is') is None - eq_({'controller':'content','action':'view','id':'3','name':'group'}, - m.match('/group/view-3')) - eq_({'controller':'content','action':'view','id':None,'name':'group'}, - m.match('/group/view-')) + assert m.match('/group/view-3') == {'controller':'content','action':'view','id':'3','name':'group'} + assert m.match('/group/view-') == {'controller':'content','action':'view','id':None,'name':'group'} def test_no_reg_make(self): m = Mapper() @@ -666,7 +647,8 @@ def test_no_reg_make(self): m.controller_scan = False def call_func(): m.match('/group/view-3') - assert_raises(RoutesException, call_func) + with pytest.raises(RoutesException): + call_func() def test_routematch(self): m = Mapper(explicit=False) @@ -676,9 +658,9 @@ def test_routematch(self): route = m.matchlist[0] resultdict, route_obj = m.routematch('/content') - eq_({'action':'index', 'controller':'content','id':None}, resultdict) - eq_(route, route_obj) - eq_(None, m.routematch('/nowhere')) + assert resultdict == {'action':'index', 'controller':'content','id':None} + assert route_obj == route + assert m.routematch('/nowhere') is None def test_routematch_debug(self): m = Mapper(explicit=False) @@ -689,12 +671,12 @@ def test_routematch_debug(self): route = m.matchlist[0] resultdict, route_obj, debug = m.routematch('/content') - eq_({'action':'index', 'controller':'content','id':None}, resultdict) - eq_(route, route_obj) + assert resultdict == {'action':'index', 'controller':'content','id':None} + assert route_obj == route resultdict, route_obj, debug = m.routematch('/nowhere') - eq_(None, resultdict) - eq_(None, route_obj) - eq_(len(debug), 0) + assert resultdict is None + assert route_obj is None + assert len(debug) == 0 def test_match_debug(self): m = Mapper(explicit=False) @@ -706,12 +688,12 @@ def test_match_debug(self): route = m.matchlist[0] resultdict, route_obj, debug = m.match('/content') - eq_({'action':'index', 'controller':'content','id':None}, resultdict) - eq_(route, route_obj) + assert resultdict == {'action':'index', 'controller':'content','id':None} + assert route_obj == route resultdict, route_obj, debug = m.match('/nowhere') - eq_(None, resultdict) - eq_(route_obj, None) - eq_(len(debug), 0) + assert resultdict is None + assert route_obj is None + assert len(debug) == 0 def test_conditions(self): m = Mapper(explicit=False) @@ -725,19 +707,19 @@ def test_conditions(self): env = dict(PATH_INFO='/nowhere', HTTP_HOST='example.com', REQUEST_METHOD='GET') con.mapper_dict = {} con.environ = env - eq_(None, con.mapper_dict) + assert con.mapper_dict is None env['PATH_INFO'] = '/content' con.environ = env - eq_({'action':'index','controller':'content','id':None}, con.mapper_dict) + assert con.mapper_dict == {'action':'index','controller':'content','id':None} env['PATH_INFO'] = '/home/upload' con.environ = env - eq_(None, con.mapper_dict) + assert con.mapper_dict is None env['REQUEST_METHOD'] = 'POST' con.environ = env - eq_({'action':'upload','controller':'content'}, con.mapper_dict) + assert con.mapper_dict == {'action':'upload','controller':'content'} def test_subdomains(self): m = Mapper(explicit=False) @@ -752,22 +734,19 @@ def test_subdomains(self): con.mapper_dict = {} con.environ = env - eq_(None, con.mapper_dict) + assert con.mapper_dict is None env['PATH_INFO'] = '/content' con.environ = env - eq_({'action': 'index', 'controller': 'content', 'sub_domain': None, 'id': None}, - con.mapper_dict) + assert con.mapper_dict == {'action': 'index', 'controller': 'content', 'sub_domain': None, 'id': None} env['HTTP_HOST'] = 'fred.example.com' con.environ = env - eq_({'action': 'index', 'controller': 'content', 'sub_domain': 'fred', 'id': None}, - con.mapper_dict) + assert con.mapper_dict == {'action': 'index', 'controller': 'content', 'sub_domain': 'fred', 'id': None} env['HTTP_HOST'] = 'www.example.com' con.environ = env - eq_({'action': 'index', 'controller': 'content', 'sub_domain': 'www', 'id': None}, - con.mapper_dict) + assert con.mapper_dict == {'action': 'index', 'controller': 'content', 'sub_domain': 'www', 'id': None} def test_subdomains_with_conditions(self): m = Mapper(explicit=False) @@ -782,27 +761,26 @@ def test_subdomains_with_conditions(self): con.mapper_dict = {} con.environ = env - eq_(None, con.mapper_dict) + assert con.mapper_dict is None env['PATH_INFO'] = '/content' con.environ = env - eq_({'action': 'index', 'controller': 'content', 'sub_domain': None, 'id': None}, - con.mapper_dict) + assert con.mapper_dict == {'action': 'index', 'controller': 'content', 'sub_domain': None, 'id': None} m.connect('', controller='users', action='home', conditions={'sub_domain':True}) m.create_regs(['content', 'users', 'blog']) env['PATH_INFO'] = '/' con.environ = env - eq_(None, con.mapper_dict) + assert con.mapper_dict is None env['HTTP_HOST'] = 'fred.example.com' con.environ = env - eq_({'action': 'home', 'controller': 'users', 'sub_domain': 'fred'}, con.mapper_dict) + assert con.mapper_dict == {'action': 'home', 'controller': 'users', 'sub_domain': 'fred'} m.sub_domains_ignore = ['www'] env['HTTP_HOST'] = 'www.example.com' con.environ = env - eq_(None, con.mapper_dict) + assert con.mapper_dict is None def test_subdomain_with_conditions2(self): m = Mapper() @@ -822,16 +800,16 @@ def test_subdomain_with_conditions2(self): con.mapper_dict = {} con.environ = env - eq_(None, con.mapper_dict) + assert con.mapper_dict is None env['PATH_INFO'] = '/admin/comments' con.environ = env - eq_({'action': 'comments', 'controller':'blog_admin', 'sub_domain': None}, con.mapper_dict) + assert con.mapper_dict == {'action': 'comments', 'controller':'blog_admin', 'sub_domain': None} env['PATH_INFO'] = '/admin/view' env['HTTP_HOST'] = 'fred.example.com' con.environ = env - eq_({'action': 'view', 'controller':'admin', 'sub_domain': 'fred'}, con.mapper_dict) + assert con.mapper_dict == {'action': 'view', 'controller':'admin', 'sub_domain': 'fred'} def test_subdomains_with_ignore(self): m = Mapper(explicit=False) @@ -847,22 +825,19 @@ def test_subdomains_with_ignore(self): con.mapper_dict = {} con.environ = env - eq_(None, con.mapper_dict) + assert con.mapper_dict is None env['PATH_INFO'] = '/content' con.environ = env - eq_({'action': 'index', 'controller': 'content', 'sub_domain': None, 'id': None}, - con.mapper_dict) + assert con.mapper_dict == {'action': 'index', 'controller': 'content', 'sub_domain': None, 'id': None} env['HTTP_HOST'] = 'fred.example.com' con.environ = env - eq_({'action': 'index', 'controller': 'content', 'sub_domain': 'fred', 'id': None}, - con.mapper_dict) + assert con.mapper_dict == {'action': 'index', 'controller': 'content', 'sub_domain': 'fred', 'id': None} env['HTTP_HOST'] = 'www.example.com' con.environ = env - eq_({'action': 'index', 'controller': 'content', 'sub_domain': None, 'id': None}, - con.mapper_dict) + assert con.mapper_dict == {'action': 'index', 'controller': 'content', 'sub_domain': None, 'id': None} def test_other_special_chars(self): m = Mapper(explicit=False) @@ -871,19 +846,11 @@ def test_other_special_chars(self): m.connect('/error/:action/:id', controller='error') m.create_regs(['content']) - eq_({'year': '2007', 'slug': 'test', 'locale': 'en', 'format': 'html', - 'controller': 'content', 'action': 'index'}, - m.match('/2007/test')) - eq_({'year': '2007', 'slug': 'test', 'format': 'html', 'locale': 'en', - 'controller': 'content', 'action': 'index'}, - m.match('/2007/test.html')) - eq_({'year': '2007', 'slug': 'test', - 'format': 'html', 'locale': 'en', - 'controller': 'content', 'action': 'index'}, - m.match('/2007/test.html,en')) - eq_(None, m.match('/2007/test.')) - eq_({'controller': 'error', 'action': 'img', - 'id': 'icon-16.png'}, m.match('/error/img/icon-16.png')) + assert m.match('/2007/test') == {'year': '2007', 'slug': 'test', 'locale': 'en', 'format': 'html', 'controller': 'content', 'action': 'index'} + assert m.match('/2007/test.html') == {'year': '2007', 'slug': 'test', 'format': 'html', 'locale': 'en', 'controller': 'content', 'action': 'index'} + assert m.match('/2007/test.html,en') == {'year': '2007', 'slug': 'test', 'format': 'html', 'locale': 'en', 'controller': 'content', 'action': 'index'} + assert m.match('/2007/test.') is None + assert m.match('/error/img/icon-16.png') == {'controller': 'error', 'action': 'img', 'id': 'icon-16.png'} def test_various_periods(self): m = Mapper(explicit=False) @@ -891,17 +858,13 @@ def test_various_periods(self): m.connect('sites/:site/pages/:page') m.create_regs(['content']) - eq_({'action': u'index', 'controller': u'content', - 'site': u'python.com', 'page': u'index.html'}, - m.match('/sites/python.com/pages/index.html')) + assert m.match('/sites/python.com/pages/index.html') == {'action': u'index', 'controller': u'content', 'site': u'python.com', 'page': u'index.html'} m = Mapper(explicit=False) m.minimization = True m.connect('sites/:site/pages/:page.:format', format='html') m.create_regs(['content']) - eq_({'action': u'index', 'controller': u'content', - 'site': u'python.com', 'page': u'index', 'format': u'html'}, - m.match('/sites/python.com/pages/index.html')) + assert m.match('/sites/python.com/pages/index.html') == {'action': u'index', 'controller': u'content', 'site': u'python.com', 'page': u'index', 'format': u'html'} def test_empty_fails(self): m = Mapper(explicit=False) @@ -910,11 +873,12 @@ def test_empty_fails(self): m.connect('', controller='content', action='view', id=4) m.create_regs(['content']) - eq_({'controller':'content','action':'index','id':None}, m.match('/content')) - eq_({'controller':'content','action':'view','id':'4'}, m.match('/')) + assert m.match('/content') == {'controller':'content','action':'index','id':None} + assert m.match('/') == {'controller':'content','action':'view','id':'4'} def call_func(): m.match(None) - assert_raises(RoutesException, call_func) + with pytest.raises(RoutesException): + call_func() def test_home_noargs(self): m = Mapper(controller_scan=None, directory=None, always_scan=False) @@ -923,11 +887,12 @@ def test_home_noargs(self): m.connect('') m.create_regs([]) - eq_(None, m.match('/content')) - eq_({}, m.match('/')) + assert m.match('/content') is None + assert m.match('/') == {} def call_func(): m.match(None) - assert_raises(RoutesException, call_func) + with pytest.raises(RoutesException): + call_func() def test_dot_format_args(self): for minimization in [False, True]: @@ -936,11 +901,11 @@ def test_dot_format_args(self): m.connect('/songs/{title}{.format}') m.connect('/stories/{slug:[^./]+?}{.format:pdf}') - eq_({'title': 'my-way', 'format': None}, m.match('/songs/my-way')) - eq_({'title': 'my-way', 'format': 'mp3'}, m.match('/songs/my-way.mp3')) - eq_({'slug': 'frist-post', 'format': None}, m.match('/stories/frist-post')) - eq_({'slug': 'frist-post', 'format': 'pdf'}, m.match('/stories/frist-post.pdf')) - eq_(None, m.match('/stories/frist-post.doc')) + assert m.match('/songs/my-way') == {'title': 'my-way', 'format': None} + assert m.match('/songs/my-way.mp3') == {'title': 'my-way', 'format': 'mp3'} + assert m.match('/stories/frist-post') == {'slug': 'frist-post', 'format': None} + assert m.match('/stories/frist-post.pdf') == {'slug': 'frist-post', 'format': 'pdf'} + assert m.match('/stories/frist-post.doc') is None if __name__ == '__main__': diff --git a/tests/test_functional/test_resources.py b/tests/test_functional/test_resources.py index 0855cd5..bc373cc 100644 --- a/tests/test_functional/test_resources.py +++ b/tests/test_functional/test_resources.py @@ -1,22 +1,22 @@ """test_resources""" import unittest -from nose.tools import eq_, assert_raises +import pytest from routes import * class TestResourceGeneration(unittest.TestCase): def _assert_restful_routes(self, m, options, path_prefix=''): baseroute = '/' + path_prefix + options['controller'] - eq_(baseroute, m.generate(action='index', **options)) - eq_(baseroute + '.xml', m.generate(action='index', format='xml', **options)) - eq_(baseroute + '/new', m.generate(action='new', **options)) - eq_(baseroute + '/1', m.generate(action='show', id='1', **options)) - eq_(baseroute + '/1/edit', m.generate(action='edit',id='1', **options)) - eq_(baseroute + '/1.xml', m.generate(action='show', id='1',format='xml', **options)) + assert m.generate(action='index', **options) == baseroute + assert m.generate(action='index', format='xml', **options) == baseroute + '.xml' + assert m.generate(action='new', **options) == baseroute + '/new' + assert m.generate(action='show', id='1', **options) == baseroute + '/1' + assert m.generate(action='edit', id='1', **options) == baseroute + '/1/edit' + assert m.generate(action='show', id='1', format='xml', **options) == baseroute + '/1.xml' - eq_(baseroute, m.generate(action='create', method='post', **options)) - eq_(baseroute + '/1', m.generate(action='update', method='put', id='1', **options)) - eq_(baseroute + '/1', m.generate(action='delete', method='delete', id='1', **options)) + assert m.generate(action='create', method='post', **options) == baseroute + assert m.generate(action='update', method='put', id='1', **options) == baseroute + '/1' + assert m.generate(action='delete', method='delete', id='1', **options) == baseroute + '/1' def test_resources(self): m = Mapper() @@ -25,14 +25,14 @@ def test_resources(self): m.resource('passage', 'passages') m.create_regs(['messages']) options = dict(controller='messages') - eq_('/messages', url_for('messages')) - eq_('/messages.xml', url_for('formatted_messages', format='xml')) - eq_('/messages/1', url_for('message', id=1)) - eq_('/messages/1.xml', url_for('formatted_message', id=1, format='xml')) - eq_('/messages/new', url_for('new_message')) - eq_('/messages/1.xml', url_for('formatted_message', id=1, format='xml')) - eq_('/messages/1/edit', url_for('edit_message', id=1)) - eq_('/messages/1/edit.xml', url_for('formatted_edit_message', id=1, format='xml')) + assert url_for('messages') == '/messages' + assert url_for('formatted_messages', format='xml') == '/messages.xml' + assert url_for('message', id=1) == '/messages/1' + assert url_for('formatted_message', id=1, format='xml') == '/messages/1.xml' + assert url_for('new_message') == '/messages/new' + assert url_for('formatted_message', id=1, format='xml') == '/messages/1.xml' + assert url_for('edit_message', id=1) == '/messages/1/edit' + assert url_for('formatted_edit_message', id=1, format='xml') == '/messages/1/edit.xml' self._assert_restful_routes(m, options) def test_resources_with_path_prefix(self): @@ -48,10 +48,10 @@ def test_resources_with_collection_action(self): m.create_regs(['messages']) options = dict(controller='messages') self._assert_restful_routes(m, options) - eq_('/messages/rss', m.generate(controller='messages', action='rss')) - eq_('/messages/rss', url_for('rss_messages')) - eq_('/messages/rss.xml', m.generate(controller='messages', action='rss', format='xml')) - eq_('/messages/rss.xml', url_for('formatted_rss_messages', format='xml')) + assert m.generate(controller='messages', action='rss') == '/messages/rss' + assert url_for('rss_messages') == '/messages/rss' + assert m.generate(controller='messages', action='rss', format='xml') == '/messages/rss.xml' + assert url_for('formatted_rss_messages', format='xml') == '/messages/rss.xml' def test_resources_with_member_action(self): for method in ['put', 'post']: @@ -60,9 +60,8 @@ def test_resources_with_member_action(self): m.create_regs(['messages']) options = dict(controller='messages') self._assert_restful_routes(m, options) - eq_('/messages/1/mark', m.generate(method=method, action='mark', id='1', **options)) - eq_('/messages/1/mark.xml', - m.generate(method=method, action='mark', id='1', format='xml', **options)) + assert m.generate(method=method, action='mark', id='1', **options) == '/messages/1/mark' + assert m.generate(method=method, action='mark', id='1', format='xml', **options) == '/messages/1/mark.xml' def test_resources_with_new_action(self): m = Mapper() @@ -70,11 +69,10 @@ def test_resources_with_new_action(self): m.create_regs(['messages']) options = dict(controller='messages') self._assert_restful_routes(m, options) - eq_('/messages/new/preview', m.generate(controller='messages', action='preview', method='post')) - eq_('/messages/new/preview', url_for('preview_new_message')) - eq_('/messages/new/preview.xml', - m.generate(controller='messages', action='preview', method='post', format='xml')) - eq_('/messages/new/preview.xml', url_for('formatted_preview_new_message', format='xml')) + assert m.generate(controller='messages', action='preview', method='post') == '/messages/new/preview' + assert url_for('preview_new_message') == '/messages/new/preview' + assert m.generate(controller='messages', action='preview', method='post', format='xml') == '/messages/new/preview.xml' + assert url_for('formatted_preview_new_message', format='xml') == '/messages/new/preview.xml' def test_resources_with_name_prefix(self): m = Mapper() @@ -82,8 +80,9 @@ def test_resources_with_name_prefix(self): m.create_regs(['messages']) options = dict(controller='messages') self._assert_restful_routes(m, options) - eq_('/messages/new/preview', url_for('category_preview_new_message')) - assert_raises(Exception, url_for, 'category_preview_new_message', method='get') + assert url_for('category_preview_new_message') == '/messages/new/preview' + with pytest.raises(Exception): + url_for('category_preview_new_message', method='get') def test_resources_with_requirements(self): m = Mapper() @@ -94,11 +93,10 @@ def test_resources_with_requirements(self): # in addition to the positive tests we need to guarantee we # are not matching when the requirements don't match. - eq_({'action': u'create', 'project_id': u'cafe', 'user_id': u'123', 'controller': u'messages'}, - m.match('/cafe/123/messages')) - eq_(None, m.match('/extensions/123/messages')) - eq_(None, m.match('/b0a3/123b/messages')) - eq_(None, m.match('/foo/bar/messages')) + assert m.match('/cafe/123/messages') == {'action': u'create', 'project_id': u'cafe', 'user_id': u'123', 'controller': u'messages'} + assert m.match('/extensions/123/messages') is None + assert m.match('/b0a3/123b/messages') is None + assert m.match('/foo/bar/messages') is None class TestResourceRecognition(unittest.TestCase): @@ -115,54 +113,54 @@ def test_path(path, method): con.environ = env test_path('/people', 'GET') - eq_({'controller':'people', 'action':'index'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'index'} test_path('/people.xml', 'GET') - eq_({'controller':'people', 'action':'index', 'format':'xml'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'index', 'format':'xml'} test_path('/people', 'POST') - eq_({'controller':'people', 'action':'create'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'create'} test_path('/people.html', 'POST') - eq_({'controller':'people', 'action':'create', 'format':'html'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'create', 'format':'html'} test_path('/people/2.xml', 'GET') - eq_({'controller':'people', 'action':'show', 'id':'2', 'format':'xml'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'show', 'id':'2', 'format':'xml'} test_path('/people/2', 'GET') - eq_({'controller':'people', 'action':'show', 'id':'2'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'show', 'id':'2'} test_path('/people/2/edit', 'GET') - eq_({'controller':'people', 'action':'edit', 'id':'2'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'edit', 'id':'2'} test_path('/people/2/edit.xml', 'GET') - eq_({'controller':'people', 'action':'edit', 'id':'2', 'format':'xml'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'edit', 'id':'2', 'format':'xml'} test_path('/people/2', 'DELETE') - eq_({'controller':'people', 'action':'delete', 'id':'2'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'delete', 'id':'2'} test_path('/people/2', 'PUT') - eq_({'controller':'people', 'action':'update', 'id':'2'}, con.mapper_dict ) + assert con.mapper_dict == {'controller':'people', 'action':'update', 'id':'2'} test_path('/people/2.json', 'PUT') - eq_({'controller':'people', 'action':'update', 'id':'2', 'format':'json'}, con.mapper_dict ) + assert con.mapper_dict == {'controller':'people', 'action':'update', 'id':'2', 'format':'json'} # Test for dots in urls test_path('/people/2\.13', 'PUT') - eq_({'controller':'people', 'action':'update', 'id':'2\.13'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'update', 'id':'2\.13'} test_path('/people/2\.13.xml', 'PUT') - eq_({'controller':'people', 'action':'update', 'id':'2\.13', 'format':'xml'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'update', 'id':'2\.13', 'format':'xml'} test_path('/people/user\.name', 'PUT') - eq_({'controller':'people', 'action':'update', 'id':'user\.name'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'update', 'id':'user\.name'} test_path('/people/user\.\.\.name', 'PUT') - eq_({'controller':'people', 'action':'update', 'id':'user\.\.\.name'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'update', 'id':'user\.\.\.name'} test_path('/people/user\.name\.has\.dots', 'PUT') - eq_({'controller':'people', 'action':'update', 'id':'user\.name\.has\.dots'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'update', 'id':'user\.name\.has\.dots'} test_path('/people/user\.name\.is\.something.xml', 'PUT') - eq_({'controller':'people', 'action':'update', 'id':'user\.name\.is\.something', 'format':'xml'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'update', 'id':'user\.name\.is\.something', 'format':'xml'} test_path('/people/user\.name\.ends\.with\.dot\..xml', 'PUT') - eq_({'controller':'people', 'action':'update', 'id':'user\.name\.ends\.with\.dot\.', 'format':'xml'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'update', 'id':'user\.name\.ends\.with\.dot\.', 'format':'xml'} test_path('/people/user\.name\.ends\.with\.dot\.', 'PUT') - eq_({'controller':'people', 'action':'update', 'id':'user\.name\.ends\.with\.dot\.'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'update', 'id':'user\.name\.ends\.with\.dot\.'} test_path('/people/\.user\.name\.starts\.with\.dot', 'PUT') - eq_({'controller':'people', 'action':'update', 'id':'\.user\.name\.starts\.with\.dot'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'update', 'id':'\.user\.name\.starts\.with\.dot'} test_path('/people/user\.name.json', 'PUT') - eq_({'controller':'people', 'action':'update', 'id':'user\.name', 'format':'json'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'update', 'id':'user\.name', 'format':'json'} def test_resource_with_nomin(self): m = Mapper() @@ -178,21 +176,21 @@ def test_path(path, method): con.environ = env test_path('/people', 'GET') - eq_({'controller':'people', 'action':'index'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'index'} test_path('/people', 'POST') - eq_({'controller':'people', 'action':'create'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'create'} test_path('/people/2', 'GET') - eq_({'controller':'people', 'action':'show', 'id':'2'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'show', 'id':'2'} test_path('/people/2/edit', 'GET') - eq_({'controller':'people', 'action':'edit', 'id':'2'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'edit', 'id':'2'} test_path('/people/2', 'DELETE') - eq_({'controller':'people', 'action':'delete', 'id':'2'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'delete', 'id':'2'} test_path('/people/2', 'PUT') - eq_({'controller':'people', 'action':'update', 'id':'2'}, con.mapper_dict) + assert con.mapper_dict == {'controller':'people', 'action':'update', 'id':'2'} def test_resource_created_with_parent_resource(self): m = Mapper() @@ -210,44 +208,38 @@ def test_path(path, method): con.environ = env test_path('/regions/13/locations', 'GET') - eq_(con.mapper_dict, {'region_id': '13', 'controller': 'locations', - 'action': 'index'}) + assert con.mapper_dict == {'region_id': '13', 'controller': 'locations', 'action': 'index'} url = url_for('region_locations', region_id=13) - eq_(url, '/regions/13/locations') + assert url == '/regions/13/locations' test_path('/regions/13/locations', 'POST') - eq_(con.mapper_dict, {'region_id': '13', 'controller': 'locations', - 'action': 'create'}) + assert con.mapper_dict == {'region_id': '13', 'controller': 'locations', 'action': 'create'} # new url = url_for('region_new_location', region_id=13) - eq_(url, '/regions/13/locations/new') + assert url == '/regions/13/locations/new' # create url = url_for('region_locations', region_id=13) - eq_(url, '/regions/13/locations') + assert url == '/regions/13/locations' test_path('/regions/13/locations/60', 'GET') - eq_(con.mapper_dict, {'region_id': '13', 'controller': 'locations', - 'id': '60', 'action': 'show'}) + assert con.mapper_dict == {'region_id': '13', 'controller': 'locations', 'id': '60', 'action': 'show'} url = url_for('region_location', region_id=13, id=60) - eq_(url, '/regions/13/locations/60') + assert url == '/regions/13/locations/60' test_path('/regions/13/locations/60/edit', 'GET') - eq_(con.mapper_dict, {'region_id': '13', 'controller': 'locations', - 'id': '60', 'action': 'edit'}) + assert con.mapper_dict == {'region_id': '13', 'controller': 'locations', 'id': '60', 'action': 'edit'} url = url_for('region_edit_location', region_id=13, id=60) - eq_(url, '/regions/13/locations/60/edit') + assert url == '/regions/13/locations/60/edit' test_path('/regions/13/locations/60', 'DELETE') - eq_(con.mapper_dict, {'region_id': '13', 'controller': 'locations', - 'id': '60', 'action': 'delete'}) + assert con.mapper_dict == {'region_id': '13', 'controller': 'locations', 'id': '60', 'action': 'delete'} url = url_for('region_location', region_id=13, id=60) - eq_(url, '/regions/13/locations/60') + assert url == '/regions/13/locations/60' test_path('/regions/13/locations/60', 'PUT') - eq_(con.mapper_dict, {'region_id': '13', 'controller': 'locations', - 'id': '60', 'action': 'update'}) + assert con.mapper_dict == {'region_id': '13', 'controller': 'locations', 'id': '60', 'action': 'update'} url = url_for('region_location', region_id=13, id=60) - eq_(url, '/regions/13/locations/60') + assert url == '/regions/13/locations/60' # Make sure ``path_prefix`` overrides work # empty ``path_prefix`` (though I'm not sure why someone would do this) @@ -257,7 +249,7 @@ def test_path(path, method): collection_name='regions'), path_prefix='') url = url_for('region_locations') - eq_(url, '/locations') + assert url == '/locations' # different ``path_prefix`` m = Mapper() m.resource('location', 'locations', @@ -265,7 +257,7 @@ def test_path(path, method): collection_name='regions'), path_prefix='areas/:area_id') url = url_for('region_locations', area_id=51) - eq_(url, '/areas/51/locations') + assert url == '/areas/51/locations' # Make sure ``name_prefix`` overrides work # empty ``name_prefix`` @@ -275,7 +267,7 @@ def test_path(path, method): collection_name='regions'), name_prefix='') url = url_for('locations', region_id=51) - eq_(url, '/regions/51/locations') + assert url == '/regions/51/locations' # different ``name_prefix`` m = Mapper() m.resource('location', 'locations', @@ -283,7 +275,7 @@ def test_path(path, method): collection_name='regions'), name_prefix='area_') url = url_for('area_locations', region_id=51) - eq_(url, '/regions/51/locations') + assert url == '/regions/51/locations' # Make sure ``path_prefix`` and ``name_prefix`` overrides work together # empty ``path_prefix`` @@ -294,7 +286,7 @@ def test_path(path, method): path_prefix='', name_prefix='place_') url = url_for('place_locations') - eq_(url, '/locations') + assert url == '/locations' # empty ``name_prefix`` m = Mapper() m.resource('location', 'locations', @@ -303,7 +295,7 @@ def test_path(path, method): path_prefix='areas/:area_id', name_prefix='') url = url_for('locations', area_id=51) - eq_(url, '/areas/51/locations') + assert url == '/areas/51/locations' # different ``path_prefix`` and ``name_prefix`` m = Mapper() m.resource('location', 'locations', @@ -312,7 +304,7 @@ def test_path(path, method): path_prefix='areas/:area_id', name_prefix='place_') url = url_for('place_locations', area_id=51) - eq_(url, '/areas/51/locations') + assert url == '/areas/51/locations' def test_resource_created_with_parent_resource_nomin(self): m = Mapper() @@ -331,44 +323,38 @@ def test_path(path, method): con.environ = env test_path('/regions/13/locations', 'GET') - eq_(con.mapper_dict, {'region_id': '13', 'controller': 'locations', - 'action': 'index'}) + assert con.mapper_dict == {'region_id': '13', 'controller': 'locations', 'action': 'index'} url = url_for('region_locations', region_id=13) - eq_(url, '/regions/13/locations') + assert url == '/regions/13/locations' test_path('/regions/13/locations', 'POST') - eq_(con.mapper_dict, {'region_id': '13', 'controller': 'locations', - 'action': 'create'}) + assert con.mapper_dict == {'region_id': '13', 'controller': 'locations', 'action': 'create'} # new url = url_for('region_new_location', region_id=13) - eq_(url, '/regions/13/locations/new') + assert url == '/regions/13/locations/new' # create url = url_for('region_locations', region_id=13) - eq_(url, '/regions/13/locations') + assert url == '/regions/13/locations' test_path('/regions/13/locations/60', 'GET') - eq_(con.mapper_dict, {'region_id': '13', 'controller': 'locations', - 'id': '60', 'action': 'show'}) + assert con.mapper_dict == {'region_id': '13', 'controller': 'locations', 'id': '60', 'action': 'show'} url = url_for('region_location', region_id=13, id=60) - eq_(url, '/regions/13/locations/60') + assert url == '/regions/13/locations/60' test_path('/regions/13/locations/60/edit', 'GET') - eq_(con.mapper_dict, {'region_id': '13', 'controller': 'locations', - 'id': '60', 'action': 'edit'}) + assert con.mapper_dict == {'region_id': '13', 'controller': 'locations', 'id': '60', 'action': 'edit'} url = url_for('region_edit_location', region_id=13, id=60) - eq_(url, '/regions/13/locations/60/edit') + assert url == '/regions/13/locations/60/edit' test_path('/regions/13/locations/60', 'DELETE') - eq_(con.mapper_dict, {'region_id': '13', 'controller': 'locations', - 'id': '60', 'action': 'delete'}) + assert con.mapper_dict == {'region_id': '13', 'controller': 'locations', 'id': '60', 'action': 'delete'} url = url_for('region_location', region_id=13, id=60) - eq_(url, '/regions/13/locations/60') + assert url == '/regions/13/locations/60' test_path('/regions/13/locations/60', 'PUT') - eq_(con.mapper_dict, {'region_id': '13', 'controller': 'locations', - 'id': '60', 'action': 'update'}) + assert con.mapper_dict == {'region_id': '13', 'controller': 'locations', 'id': '60', 'action': 'update'} url = url_for('region_location', region_id=13, id=60) - eq_(url, '/regions/13/locations/60') + assert url == '/regions/13/locations/60' # Make sure ``path_prefix`` overrides work # empty ``path_prefix`` (though I'm not sure why someone would do this) @@ -378,7 +364,7 @@ def test_path(path, method): collection_name='regions'), path_prefix='/') url = url_for('region_locations') - eq_(url, '/locations') + assert url == '/locations' # different ``path_prefix`` m = Mapper() m.resource('location', 'locations', @@ -386,7 +372,7 @@ def test_path(path, method): collection_name='regions'), path_prefix='areas/:area_id') url = url_for('region_locations', area_id=51) - eq_(url, '/areas/51/locations') + assert url == '/areas/51/locations' # Make sure ``name_prefix`` overrides work # empty ``name_prefix`` @@ -396,7 +382,7 @@ def test_path(path, method): collection_name='regions'), name_prefix='') url = url_for('locations', region_id=51) - eq_(url, '/regions/51/locations') + assert url == '/regions/51/locations' # different ``name_prefix`` m = Mapper() m.resource('location', 'locations', @@ -404,7 +390,7 @@ def test_path(path, method): collection_name='regions'), name_prefix='area_') url = url_for('area_locations', region_id=51) - eq_(url, '/regions/51/locations') + assert url == '/regions/51/locations' # Make sure ``path_prefix`` and ``name_prefix`` overrides work together # empty ``path_prefix`` @@ -415,7 +401,7 @@ def test_path(path, method): path_prefix='', name_prefix='place_') url = url_for('place_locations') - eq_(url, '/locations') + assert url == '/locations' # empty ``name_prefix`` m = Mapper() m.resource('location', 'locations', @@ -424,7 +410,7 @@ def test_path(path, method): path_prefix='areas/:area_id', name_prefix='') url = url_for('locations', area_id=51) - eq_(url, '/areas/51/locations') + assert url == '/areas/51/locations' # different ``path_prefix`` and ``name_prefix`` m = Mapper() m.resource('location', 'locations', @@ -433,7 +419,7 @@ def test_path(path, method): path_prefix='areas/:area_id', name_prefix='place_') url = url_for('place_locations', area_id=51) - eq_(url, '/areas/51/locations') + assert url == '/areas/51/locations' diff --git a/tests/test_functional/test_submapper.py b/tests/test_functional/test_submapper.py index 8821de9..46eca90 100644 --- a/tests/test_functional/test_submapper.py +++ b/tests/test_functional/test_submapper.py @@ -1,6 +1,6 @@ """test_resources""" import unittest -from nose.tools import eq_, assert_raises +import pytest from routes import * @@ -10,14 +10,15 @@ def test_submapper(self): c = m.submapper(path_prefix='/entries', requirements=dict(id='\d+')) c.connect('entry', '/{id}') - eq_('/entries/1', url_for('entry', id=1)) - assert_raises(Exception, url_for, 'entry', id='foo') + assert url_for('entry', id=1) == '/entries/1' + with pytest.raises(Exception): + url_for('entry', id='foo') def test_submapper_with_no_path(self): m = Mapper() c = m.submapper(path_prefix='/') c.connect('entry') - eq_('/entry?id=1', url_for('entry', id=1)) + assert url_for('entry', id=1) == '/entry?id=1' def test_submapper_nesting(self): m = Mapper() @@ -25,15 +26,16 @@ def test_submapper_nesting(self): requirements=dict(id='\d+')) e = c.submapper(path_prefix='/{id}') - eq_('entry', c.resource_name) - eq_('entry', e.resource_name) + assert c.resource_name == 'entry' + assert e.resource_name == 'entry' e.connect('entry', '') e.connect('edit_entry', '/edit') - eq_('/entries/1', url_for('entry', id=1)) - eq_('/entries/1/edit', url_for('edit_entry', id=1)) - assert_raises(Exception, url_for, 'entry', id='foo') + assert url_for('entry', id=1) == '/entries/1' + assert url_for('edit_entry', id=1) == '/entries/1/edit' + with pytest.raises(Exception): + url_for('entry', id='foo') def test_submapper_action(self): m = Mapper(explicit=True) @@ -42,11 +44,12 @@ def test_submapper_action(self): c.action(name='entries', action='list') c.action(action='create', method='POST') - eq_('/entries', url_for('entries', method='GET')) - eq_('/entries', url_for('create_entry', method='POST')) - eq_('/entries', url_for(controller='entry', action='list', method='GET')) - eq_('/entries', url_for(controller='entry', action='create', method='POST')) - assert_raises(Exception, url_for, 'entries', method='DELETE') + assert url_for('entries', method='GET') == '/entries' + assert url_for('create_entry', method='POST') == '/entries' + assert url_for(controller='entry', action='list', method='GET') == '/entries' + assert url_for(controller='entry', action='create', method='POST') == '/entries' + with pytest.raises(Exception): + url_for('entries', method='DELETE') def test_submapper_link(self): m = Mapper(explicit=True) @@ -55,12 +58,14 @@ def test_submapper_link(self): c.link(rel='new') c.link(rel='ping', method='POST') - eq_('/entries/new', url_for('new_entry', method='GET')) - eq_('/entries/ping', url_for('ping_entry', method='POST')) - eq_('/entries/new', url_for(controller='entry', action='new', method='GET')) - eq_('/entries/ping', url_for(controller='entry', action='ping', method='POST')) - assert_raises(Exception, url_for, 'new_entry', method='PUT') - assert_raises(Exception, url_for, 'ping_entry', method='PUT') + assert url_for('new_entry', method='GET') == '/entries/new' + assert url_for('ping_entry', method='POST') == '/entries/ping' + assert url_for(controller='entry', action='new', method='GET') == '/entries/new' + assert url_for(controller='entry', action='ping', method='POST') == '/entries/ping' + with pytest.raises(Exception): + url_for('new_entry', method='PUT') + with pytest.raises(Exception): + url_for('ping_entry', method='PUT') def test_submapper_standard_actions(self): m = Mapper() @@ -74,14 +79,16 @@ def test_submapper_standard_actions(self): e.update() e.delete() - eq_('/entries', url_for('entries', method='GET')) - eq_('/entries', url_for('create_entry', method='POST')) - assert_raises(Exception, url_for, 'entries', method='DELETE') + assert url_for('entries', method='GET') == '/entries' + assert url_for('create_entry', method='POST') == '/entries' + with pytest.raises(Exception): + url_for('entries', method='DELETE') - eq_('/entries/1', url_for('entry', id=1, method='GET')) - eq_('/entries/1', url_for('update_entry', id=1, method='PUT')) - eq_('/entries/1', url_for('delete_entry', id=1, method='DELETE')) - assert_raises(Exception, url_for, 'entry', id=1, method='POST') + assert url_for('entry', id=1, method='GET') == '/entries/1' + assert url_for('update_entry', id=1, method='PUT') == '/entries/1' + assert url_for('delete_entry', id=1, method='DELETE') == '/entries/1' + with pytest.raises(Exception): + url_for('entry', id=1, method='POST') def test_submapper_standard_links(self): m = Mapper() @@ -91,11 +98,13 @@ def test_submapper_standard_links(self): c.new() e.edit() - eq_('/entries/new', url_for('new_entry', method='GET')) - assert_raises(Exception, url_for, 'new_entry', method='POST') + assert url_for('new_entry', method='GET') == '/entries/new' + with pytest.raises(Exception): + url_for('new_entry', method='POST') - eq_('/entries/1/edit', url_for('edit_entry', id=1, method='GET')) - assert_raises(Exception, url_for, 'edit_entry', id=1, method='POST') + assert url_for('edit_entry', id=1, method='GET') == '/entries/1/edit' + with pytest.raises(Exception): + url_for('edit_entry', id=1, method='POST') def test_submapper_action_and_link_generation(self): m = Mapper() @@ -105,39 +114,47 @@ def test_submapper_action_and_link_generation(self): e = c.submapper(path_prefix='/{id}', actions=['show', 'edit', 'update', 'delete']) - eq_('/entries', url_for('entries', method='GET')) - eq_('/entries', url_for('create_entry', method='POST')) - assert_raises(Exception, url_for, 'entries', method='DELETE') + assert url_for('entries', method='GET') == '/entries' + assert url_for('create_entry', method='POST') == '/entries' + with pytest.raises(Exception): + url_for('entries', method='DELETE') - eq_('/entries/1', url_for('entry', id=1, method='GET')) - eq_('/entries/1', url_for('update_entry', id=1, method='PUT')) - eq_('/entries/1', url_for('delete_entry', id=1, method='DELETE')) - assert_raises(Exception, url_for, 'entry', id=1, method='POST') + assert url_for('entry', id=1, method='GET') == '/entries/1' + assert url_for('update_entry', id=1, method='PUT') == '/entries/1' + assert url_for('delete_entry', id=1, method='DELETE') == '/entries/1' + with pytest.raises(Exception): + url_for('entry', id=1, method='POST') - eq_('/entries/new', url_for('new_entry', method='GET')) - assert_raises(Exception, url_for, 'new_entry', method='POST') + assert url_for('new_entry', method='GET') == '/entries/new' + with pytest.raises(Exception): + url_for('new_entry', method='POST') - eq_('/entries/1/edit', url_for('edit_entry', id=1, method='GET')) - assert_raises(Exception, url_for, 'edit_entry', id=1, method='POST') + assert url_for('edit_entry', id=1, method='GET') == '/entries/1/edit' + with pytest.raises(Exception): + url_for('edit_entry', id=1, method='POST') def test_collection(self): m = Mapper() c = m.collection('entries', 'entry') - eq_('/entries', url_for('entries', method='GET')) - eq_('/entries', url_for('create_entry', method='POST')) - assert_raises(Exception, url_for, 'entries', method='DELETE') + assert url_for('entries', method='GET') == '/entries' + assert url_for('create_entry', method='POST') == '/entries' + with pytest.raises(Exception): + url_for('entries', method='DELETE') - eq_('/entries/1', url_for('entry', id=1, method='GET')) - eq_('/entries/1', url_for('update_entry', id=1, method='PUT')) - eq_('/entries/1', url_for('delete_entry', id=1, method='DELETE')) - assert_raises(Exception, url_for, 'entry', id=1, method='POST') + assert url_for('entry', id=1, method='GET') == '/entries/1' + assert url_for('update_entry', id=1, method='PUT') == '/entries/1' + assert url_for('delete_entry', id=1, method='DELETE') == '/entries/1' + with pytest.raises(Exception): + url_for('entry', id=1, method='POST') - eq_('/entries/new', url_for('new_entry', method='GET')) - assert_raises(Exception, url_for, 'new_entry', method='POST') + assert url_for('new_entry', method='GET') == '/entries/new' + with pytest.raises(Exception): + url_for('new_entry', method='POST') - eq_('/entries/1/edit', url_for('edit_entry', id=1, method='GET')) - assert_raises(Exception, url_for, 'edit_entry', id=1, method='POST') + assert url_for('edit_entry', id=1, method='GET') == '/entries/1/edit' + with pytest.raises(Exception): + url_for('edit_entry', id=1, method='POST') def test_collection_options(self): m = Mapper() @@ -145,8 +162,8 @@ def test_collection_options(self): c = m.collection('entries', 'entry', conditions=dict(sub_domain=True), requirements=requirement) for r in m.matchlist: - eq_(True, r.conditions['sub_domain']) - eq_(requirement, r.reqs) + assert r.conditions['sub_domain'] is True + assert r.reqs == requirement def test_subsubmapper_with_controller(self): m = Mapper() @@ -158,7 +175,7 @@ def test_subsubmapper_with_controller(self): controller='col2', member_prefix='/{child_id}') match = m.match('/parents/1/children/2') - eq_('col2', match.get('controller')) + assert match.get('controller') == 'col2' def test_submapper_argument_overriding(self): m = Mapper() @@ -177,25 +194,24 @@ def test_submapper_argument_overriding(self): # test first level match = m.match('/first_level/test') - eq_('first', match.get('controller')) - eq_('test', match.get('action')) + assert match.get('controller') == 'first' + assert match.get('action') == 'test' # test name_prefix worked - eq_('/first_level/test', url_for('first_test')) + assert url_for('first_test') == '/first_level/test' # test second level controller override match = m.match('/first_level/second_level/test') - eq_('second', match.get('controller')) - eq_('test', match.get('action')) + assert match.get('controller') == 'second' + assert match.get('action') == 'test' # test name_prefix worked - eq_('/first_level/second_level/test', url_for('first_second_test')) + assert url_for('first_second_test') == '/first_level/second_level/test' # test third level controller and action override match = m.match('/first_level/second_level/third_level/test') - eq_('third', match.get('controller')) - eq_('third_action', match.get('action')) + assert match.get('controller') == 'third' + assert match.get('action') == 'third_action' # test name_prefix worked - eq_('/first_level/second_level/third_level/test', - url_for('first_second_third_test')) + assert url_for('first_second_third_test') == '/first_level/second_level/third_level/test' if __name__ == '__main__': diff --git a/tests/test_functional/test_utils.py b/tests/test_functional/test_utils.py index e2a6a04..d7b03a2 100644 --- a/tests/test_functional/test_utils.py +++ b/tests/test_functional/test_utils.py @@ -1,7 +1,7 @@ """test_utils""" import os, sys, time, unittest -from nose.tools import eq_, assert_raises +import pytest from routes.util import controller_scan, GenerationException from routes import * @@ -25,32 +25,32 @@ def test_url_for_with_nongen(self): con = self.con con.mapper_dict = {} - eq_('/blog', url_for('/blog')) - eq_('/blog?q=fred&q=here%20now', url_for('/blog', q=['fred', u'here now'])) - eq_('/blog#here', url_for('/blog', anchor='here')) + assert url_for('/blog') == '/blog' + assert url_for('/blog', q=['fred', u'here now']) == '/blog?q=fred&q=here%20now' + assert url_for('/blog', anchor='here') == '/blog#here' def test_url_for_with_nongen_no_encoding(self): con = self.con con.mapper_dict = {} con.mapper.encoding = None - eq_('/blog', url_for('/blog')) - eq_('/blog#here', url_for('/blog', anchor='here')) + assert url_for('/blog') == '/blog' + assert url_for('/blog', anchor='here') == '/blog#here' def test_url_for_with_unicode(self): con = self.con con.mapper_dict = {} - eq_('/blog', url_for(controller='blog')) - eq_('/blog/view/umulat', url_for(controller='blog', action='view', id=u'umulat')) - eq_('/blog/view/umulat?other=%CE%B1%CF%83%CE%B4%CE%B3', - url_for(controller='blog', action='view', id=u'umulat', other=u'\u03b1\u03c3\u03b4\u03b3')) + assert url_for(controller='blog') == '/blog' + assert url_for(controller='blog', action='view', id=u'umulat') == '/blog/view/umulat' + assert url_for(controller='blog', action='view', id=u'umulat', other=u'\u03b1\u03c3\u03b4\u03b3') == '/blog/view/umulat?other=%CE%B1%CF%83%CE%B4%CE%B3' url = URLGenerator(con.mapper, {}) for urlobj in [url_for, url]: def raise_url(): return urlobj(u'/some/st\xc3rng') - assert_raises(Exception, raise_url) + with pytest.raises(Exception): + raise_url() def test_url_for(self): con = self.con @@ -58,73 +58,75 @@ def test_url_for(self): url = URLGenerator(con.mapper, {'HTTP_HOST':'www.test.com:80'}) for urlobj in [url_for, url]: - eq_('/blog', urlobj(controller='blog')) - eq_('/content', urlobj()) - eq_('https://www.test.com/viewpost', urlobj(controller='post', action='view', protocol='https')) - eq_('http://www.test.org/content', urlobj(host='www.test.org')) - eq_('//www.test.com/viewpost', urlobj(controller='post', action='view', protocol='')) - eq_('//www.test.org/content', urlobj(host='www.test.org', protocol='')) + assert urlobj(controller='blog') == '/blog' + assert urlobj() == '/content' + assert urlobj(controller='post', action='view', protocol='https') == 'https://www.test.com/viewpost' + assert urlobj(host='www.test.org') == 'http://www.test.org/content' + assert urlobj(controller='post', action='view', protocol='') == '//www.test.com/viewpost' + assert urlobj(host='www.test.org', protocol='') == '//www.test.org/content' def test_url_raises(self): con = self.con con.mapper.explicit = True con.mapper_dict = {} url = URLGenerator(con.mapper, {}) - assert_raises(GenerationException, url_for, action='juice') - assert_raises(GenerationException, url, action='juice') + with pytest.raises(GenerationException): + url_for(action='juice') + with pytest.raises(GenerationException): + url(action='juice') def test_url_for_with_defaults(self): con = self.con con.mapper_dict = {'controller':'blog','action':'view','id':4} url = URLGenerator(con.mapper, {'wsgiorg.routing_args':((), con.mapper_dict)}) - eq_('/blog/view/4', url_for()) - eq_('/post/index/4', url_for(controller='post')) - eq_('/blog/view/2', url_for(id=2)) - eq_('/viewpost/4', url_for(controller='post', action='view', id=4)) + assert url_for() == '/blog/view/4' + assert url_for(controller='post') == '/post/index/4' + assert url_for(id=2) == '/blog/view/2' + assert url_for(controller='post', action='view', id=4) == '/viewpost/4' - eq_('/blog/view/4', url.current()) - eq_('/post/index/4', url.current(controller='post')) - eq_('/blog/view/2', url.current(id=2)) - eq_('/viewpost/4', url.current(controller='post', action='view', id=4)) + assert url.current() == '/blog/view/4' + assert url.current(controller='post') == '/post/index/4' + assert url.current(id=2) == '/blog/view/2' + assert url.current(controller='post', action='view', id=4) == '/viewpost/4' con.mapper_dict = {'controller':'blog','action':'view','year':2004} url = URLGenerator(con.mapper, {'wsgiorg.routing_args':((), con.mapper_dict)}) - eq_('/archive/2004/10', url_for(month=10)) - eq_('/archive/2004/9/2', url_for(month=9, day=2)) - eq_('/blog', url_for(controller='blog', year=None)) + assert url_for(month=10) == '/archive/2004/10' + assert url_for(month=9, day=2) == '/archive/2004/9/2' + assert url_for(controller='blog', year=None) == '/blog' - eq_('/archive/2004/10', url.current(month=10)) - eq_('/archive/2004/9/2', url.current(month=9, day=2)) - eq_('/blog', url.current(controller='blog', year=None)) + assert url.current(month=10) == '/archive/2004/10' + assert url.current(month=9, day=2) == '/archive/2004/9/2' + assert url.current(controller='blog', year=None) == '/blog' def test_url_for_with_more_defaults(self): con = self.con con.mapper_dict = {'controller':'blog','action':'view','id':4} url = URLGenerator(con.mapper, {'wsgiorg.routing_args':((), con.mapper_dict)}) - eq_('/blog/view/4', url_for()) - eq_('/post/index/4', url_for(controller='post')) - eq_('/blog/view/2', url_for(id=2)) - eq_('/viewpost/4', url_for(controller='post', action='view', id=4)) + assert url_for() == '/blog/view/4' + assert url_for(controller='post') == '/post/index/4' + assert url_for(id=2) == '/blog/view/2' + assert url_for(controller='post', action='view', id=4) == '/viewpost/4' - eq_('/blog/view/4', url.current()) - eq_('/post/index/4', url.current(controller='post')) - eq_('/blog/view/2', url.current(id=2)) - eq_('/viewpost/4', url.current(controller='post', action='view', id=4)) + assert url.current() == '/blog/view/4' + assert url.current(controller='post') == '/post/index/4' + assert url.current(id=2) == '/blog/view/2' + assert url.current(controller='post', action='view', id=4) == '/viewpost/4' con.mapper_dict = {'controller':'blog','action':'view','year':2004} url = URLGenerator(con.mapper, {'wsgiorg.routing_args':((), con.mapper_dict)}) - eq_('/archive/2004/10', url_for(month=10)) - eq_('/archive/2004/9/2', url_for(month=9, day=2)) - eq_('/blog', url_for(controller='blog', year=None)) - eq_('/archive/2004', url_for()) + assert url_for(month=10) == '/archive/2004/10' + assert url_for(month=9, day=2) == '/archive/2004/9/2' + assert url_for(controller='blog', year=None) == '/blog' + assert url_for() == '/archive/2004' - eq_('/archive/2004/10', url.current(month=10)) - eq_('/archive/2004/9/2', url.current(month=9, day=2)) - eq_('/blog', url.current(controller='blog', year=None)) - eq_('/archive/2004', url.current()) + assert url.current(month=10) == '/archive/2004/10' + assert url.current(month=9, day=2) == '/archive/2004/9/2' + assert url.current(controller='blog', year=None) == '/blog' + assert url.current() == '/archive/2004' def test_url_for_with_defaults_and_qualified(self): m = self.con.mapper @@ -136,17 +138,17 @@ def test_url_for_with_defaults_and_qualified(self): self.con.environ.update({'wsgiorg.routing_args':((), self.con.mapper_dict)}) url = URLGenerator(m, self.con.environ) - eq_('/blog/view/4', url_for()) - eq_('/post/index/4', url_for(controller='post')) - eq_('http://www.example.com/blog/view/4', url_for(qualified=True)) - eq_('/blog/view/2', url_for(id=2)) - eq_('/viewpost/4', url_for(controller='post', action='view', id=4)) + assert url_for() == '/blog/view/4' + assert url_for(controller='post') == '/post/index/4' + assert url_for(qualified=True) == 'http://www.example.com/blog/view/4' + assert url_for(id=2) == '/blog/view/2' + assert url_for(controller='post', action='view', id=4) == '/viewpost/4' - eq_('/blog/view/4', url.current()) - eq_('/post/index/4', url.current(controller='post')) - eq_('http://www.example.com/blog/view/4', url.current(qualified=True)) - eq_('/blog/view/2', url.current(id=2)) - eq_('/viewpost/4', url.current(controller='post', action='view', id=4)) + assert url.current() == '/blog/view/4' + assert url.current(controller='post') == '/post/index/4' + assert url.current(qualified=True) == 'http://www.example.com/blog/view/4' + assert url.current(id=2) == '/blog/view/2' + assert url.current(controller='post', action='view', id=4) == '/viewpost/4' env = dict(SCRIPT_NAME='', SERVER_NAME='www.example.com', SERVER_PORT='8080', PATH_INFO='/blog/view/4') env['wsgi.url_scheme'] = 'http' @@ -154,18 +156,18 @@ def test_url_for_with_defaults_and_qualified(self): self.con.environ.update({'wsgiorg.routing_args':((), self.con.mapper_dict)}) url = URLGenerator(m, self.con.environ) - eq_('/post/index/4', url_for(controller='post')) - eq_('http://www.example.com:8080/blog/view/4', url_for(qualified=True)) + assert url_for(controller='post') == '/post/index/4' + assert url_for(qualified=True) == 'http://www.example.com:8080/blog/view/4' - eq_('/post/index/4', url.current(controller='post')) - eq_('http://www.example.com:8080/blog/view/4', url.current(qualified=True)) + assert url.current(controller='post') == '/post/index/4' + assert url.current(qualified=True) == 'http://www.example.com:8080/blog/view/4' def test_route_overflow(self): m = self.con.mapper m.create_regs(["x"*50000]) m.connect('route-overflow', "x"*50000) url = URLGenerator(m, {}) - eq_("/%s" % ("x"*50000), url('route-overflow')) + assert url('route-overflow') == "/%s" % ("x"*50000) def test_with_route_names(self): m = self.con.mapper @@ -176,12 +178,12 @@ def test_with_route_names(self): url = URLGenerator(m, {}) for urlobj in [url, url_for]: - eq_('/content/view', urlobj(controller='content', action='view')) - eq_('/content', urlobj(controller='content')) - eq_('/admin/comments', urlobj(controller='admin/comments')) - eq_('/category', urlobj('category_home')) - eq_('/category/food', urlobj('category_home', section='food')) - eq_('/', urlobj('home')) + assert urlobj(controller='content', action='view') == '/content/view' + assert urlobj(controller='content') == '/content' + assert urlobj(controller='admin/comments') == '/admin/comments' + assert urlobj('category_home') == '/category' + assert urlobj('category_home', section='food') == '/category/food' + assert urlobj('home') == '/' def test_with_route_names_and_defaults(self): m = self.con.mapper @@ -194,10 +196,10 @@ def test_with_route_names_and_defaults(self): self.con.mapper_dict = dict(controller='building', action='showjacks', campus='wilma', building='port') url = URLGenerator(m, {'wsgiorg.routing_args':((), self.con.mapper_dict)}) - eq_('/building/wilma/port/alljacks', url_for()) - eq_('/', url_for('home')) - eq_('/building/wilma/port/alljacks', url.current()) - eq_('/', url.current('home')) + assert url_for() == '/building/wilma/port/alljacks' + assert url_for('home') == '/' + assert url.current() == '/building/wilma/port/alljacks' + assert url.current('home') == '/' def test_with_route_names_and_hardcode(self): m = self.con.mapper @@ -213,22 +215,22 @@ def test_with_route_names_and_hardcode(self): self.con.mapper_dict = dict(controller='building', action='showjacks', campus='wilma', building='port') url = URLGenerator(m, {'wsgiorg.routing_args':((), self.con.mapper_dict)}) - eq_('/building/wilma/port/alljacks', url_for()) - eq_('/', url_for('home')) - eq_('/gallery/home_thumbnail.jpg', url_for('gallery_thumb', img_id='home')) - eq_('/gallery/home_thumbnail.jpg', url_for('gallery', img_id='home')) + assert url_for() == '/building/wilma/port/alljacks' + assert url_for('home') == '/' + assert url_for('gallery_thumb', img_id='home') == '/gallery/home_thumbnail.jpg' + assert url_for('gallery', img_id='home') == '/gallery/home_thumbnail.jpg' - eq_('/building/wilma/port/alljacks', url.current()) - eq_('/', url.current('home')) - eq_('/gallery/home_thumbnail.jpg', url.current('gallery_thumb', img_id='home')) - eq_('/gallery/home_thumbnail.jpg', url.current('gallery', img_id='home')) + assert url.current() == '/building/wilma/port/alljacks' + assert url.current('home') == '/' + assert url.current('gallery_thumb', img_id='home') == '/gallery/home_thumbnail.jpg' + assert url.current('gallery', img_id='home') == '/gallery/home_thumbnail.jpg' m.hardcode_names = True - eq_('/gallery/home_thumbnail.jpg', url_for('gallery_thumb', img_id='home')) - eq_('/gallery/home.jpg', url_for('gallery', img_id='home')) + assert url_for('gallery_thumb', img_id='home') == '/gallery/home_thumbnail.jpg' + assert url_for('gallery', img_id='home') == '/gallery/home.jpg' - eq_('/gallery/home_thumbnail.jpg', url.current('gallery_thumb', img_id='home')) - eq_('/gallery/home.jpg', url.current('gallery', img_id='home')) + assert url.current('gallery_thumb', img_id='home') == '/gallery/home_thumbnail.jpg' + assert url.current('gallery', img_id='home') == '/gallery/home.jpg' m.hardcode_names = False def test_redirect_to(self): @@ -242,15 +244,15 @@ def printer(echo): m.create_regs(['content','blog','admin/comments']) redirect_to(controller='content', action='view') - eq_('/content/view', redirect_to.result) + assert redirect_to.result == '/content/view' redirect_to(controller='content', action='lookup', id=4) - eq_('/content/lookup/4', redirect_to.result) + assert redirect_to.result == '/content/lookup/4' redirect_to(controller='admin/comments',action='splash') - eq_('/admin/comments/splash', redirect_to.result) + assert redirect_to.result == '/admin/comments/splash' redirect_to('http://www.example.com/') - eq_('http://www.example.com/', redirect_to.result) + assert redirect_to.result == 'http://www.example.com/' redirect_to('/somewhere.html', var='keyword') - eq_('/somewhere.html?var=keyword', redirect_to.result) + assert redirect_to.result == '/somewhere.html?var=keyword' def test_redirect_to_with_route_names(self): m = self.con.mapper @@ -264,17 +266,17 @@ def printer(echo): m.create_regs(['content','blog','admin/comments']) redirect_to(controller='content', action='view') - eq_('/content/view', redirect_to.result) + assert redirect_to.result == '/content/view' redirect_to(controller='content') - eq_('/content', redirect_to.result) + assert redirect_to.result == '/content' redirect_to(controller='admin/comments') - eq_('/admin/comments', redirect_to.result) + assert redirect_to.result == '/admin/comments' redirect_to('category_home') - eq_('/category', redirect_to.result) + assert redirect_to.result == '/category' redirect_to('category_home', section='food') - eq_('/category/food', redirect_to.result) + assert redirect_to.result == '/category/food' redirect_to('home') - eq_('/', redirect_to.result) + assert redirect_to.result == '/' def test_static_route(self): m = self.con.mapper @@ -287,10 +289,10 @@ def test_static_route(self): url = URLGenerator(m, {}) for urlobj in [url_for, url]: - eq_('http://www.groovie.org/', urlobj('home')) - eq_('http://www.groovie.org/?s=stars', urlobj('home', s='stars')) - eq_('/content/view', urlobj(controller='content', action='view')) - eq_('/nasa/images?search=all', urlobj('space', search='all')) + assert urlobj('home') == 'http://www.groovie.org/' + assert urlobj('home', s='stars') == 'http://www.groovie.org/?s=stars' + assert urlobj(controller='content', action='view') == '/content/view' + assert urlobj('space', search='all') == '/nasa/images?search=all' def test_static_route_with_script(self): m = self.con.mapper @@ -305,12 +307,12 @@ def test_static_route_with_script(self): self.con.environ.update({'wsgiorg.routing_args':((), {})}) url = URLGenerator(m, self.con.environ) for urlobj in [url_for, url]: - eq_('http://www.groovie.org/', urlobj('home')) - eq_('http://www.groovie.org/?s=stars', urlobj('home', s='stars')) - eq_('/webapp/content/view', urlobj(controller='content', action='view')) - eq_('/webapp/nasa/images?search=all', urlobj('space', search='all')) - eq_('http://example.com/webapp/nasa/images', urlobj('space', protocol='http')) - eq_('http://example.com/webapp/login', urlobj('login', qualified=True)) + assert urlobj('home') == 'http://www.groovie.org/' + assert urlobj('home', s='stars') == 'http://www.groovie.org/?s=stars' + assert urlobj(controller='content', action='view') == '/webapp/content/view' + assert urlobj('space', search='all') == '/webapp/nasa/images?search=all' + assert urlobj('space', protocol='http') == 'http://example.com/webapp/nasa/images' + assert urlobj('login', qualified=True) == 'http://example.com/webapp/login' def test_static_route_with_vars(self): m = self.con.mapper @@ -323,13 +325,16 @@ def test_static_route_with_vars(self): self.con.environ.update({'wsgiorg.routing_args':((), {})}) url = URLGenerator(m, self.con.environ) for urlobj in [url_for, url]: - assert_raises(GenerationException, urlobj, 'home') - assert_raises(GenerationException, urlobj, 'home', domain='fred') - assert_raises(GenerationException, urlobj, 'home', location='index') - eq_('http://fred.groovie.org/index', urlobj('home', domain='fred', location='index')) - eq_('http://fred.groovie.org/index?search=all', urlobj('home', domain='fred', location='index', search='all')) - eq_('/webapp/nasa/images?search=all', urlobj('space', location='images', search='all')) - eq_('http://example.com/webapp/nasa/images', urlobj('space', location='images', protocol='http')) + with pytest.raises(GenerationException): + urlobj('home') + with pytest.raises(GenerationException): + urlobj('home', domain='fred') + with pytest.raises(GenerationException): + urlobj('home', location='index') + assert urlobj('home', domain='fred', location='index') == 'http://fred.groovie.org/index' + assert urlobj('home', domain='fred', location='index', search='all') == 'http://fred.groovie.org/index?search=all' + assert urlobj('space', location='images', search='all') == '/webapp/nasa/images?search=all' + assert urlobj('space', location='images', protocol='http') == 'http://example.com/webapp/nasa/images' def test_static_route_with_vars_and_defaults(self): m = self.con.mapper @@ -342,27 +347,31 @@ def test_static_route_with_vars_and_defaults(self): self.con.environ.update({'wsgiorg.routing_args':((), {})}) url = URLGenerator(m, self.con.environ) - assert_raises(GenerationException, url_for, 'home') - assert_raises(GenerationException, url_for, 'home', domain='fred') - eq_('http://routes.groovie.org/index', url_for('home', location='index')) - eq_('http://fred.groovie.org/index', url_for('home', domain='fred', location='index')) - eq_('http://routes.groovie.org/index?search=all', url_for('home', location='index', search='all')) - eq_('http://fred.groovie.org/index?search=all', url_for('home', domain='fred', location='index', search='all')) - eq_('/webapp/nasa/articles?search=all', url_for('space', location='articles', search='all')) - eq_('http://example.com/webapp/nasa/articles', url_for('space', location='articles', protocol='http')) - eq_('/webapp/nasa/images?search=all', url_for('space', search='all')) - eq_('http://example.com/webapp/nasa/images', url_for('space', protocol='http')) - - assert_raises(GenerationException, url.current, 'home') - assert_raises(GenerationException, url.current, 'home', domain='fred') - eq_('http://routes.groovie.org/index', url.current('home', location='index')) - eq_('http://fred.groovie.org/index', url.current('home', domain='fred', location='index')) - eq_('http://routes.groovie.org/index?search=all', url.current('home', location='index', search='all')) - eq_('http://fred.groovie.org/index?search=all', url.current('home', domain='fred', location='index', search='all')) - eq_('/webapp/nasa/articles?search=all', url.current('space', location='articles', search='all')) - eq_('http://example.com/webapp/nasa/articles', url.current('space', location='articles', protocol='http')) - eq_('/webapp/nasa/images?search=all', url.current('space', search='all')) - eq_('http://example.com/webapp/nasa/images', url.current('space', protocol='http')) + with pytest.raises(GenerationException): + url_for('home') + with pytest.raises(GenerationException): + url_for('home', domain='fred') + assert url_for('home', location='index') == 'http://routes.groovie.org/index' + assert url_for('home', domain='fred', location='index') == 'http://fred.groovie.org/index' + assert url_for('home', location='index', search='all') == 'http://routes.groovie.org/index?search=all' + assert url_for('home', domain='fred', location='index', search='all') == 'http://fred.groovie.org/index?search=all' + assert url_for('space', location='articles', search='all') == '/webapp/nasa/articles?search=all' + assert url_for('space', location='articles', protocol='http') == 'http://example.com/webapp/nasa/articles' + assert url_for('space', search='all') == '/webapp/nasa/images?search=all' + assert url_for('space', protocol='http') == 'http://example.com/webapp/nasa/images' + + with pytest.raises(GenerationException): + url.current('home') + with pytest.raises(GenerationException): + url.current('home', domain='fred') + assert url.current('home', location='index') == 'http://routes.groovie.org/index' + assert url.current('home', domain='fred', location='index') == 'http://fred.groovie.org/index' + assert url.current('home', location='index', search='all') == 'http://routes.groovie.org/index?search=all' + assert url.current('home', domain='fred', location='index', search='all') == 'http://fred.groovie.org/index?search=all' + assert url.current('space', location='articles', search='all') == '/webapp/nasa/articles?search=all' + assert url.current('space', location='articles', protocol='http') == 'http://example.com/webapp/nasa/articles' + assert url.current('space', search='all') == '/webapp/nasa/images?search=all' + assert url.current('space', protocol='http') == 'http://example.com/webapp/nasa/images' def test_static_route_with_vars_and_requirements(self): @@ -377,31 +386,43 @@ def test_static_route_with_vars_and_requirements(self): self.con.environ.update({'wsgiorg.routing_args':((), {})}) url = URLGenerator(m, self.con.environ) - assert_raises(GenerationException, url_for, 'home', domain='george', location='index') - assert_raises(GenerationException, url_for, 'space', year='asdf', month='1') - assert_raises(GenerationException, url_for, 'space', year='2004', month='a') - assert_raises(GenerationException, url_for, 'space', year='1', month='1') - assert_raises(GenerationException, url_for, 'space', year='20045', month='1') - assert_raises(GenerationException, url_for, 'space', year='2004', month='123') - eq_('http://fred.groovie.org/index', url_for('home', domain='fred', location='index')) - eq_('http://bob.groovie.org/index', url_for('home', domain='bob', location='index')) - eq_('http://fred.groovie.org/asdf', url_for('home', domain='fred', location='asdf')) - eq_('/webapp/nasa/articles/2004/6', url_for('space', year='2004', month='6')) - eq_('/webapp/nasa/articles/2004/12', url_for('space', year='2004', month='12')) - eq_('/webapp/nasa/articles/89/6', url_for('space', year='89', month='6')) - - assert_raises(GenerationException, url.current, 'home', domain='george', location='index') - assert_raises(GenerationException, url.current, 'space', year='asdf', month='1') - assert_raises(GenerationException, url.current, 'space', year='2004', month='a') - assert_raises(GenerationException, url.current, 'space', year='1', month='1') - assert_raises(GenerationException, url.current, 'space', year='20045', month='1') - assert_raises(GenerationException, url.current, 'space', year='2004', month='123') - eq_('http://fred.groovie.org/index', url.current('home', domain='fred', location='index')) - eq_('http://bob.groovie.org/index', url.current('home', domain='bob', location='index')) - eq_('http://fred.groovie.org/asdf', url.current('home', domain='fred', location='asdf')) - eq_('/webapp/nasa/articles/2004/6', url.current('space', year='2004', month='6')) - eq_('/webapp/nasa/articles/2004/12', url.current('space', year='2004', month='12')) - eq_('/webapp/nasa/articles/89/6', url.current('space', year='89', month='6')) + with pytest.raises(GenerationException): + url_for('home', domain='george', location='index') + with pytest.raises(GenerationException): + url_for('space', year='asdf', month='1') + with pytest.raises(GenerationException): + url_for('space', year='2004', month='a') + with pytest.raises(GenerationException): + url_for('space', year='1', month='1') + with pytest.raises(GenerationException): + url_for('space', year='20045', month='1') + with pytest.raises(GenerationException): + url_for('space', year='2004', month='123') + assert url_for('home', domain='fred', location='index') == 'http://fred.groovie.org/index' + assert url_for('home', domain='bob', location='index') == 'http://bob.groovie.org/index' + assert url_for('home', domain='fred', location='asdf') == 'http://fred.groovie.org/asdf' + assert url_for('space', year='2004', month='6') == '/webapp/nasa/articles/2004/6' + assert url_for('space', year='2004', month='12') == '/webapp/nasa/articles/2004/12' + assert url_for('space', year='89', month='6') == '/webapp/nasa/articles/89/6' + + with pytest.raises(GenerationException): + url.current('home', domain='george', location='index') + with pytest.raises(GenerationException): + url.current('space', year='asdf', month='1') + with pytest.raises(GenerationException): + url.current('space', year='2004', month='a') + with pytest.raises(GenerationException): + url.current('space', year='1', month='1') + with pytest.raises(GenerationException): + url.current('space', year='20045', month='1') + with pytest.raises(GenerationException): + url.current('space', year='2004', month='123') + assert url.current('home', domain='fred', location='index') == 'http://fred.groovie.org/index' + assert url.current('home', domain='bob', location='index') == 'http://bob.groovie.org/index' + assert url.current('home', domain='fred', location='asdf') == 'http://fred.groovie.org/asdf' + assert url.current('space', year='2004', month='6') == '/webapp/nasa/articles/2004/6' + assert url.current('space', year='2004', month='12') == '/webapp/nasa/articles/2004/12' + assert url.current('space', year='89', month='6') == '/webapp/nasa/articles/89/6' def test_no_named_path(self): m = self.con.mapper @@ -414,10 +435,10 @@ def test_no_named_path(self): url = URLGenerator(m, {}) for urlobj in [url_for, url]: - eq_('http://www.google.com/search', urlobj('http://www.google.com/search')) - eq_('http://www.google.com/search?q=routes', urlobj('http://www.google.com/search', q='routes')) - eq_('/delicious.jpg', urlobj('/delicious.jpg')) - eq_('/delicious/search?v=routes', urlobj('/delicious/search', v='routes')) + assert urlobj('http://www.google.com/search') == 'http://www.google.com/search' + assert urlobj('http://www.google.com/search', q='routes') == 'http://www.google.com/search?q=routes' + assert urlobj('/delicious.jpg') == '/delicious.jpg' + assert urlobj('/delicious/search', v='routes') == '/delicious/search?v=routes' def test_append_slash(self): m = self.con.mapper @@ -431,12 +452,12 @@ def test_append_slash(self): url = URLGenerator(m, {}) for urlobj in [url_for, url]: - eq_('http://www.google.com/search', urlobj('http://www.google.com/search')) - eq_('http://www.google.com/search?q=routes', urlobj('http://www.google.com/search', q='routes')) - eq_('/delicious.jpg', urlobj('/delicious.jpg')) - eq_('/delicious/search?v=routes', urlobj('/delicious/search', v='routes')) - eq_('/content/list/', urlobj(controller='/content', action='list')) - eq_('/content/list/?page=1', urlobj(controller='/content', action='list', page='1')) + assert urlobj('http://www.google.com/search') == 'http://www.google.com/search' + assert urlobj('http://www.google.com/search', q='routes') == 'http://www.google.com/search?q=routes' + assert urlobj('/delicious.jpg') == '/delicious.jpg' + assert urlobj('/delicious/search', v='routes') == '/delicious/search?v=routes' + assert urlobj(controller='/content', action='list') == '/content/list/' + assert urlobj(controller='/content', action='list', page='1') == '/content/list/?page=1' def test_no_named_path_with_script(self): m = self.con.mapper @@ -449,10 +470,10 @@ def test_no_named_path_with_script(self): url = URLGenerator(m, self.con.environ) for urlobj in [url_for, url]: - eq_('http://www.google.com/search', urlobj('http://www.google.com/search')) - eq_('http://www.google.com/search?q=routes', urlobj('http://www.google.com/search', q='routes')) - eq_('/webapp/delicious.jpg', urlobj('/delicious.jpg')) - eq_('/webapp/delicious/search?v=routes', urlobj('/delicious/search', v='routes')) + assert urlobj('http://www.google.com/search') == 'http://www.google.com/search' + assert urlobj('http://www.google.com/search', q='routes') == 'http://www.google.com/search?q=routes' + assert urlobj('/delicious.jpg') == '/webapp/delicious.jpg' + assert urlobj('/delicious/search', v='routes') == '/webapp/delicious/search?v=routes' def test_route_filter(self): def article_filter(kargs): @@ -480,20 +501,20 @@ def article_filter(kargs): url = URLGenerator(m, self.con.environ) for urlobj in [url_for, url]: - assert_raises(Exception, urlobj, controller='content', action='view') - assert_raises(Exception, urlobj, controller='content') + with pytest.raises(Exception): + urlobj(controller='content', action='view') + with pytest.raises(Exception): + urlobj(controller='content') - eq_('/content/view-3.html', urlobj(controller='content', action='view', id=3)) - eq_('/content/index-2.html', urlobj(controller='content', id=2)) + assert urlobj(controller='content', action='view', id=3) == '/content/view-3.html' + assert urlobj(controller='content', id=2) == '/content/index-2.html' - eq_('/archives/2005/10/5/happy', - urlobj('archives',year=2005, month=10, day=5, slug='happy')) + assert urlobj('archives', year=2005, month=10, day=5, slug='happy') == '/archives/2005/10/5/happy' story = dict(year=2003, month=8, day=2, slug='woopee') empty = {} - eq_({'controller':'archives','action':'view','year':'2005', - 'month':'10','day':'5','slug':'happy'}, m.match('/archives/2005/10/5/happy')) - eq_('/archives/2003/8/2/woopee', urlobj('archives', article=story)) - eq_('/archives/2004/12/20/default', urlobj('archives', article=empty)) + assert m.match('/archives/2005/10/5/happy') == {'controller':'archives','action':'view','year':'2005','month':'10','day':'5','slug':'happy'} + assert urlobj('archives', article=story) == '/archives/2003/8/2/woopee' + assert urlobj('archives', article=empty) == '/archives/2004/12/20/default' def test_with_ssl_environ(self): base_environ = dict(SCRIPT_NAME='', HTTPS='on', SERVER_PORT='443', PATH_INFO='/', @@ -512,21 +533,21 @@ def test_with_ssl_environ(self): for urlobj in [url_for, url]: # HTTPS is on, but we're running on a different port internally - eq_(self.con.protocol, 'https') - eq_('/content/view', urlobj(controller='content', action='view')) - eq_('/content/index/2', urlobj(controller='content', id=2)) - eq_('https://nowhere.com/content', urlobj(host='nowhere.com', controller='content')) + assert self.con.protocol == 'https' + assert urlobj(controller='content', action='view') == '/content/view' + assert urlobj(controller='content', id=2) == '/content/index/2' + assert urlobj(host='nowhere.com', controller='content') == 'https://nowhere.com/content' # If HTTPS is on, but the port isn't 443, we'll need to include the port info environ = base_environ.copy() environ.update(dict(SERVER_PORT='8080')) self.con.environ = environ self.con.mapper_dict = {} - eq_('/content/index/2', urlobj(controller='content', id=2)) - eq_('https://nowhere.com/content', urlobj(host='nowhere.com', controller='content')) - eq_('https://nowhere.com:8080/content', urlobj(host='nowhere.com:8080', controller='content')) - eq_('http://nowhere.com/content', urlobj(host='nowhere.com', protocol='http', controller='content')) - eq_('http://home.com/content', urlobj(host='home.com', protocol='http', controller='content')) + assert urlobj(controller='content', id=2) == '/content/index/2' + assert urlobj(host='nowhere.com', controller='content') == 'https://nowhere.com/content' + assert urlobj(host='nowhere.com:8080', controller='content') == 'https://nowhere.com:8080/content' + assert urlobj(host='nowhere.com', protocol='http', controller='content') == 'http://nowhere.com/content' + assert urlobj(host='home.com', protocol='http', controller='content') == 'http://home.com/content' def test_with_http_environ(self): @@ -544,10 +565,10 @@ def test_with_http_environ(self): url = URLGenerator(m, self.con.environ) for urlobj in [url_for, url]: - eq_(self.con.protocol, 'http') - eq_('/content/view', urlobj(controller='content', action='view')) - eq_('/content/index/2', urlobj(controller='content', id=2)) - eq_('https://example.com/content', urlobj(protocol='https', controller='content')) + assert self.con.protocol == 'http' + assert urlobj(controller='content', action='view') == '/content/view' + assert urlobj(controller='content', id=2) == '/content/index/2' + assert urlobj(protocol='https', controller='content') == 'https://example.com/content' def test_subdomains(self): @@ -564,14 +585,14 @@ def test_subdomains(self): url = URLGenerator(m, self.con.environ) for urlobj in [url_for, url]: - eq_('/content/view', urlobj(controller='content', action='view')) - eq_('/content/index/2', urlobj(controller='content', id=2)) + assert urlobj(controller='content', action='view') == '/content/view' + assert urlobj(controller='content', id=2) == '/content/index/2' environ = base_environ.copy() environ.update(dict(HTTP_HOST='sub.example.com')) self.con.environ = environ self.con.mapper_dict = {'sub_domain':'sub'} - eq_('/content/view/3', urlobj(controller='content', action='view', id=3)) - eq_('http://new.example.com/content', urlobj(controller='content', sub_domain='new')) + assert urlobj(controller='content', action='view', id=3) == '/content/view/3' + assert urlobj(controller='content', sub_domain='new') == 'http://new.example.com/content' def test_subdomains_with_exceptions(self): base_environ = dict(SCRIPT_NAME='', PATH_INFO='/', HTTP_HOST='example.com', SERVER_NAME='example.com') @@ -587,10 +608,10 @@ def test_subdomains_with_exceptions(self): self.con.mapper = m url = URLGenerator(m, self.con.environ) - eq_('/content/view', url_for(controller='content', action='view')) - eq_('/content/index/2', url_for(controller='content', id=2)) - eq_('/content/view', url(controller='content', action='view')) - eq_('/content/index/2', url(controller='content', id=2)) + assert url_for(controller='content', action='view') == '/content/view' + assert url_for(controller='content', id=2) == '/content/index/2' + assert url(controller='content', action='view') == '/content/view' + assert url(controller='content', id=2) == '/content/index/2' environ = base_environ.copy() environ.update(dict(HTTP_HOST='sub.example.com')) @@ -599,25 +620,25 @@ def test_subdomains_with_exceptions(self): self.con.environ.update({'wsgiorg.routing_args':((), self.con.mapper_dict)}) url = URLGenerator(m, self.con.environ) - eq_('/content/view/3', url_for(controller='content', action='view', id=3)) - eq_('http://new.example.com/content', url_for(controller='content', sub_domain='new')) - eq_('http://example.com/content', url_for(controller='content', sub_domain='www')) - eq_('/content/view/3', url(controller='content', action='view', id=3)) - eq_('http://new.example.com/content', url(controller='content', sub_domain='new')) - eq_('http://example.com/content', url(controller='content', sub_domain='www')) + assert url_for(controller='content', action='view', id=3) == '/content/view/3' + assert url_for(controller='content', sub_domain='new') == 'http://new.example.com/content' + assert url_for(controller='content', sub_domain='www') == 'http://example.com/content' + assert url(controller='content', action='view', id=3) == '/content/view/3' + assert url(controller='content', sub_domain='new') == 'http://new.example.com/content' + assert url(controller='content', sub_domain='www') == 'http://example.com/content' self.con.mapper_dict = {'sub_domain':'www'} self.con.environ.update({'wsgiorg.routing_args':((), self.con.mapper_dict)}) url = URLGenerator(m, self.con.environ) - eq_('http://example.com/content/view/3', url_for(controller='content', action='view', id=3)) - eq_('http://new.example.com/content', url_for(controller='content', sub_domain='new')) - eq_('/content', url_for(controller='content', sub_domain='sub')) + assert url_for(controller='content', action='view', id=3) == 'http://example.com/content/view/3' + assert url_for(controller='content', sub_domain='new') == 'http://new.example.com/content' + assert url_for(controller='content', sub_domain='sub') == '/content' # This requires the sub-domain, because we don't automatically go to the existing match dict - eq_('http://example.com/content/view/3', url(controller='content', action='view', id=3, sub_domain='www')) - eq_('http://new.example.com/content', url(controller='content', sub_domain='new')) - eq_('/content', url(controller='content', sub_domain='sub')) + assert url(controller='content', action='view', id=3, sub_domain='www') == 'http://example.com/content/view/3' + assert url(controller='content', sub_domain='new') == 'http://new.example.com/content' + assert url(controller='content', sub_domain='sub') == '/content' def test_subdomains_with_named_routes(self): base_environ = dict(SCRIPT_NAME='', PATH_INFO='/', HTTP_HOST='example.com', SERVER_NAME='example.com') @@ -635,10 +656,10 @@ def test_subdomains_with_named_routes(self): url = URLGenerator(m, self.con.environ) for urlobj in [url_for, url]: - eq_('/content/view', urlobj(controller='content', action='view')) - eq_('/content/index/2', urlobj(controller='content', id=2)) - eq_('/category', urlobj('category_home')) - eq_('http://new.example.com/category', urlobj('category_home', sub_domain='new')) + assert urlobj(controller='content', action='view') == '/content/view' + assert urlobj(controller='content', id=2) == '/content/index/2' + assert urlobj('category_home') == '/category' + assert urlobj('category_home', sub_domain='new') == 'http://new.example.com/category' environ = base_environ.copy() environ.update(dict(HTTP_HOST='sub.example.com')) @@ -647,15 +668,13 @@ def test_subdomains_with_named_routes(self): self.con.environ.update({'wsgiorg.routing_args':((), self.con.mapper_dict)}) url = URLGenerator(m, self.con.environ) - eq_('/content/view/3', url_for(controller='content', action='view', id=3)) - eq_('http://joy.example.com/building/west/merlot/alljacks', - url_for('building', campus='west', building='merlot', sub_domain='joy')) - eq_('http://example.com/category/feeds', url_for('category_home', section='feeds', sub_domain=None)) + assert url_for(controller='content', action='view', id=3) == '/content/view/3' + assert url_for('building', campus='west', building='merlot', sub_domain='joy') == 'http://joy.example.com/building/west/merlot/alljacks' + assert url_for('category_home', section='feeds', sub_domain=None) == 'http://example.com/category/feeds' - eq_('/content/view/3', url(controller='content', action='view', id=3)) - eq_('http://joy.example.com/building/west/merlot/alljacks', - url('building', campus='west', building='merlot', sub_domain='joy')) - eq_('http://example.com/category/feeds', url('category_home', section='feeds', sub_domain=None)) + assert url(controller='content', action='view', id=3) == '/content/view/3' + assert url('building', campus='west', building='merlot', sub_domain='joy') == 'http://joy.example.com/building/west/merlot/alljacks' + assert url('category_home', section='feeds', sub_domain=None) == 'http://example.com/category/feeds' def test_subdomains_with_ports(self): @@ -675,15 +694,14 @@ def test_subdomains_with_ports(self): url = URLGenerator(m, self.con.environ) for urlobj in [url, url_for]: self.con.environ['HTTP_HOST'] = 'example.com:8000' - eq_('/content/view', urlobj(controller='content', action='view')) - eq_('/category', urlobj('category_home')) - eq_('http://new.example.com:8000/category', urlobj('category_home', sub_domain='new')) - eq_('http://joy.example.com:8000/building/west/merlot/alljacks', - urlobj('building', campus='west', building='merlot', sub_domain='joy')) + assert urlobj(controller='content', action='view') == '/content/view' + assert urlobj('category_home') == '/category' + assert urlobj('category_home', sub_domain='new') == 'http://new.example.com:8000/category' + assert urlobj('building', campus='west', building='merlot', sub_domain='joy') == 'http://joy.example.com:8000/building/west/merlot/alljacks' self.con.environ['HTTP_HOST'] = 'example.com' del self.con.environ['routes.cached_hostinfo'] - eq_('http://new.example.com/category', urlobj('category_home', sub_domain='new')) + assert urlobj('category_home', sub_domain='new') == 'http://new.example.com/category' def test_subdomains_with_default(self): base_environ = dict(SCRIPT_NAME='', PATH_INFO='/', HTTP_HOST='example.com:8000', SERVER_NAME='example.com') @@ -702,13 +720,14 @@ def test_subdomains_with_default(self): urlobj = URLGenerator(m, self.con.environ) self.con.environ['HTTP_HOST'] = 'example.com:8000' - eq_('/content/view', urlobj(controller='content', action='view')) - eq_('http://cat.example.com:8000/category', urlobj('category_home')) + assert urlobj(controller='content', action='view') == '/content/view' + assert urlobj('category_home') == 'http://cat.example.com:8000/category' self.con.environ['HTTP_HOST'] = 'example.com' del self.con.environ['routes.cached_hostinfo'] - assert_raises(GenerationException, lambda: urlobj('category_home', sub_domain='new')) + with pytest.raises(GenerationException): + urlobj('category_home', sub_domain='new') def test_controller_scan(self): @@ -716,10 +735,10 @@ def test_controller_scan(self): controller_dir = os.path.join(os.path.dirname(here_dir), os.path.join('test_files', 'controller_files')) controllers = controller_scan(controller_dir) - eq_(len(controllers), 3) - eq_(controllers[0], 'admin/users') - eq_(controllers[1], 'content') - eq_(controllers[2], 'users') + assert len(controllers) == 3 + assert controllers[0] == 'admin/users' + assert controllers[1] == 'content' + assert controllers[2] == 'users' def test_auto_controller_scan(self): here_dir = os.path.dirname(__file__) @@ -730,9 +749,9 @@ def test_auto_controller_scan(self): m.always_scan = True m.connect(':controller/:action/:id') - eq_({'action':'index', 'controller':'content','id':None}, m.match('/content')) - eq_({'action':'index', 'controller':'users','id':None}, m.match('/users')) - eq_({'action':'index', 'controller':'admin/users','id':None}, m.match('/admin/users')) + assert m.match('/content') == {'action':'index', 'controller':'content','id':None} + assert m.match('/users') == {'action':'index', 'controller':'users','id':None} + assert m.match('/admin/users') == {'action':'index', 'controller':'admin/users','id':None} class TestUtilsWithExplicit(unittest.TestCase): def setUp(self): @@ -752,38 +771,51 @@ def test_url_for(self): con = self.con con.mapper_dict = {} - assert_raises(Exception, url_for, controller='blog') - assert_raises(Exception, url_for) - eq_('/blog/view/3', url_for(controller='blog', action='view', id=3)) - eq_('https://www.test.com/viewpost', url_for(controller='post', action='view', protocol='https')) - eq_('http://www.test.org/content/view/2', url_for(host='www.test.org', controller='content', action='view', id=2)) + with pytest.raises(Exception): + url_for(controller='blog') + with pytest.raises(Exception): + url_for() + assert url_for(controller='blog', action='view', id=3) == '/blog/view/3' + assert url_for(controller='post', action='view', protocol='https') == 'https://www.test.com/viewpost' + assert url_for(host='www.test.org', controller='content', action='view', id=2) == 'http://www.test.org/content/view/2' def test_url_for_with_defaults(self): con = self.con con.mapper_dict = {'controller':'blog','action':'view','id':4} - assert_raises(Exception, url_for) - assert_raises(Exception, url_for, controller='post') - assert_raises(Exception, url_for, id=2) - eq_('/viewpost/4', url_for(controller='post', action='view', id=4)) + with pytest.raises(Exception): + url_for() + with pytest.raises(Exception): + url_for(controller='post') + with pytest.raises(Exception): + url_for(id=2) + assert url_for(controller='post', action='view', id=4) == '/viewpost/4' con.mapper_dict = {'controller':'blog','action':'view','year':2004} - assert_raises(Exception, url_for, month=10) - assert_raises(Exception, url_for, month=9, day=2) - assert_raises(Exception, url_for, controller='blog', year=None) + with pytest.raises(Exception): + url_for(month=10) + with pytest.raises(Exception): + url_for(month=9, day=2) + with pytest.raises(Exception): + url_for(controller='blog', year=None) def test_url_for_with_more_defaults(self): con = self.con con.mapper_dict = {'controller':'blog','action':'view','id':4} - assert_raises(Exception, url_for) - assert_raises(Exception, url_for, controller='post') - assert_raises(Exception, url_for, id=2) - eq_('/viewpost/4', url_for(controller='post', action='view', id=4)) + with pytest.raises(Exception): + url_for() + with pytest.raises(Exception): + url_for(controller='post') + with pytest.raises(Exception): + url_for(id=2) + assert url_for(controller='post', action='view', id=4) == '/viewpost/4' con.mapper_dict = {'controller':'blog','action':'view','year':2004} - assert_raises(Exception, url_for, month=10) - assert_raises(Exception, url_for) + with pytest.raises(Exception): + url_for(month=10) + with pytest.raises(Exception): + url_for() def test_url_for_with_defaults_and_qualified(self): m = self.con.mapper @@ -796,18 +828,23 @@ def test_url_for_with_defaults_and_qualified(self): self.con.environ = env - assert_raises(Exception, url_for) - assert_raises(Exception, url_for, controller='post') - assert_raises(Exception, url_for, id=2) - assert_raises(Exception, url_for, qualified=True, controller='blog', id=4) - eq_('http://www.example.com/blog/view/4', url_for(qualified=True, controller='blog', action='view', id=4)) - eq_('/viewpost/4', url_for(controller='post', action='view', id=4)) + with pytest.raises(Exception): + url_for() + with pytest.raises(Exception): + url_for(controller='post') + with pytest.raises(Exception): + url_for(id=2) + with pytest.raises(Exception): + url_for(qualified=True, controller='blog', id=4) + assert url_for(qualified=True, controller='blog', action='view', id=4) == 'http://www.example.com/blog/view/4' + assert url_for(controller='post', action='view', id=4) == '/viewpost/4' env = dict(SCRIPT_NAME='', SERVER_NAME='www.example.com', SERVER_PORT='8080', PATH_INFO='/blog/view/4') env['wsgi.url_scheme'] = 'http' self.con.environ = env - assert_raises(Exception, url_for, controller='post') - eq_('http://www.example.com:8080/blog/view/4', url_for(qualified=True, controller='blog', action='view', id=4)) + with pytest.raises(Exception): + url_for(controller='post') + assert url_for(qualified=True, controller='blog', action='view', id=4) == 'http://www.example.com:8080/blog/view/4' def test_with_route_names(self): @@ -818,13 +855,17 @@ def test_with_route_names(self): m.connect('category_home', 'category/:section', controller='blog', action='view', section='home') m.create_regs(['content','blog','admin/comments']) - assert_raises(Exception, url_for, controller='content', action='view') - assert_raises(Exception, url_for, controller='content') - assert_raises(Exception, url_for, controller='admin/comments') - eq_('/category', url_for('category_home')) - eq_('/category/food', url_for('category_home', section='food')) - assert_raises(Exception, url_for, 'home', controller='content') - eq_('/', url_for('home')) + with pytest.raises(Exception): + url_for(controller='content', action='view') + with pytest.raises(Exception): + url_for(controller='content') + with pytest.raises(Exception): + url_for(controller='admin/comments') + assert url_for('category_home') == '/category' + assert url_for('category_home', section='food') == '/category/food' + with pytest.raises(Exception): + url_for('home', controller='content') + assert url_for('home') == '/' def test_with_route_names_and_nomin(self): m = self.con.mapper @@ -834,13 +875,17 @@ def test_with_route_names_and_nomin(self): m.connect('category_home', 'category/:section', controller='blog', action='view', section='home') m.create_regs(['content','blog','admin/comments']) - assert_raises(Exception, url_for, controller='content', action='view') - assert_raises(Exception, url_for, controller='content') - assert_raises(Exception, url_for, controller='admin/comments') - eq_('/category/home', url_for('category_home')) - eq_('/category/food', url_for('category_home', section='food')) - assert_raises(Exception, url_for, 'home', controller='content') - eq_('/', url_for('home')) + with pytest.raises(Exception): + url_for(controller='content', action='view') + with pytest.raises(Exception): + url_for(controller='content') + with pytest.raises(Exception): + url_for(controller='admin/comments') + assert url_for('category_home') == '/category/home' + assert url_for('category_home', section='food') == '/category/food' + with pytest.raises(Exception): + url_for('home', controller='content') + assert url_for('home') == '/' def test_with_route_names_and_defaults(self): m = self.con.mapper @@ -851,9 +896,10 @@ def test_with_route_names_and_defaults(self): m.create_regs(['content','blog','admin/comments','building']) self.con.mapper_dict = dict(controller='building', action='showjacks', campus='wilma', building='port') - assert_raises(Exception, url_for) - eq_('/building/wilma/port/alljacks', url_for(controller='building', action='showjacks', campus='wilma', building='port')) - eq_('/', url_for('home')) + with pytest.raises(Exception): + url_for() + assert url_for(controller='building', action='showjacks', campus='wilma', building='port') == '/building/wilma/port/alljacks' + assert url_for('home') == '/' def test_with_resource_route_names(self): m = Mapper() @@ -862,22 +908,25 @@ def test_with_resource_route_names(self): m.resource('message', 'messages', member={'mark':'GET'}, collection={'rss':'GET'}) m.create_regs(['messages']) - assert_raises(Exception, url_for, controller='content', action='view') - assert_raises(Exception, url_for, controller='content') - assert_raises(Exception, url_for, controller='admin/comments') - eq_('/messages', url_for('messages')) - eq_('/messages/rss', url_for('rss_messages')) - eq_('/messages/4', url_for('message', id=4)) - eq_('/messages/4/edit', url_for('edit_message', id=4)) - eq_('/messages/4/mark', url_for('mark_message', id=4)) - eq_('/messages/new', url_for('new_message')) - - eq_('/messages.xml', url_for('formatted_messages', format='xml')) - eq_('/messages/rss.xml', url_for('formatted_rss_messages', format='xml')) - eq_('/messages/4.xml', url_for('formatted_message', id=4, format='xml')) - eq_('/messages/4/edit.xml', url_for('formatted_edit_message', id=4, format='xml')) - eq_('/messages/4/mark.xml', url_for('formatted_mark_message', id=4, format='xml')) - eq_('/messages/new.xml', url_for('formatted_new_message', format='xml')) + with pytest.raises(Exception): + url_for(controller='content', action='view') + with pytest.raises(Exception): + url_for(controller='content') + with pytest.raises(Exception): + url_for(controller='admin/comments') + assert url_for('messages') == '/messages' + assert url_for('rss_messages') == '/messages/rss' + assert url_for('message', id=4) == '/messages/4' + assert url_for('edit_message', id=4) == '/messages/4/edit' + assert url_for('mark_message', id=4) == '/messages/4/mark' + assert url_for('new_message') == '/messages/new' + + assert url_for('formatted_messages', format='xml') == '/messages.xml' + assert url_for('formatted_rss_messages', format='xml') == '/messages/rss.xml' + assert url_for('formatted_message', id=4, format='xml') == '/messages/4.xml' + assert url_for('formatted_edit_message', id=4, format='xml') == '/messages/4/edit.xml' + assert url_for('formatted_mark_message', id=4, format='xml') == '/messages/4/mark.xml' + assert url_for('formatted_new_message', format='xml') == '/messages/new.xml' def test_with_resource_route_names_and_nomin(self): m = Mapper() @@ -887,22 +936,25 @@ def test_with_resource_route_names_and_nomin(self): m.resource('message', 'messages', member={'mark':'GET'}, collection={'rss':'GET'}) m.create_regs(['messages']) - assert_raises(Exception, url_for, controller='content', action='view') - assert_raises(Exception, url_for, controller='content') - assert_raises(Exception, url_for, controller='admin/comments') - eq_('/messages', url_for('messages')) - eq_('/messages/rss', url_for('rss_messages')) - eq_('/messages/4', url_for('message', id=4)) - eq_('/messages/4/edit', url_for('edit_message', id=4)) - eq_('/messages/4/mark', url_for('mark_message', id=4)) - eq_('/messages/new', url_for('new_message')) - - eq_('/messages.xml', url_for('formatted_messages', format='xml')) - eq_('/messages/rss.xml', url_for('formatted_rss_messages', format='xml')) - eq_('/messages/4.xml', url_for('formatted_message', id=4, format='xml')) - eq_('/messages/4/edit.xml', url_for('formatted_edit_message', id=4, format='xml')) - eq_('/messages/4/mark.xml', url_for('formatted_mark_message', id=4, format='xml')) - eq_('/messages/new.xml', url_for('formatted_new_message', format='xml')) + with pytest.raises(Exception): + url_for(controller='content', action='view') + with pytest.raises(Exception): + url_for(controller='content') + with pytest.raises(Exception): + url_for(controller='admin/comments') + assert url_for('messages') == '/messages' + assert url_for('rss_messages') == '/messages/rss' + assert url_for('message', id=4) == '/messages/4' + assert url_for('edit_message', id=4) == '/messages/4/edit' + assert url_for('mark_message', id=4) == '/messages/4/mark' + assert url_for('new_message') == '/messages/new' + + assert url_for('formatted_messages', format='xml') == '/messages.xml' + assert url_for('formatted_rss_messages', format='xml') == '/messages/rss.xml' + assert url_for('formatted_message', id=4, format='xml') == '/messages/4.xml' + assert url_for('formatted_edit_message', id=4, format='xml') == '/messages/4/edit.xml' + assert url_for('formatted_mark_message', id=4, format='xml') == '/messages/4/mark.xml' + assert url_for('formatted_new_message', format='xml') == '/messages/new.xml' if __name__ == '__main__': diff --git a/tests/test_units/__init__.py b/tests/test_units/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tox.ini b/tox.ini index 4defb14..24a4f99 100644 --- a/tox.ini +++ b/tox.ini @@ -3,10 +3,12 @@ envlist = py{27,35,36},pypy,pypy3,style [testenv] deps= - # Adds nosetests command to setup.py - nose + pytest + pytest-cov + soupsieve<2.0 + webtest commands= - python -bb setup.py nosetests {posargs:--with-coverage} + py.test --cov=routes --cov-report html:html_coverage -v {posargs:tests/} # We could to this in dependencies, but explicit is better than implicit pip install .[middleware]