How do I poke fun at the Pyramid object `request.matched_route`?

I am writing tests for my project that uses Pyramid . What I have done so far is add data and attributes manually to queries. For example, by setting the ID in the route:

request = testing.DummyRequest()
request.matchdict['id'] = 19

      

One of my views has multiple routes and I define the route using request.matched_route.name

.

Now when I try to manually set the route, for example:

request.matched_route.name = 'one_of_my_routes'

      

or

request.matched_route = {'name': 'one_of_my_routes'}

      

I am getting errors. What is the correct way to test using Python unit tests?

+3


source to share


1 answer


Well, this is not Javascript. You cannot make a dictionary and expect to use the dot operator on it. So why # 2 doesn't work. # 1 is probably due to the fact that you need to create every object in the chain. request

has a property matched_route

if the route matches, so you need to create that object.



class DummyRoute(object):
    name = 'one_of_my_routes'

request.matched_route = DummyRoute()

      

+2


source







All Articles