Ok I manage it using request.route_url('my_view') instead of
request.current_route_url().
I assume this is because request.route_url ask the Configurator which url a
given route has, whereas request.current_route_url needs the requested to
were routed which is not the case in a ViewIntegretionTest.
But if my assomptions are right, does it means we can't perform an
integretion test on a view callable that uses request.current_route_url ?
Or is there a way to mock the routing operations by setting some attributes
of the DummyRequest ?
Any help appreciated.
Thanks.
Le jeudi 6 décembre 2012 11:45:35 UTC+1, Emmanuel Cazenave a écrit :
>
> Hi,
>
> In a view I use request.current_route_url() because I want it in the
> returned dict.
>
> @view_config(route_name='my_view', renderer='templates/my_view.pt')
> def my_view(request):
> ....
> ....
> return dict(....,url=request.current_route_url())
>
> It works properly in a 'production' context but raises an exception in a
> unittest:
>
> class ViewIntegretionTest(unittest.TestCase):
>
> def setUp(self):
> self.request = testing.DummyRequest()
> self.config = testing.setUp(request=self.request)
> from sqlalchemy import create_engine
> engine = create_engine('sqlite://')
> DBSession.configure(bind=engine)
> Base.metadata.create_all(engine)
>
> def test_my_view(self):
> def callable(config):
> config.add_route('my_view', '/my_view')
> self.config.include(callable)
> from myapp.views import my_view
> response = my_view(self.request)
>
> def tearDown(self):
> DBSession.remove()
> testing.tearDown()
>
> This raises the following exception:
>
> Traceback (most recent call last):
> File "d:\envs\myapp_env\myapp_repo\myapp\tests\test_views\tes
> t_myview.py", line 16, in test_my_view
> response = my_view(self.request)
> File "d:\envs\myapp_env\myapp_repo\myapp\views.py", line 42,
> in my_view
> request.current_route_url()
> File "d:\envs\myapp_env\pyramid-1.3\pyramid\url.py", line 677, in curre
> nt_route_url
> raise ValueError('Current request matches no route')
> ValueError: Current request matches no route
>
> I suppose I don't initialize the testing environment properly.......any
> help ?
>
> Thanks.
>
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/pylons-discuss/-/fX2AS7YS1KgJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.