On Thu, Aug 12, 2010 at 3:49 PM, waugust <[email protected]> wrote:
> This is most likely a very trivial question, but believe me I did my
> due diligence and googled but alas I can't find the answer.
>
> All I'm trying to do is write tests for my controllers but I fail to
> see how to set an AUTH_USER environ variable.
>
> I thought to just instantiate my User model and pass it in the headers
> attribute of self.app.post though i get "AssertionError: Environmental
> variable HTTP_AUTH_USER is not a string:"
>
> What am I missing here? How do I mimic a logged in user when testing
> my controllers?
So you need to replicate the dictionary that repoze.what puts in place
in the wsgi request.
So what I do is have a series of functions in the test class like:
admin_user = { 'user': object(),
'groups': ('admin'),
'permissions': ('add_job')
}
and then I will use it in a test like so:
def test_list(self):
# check that it's first permission locked down
response = self.app.get(
url=url(controller='accounts', action='list'),
params={},
status=302
)
response = self.app.get(
url=url(controller='accounts', action='list'),
params={},
extra_environ={'repoze.what.credentials': self.admin_user},
status=200
)
http://what.repoze.org/docs/1.0/Manual/InnerWorkings.html
Rick Harding
http://blog.mitechie.com
http://lococast.net
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
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.