python - How to Make view_config decorator work with a Pyramid Unit Test? -


i wrote login_required decorator pyramid web framework. in pyramid test server works well.

but in pyramid unit tests @view_config decorator not work configurations (not decorator parameter).

this code:

class myviews(object):   @view_config(decorator=login_required(login_url=login_url),                match_param="action=change_password", request_method="get",                renderer="accounts/change_password.jinja2")     def change_password(self):         form = changepwdform()         return {'form': form} 

here test code:

def test_change_password_fail(self):         .views import accountsviews         aviews = accountsviews(testing.dummyrequest(path='/accounts/forget_password'))         response = aviews.forget_password()         self.assertequal(response.status_code, 307)  #httptemporaryredirect 

what excepted not-logined-user redirected login url. paramenters in @view_config such renderer , 'match_param' not work.

how can solve problem?

references:
mocking render response pyramid
unit , integration testing:pyramid official guide,but not refer class-based view's decorator problem

@view_config() not applied until run config.scan().

when doing testing, in general want test single unit, in case view without worrying rest of framework.

you'd test view , decorator separately.

once higher level, , want test pyramid doing right thing views, want integration testing. integration testing set full configurator object, , full app, more heavy handed, allows test pyramid applies decorator.

the last tests want full end 2 end tests emulate full application. latest documentation available at: http://docs.pylonsproject.org/docs/pyramid/en/latest/narr/testing.html


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -