Okay I am having some troubles getting this to work. In my application
I am using WebTest and django-webtest to do template testing. In order
to monkeypatch the django.core.urlresolvers.reverse function, I have
created a new Test base that looks like this:

class FacebookWebTest(WebTest):

    def __init__(self, methodName='runTest'):
        super(FacebookWebTest, self).__init__(methodName)
        import django.core.urlresolvers
        django.core.urlresolvers.reverse = self.reverse

    def reverse(*args, **kwargs):
        return "foo"


Then hier is a test:

from django.core.urlresolvers import reverse

class HomepageViewTestCase(FacebookWebTest):

    def testPopulateFieldsInitially(self):
        url = reverse('webapp_home')
        form = self.app.get(url).form
        ...

Within the HomepageViewTestCase it is still calling the original
reverse method in django.core.urlresolvers even though it is calling
the FacebookWebTest constructor before. Any suggestions :)


On Sep 7, 10:23 am, Daniel Roseman <[email protected]> wrote:
> On Wednesday, 7 September 2011 07:49:00 UTC+1, Reikje wrote:
>
> > Hi, I have a bunch of WebTest's which are using the reverse method
> > from django.core.urlresolvers to resolve a URL which the test should
> > call. Example:
>
> > url = reverse('webapp_home')
> > form = self.app.get(url).form
>
> > Now I need to add a query parameter to every url. This is to mimic a
> > Facebook request which will always have the signed_request query
> > parameter. So in theory I could just do this:
>
> > url = reverse('webapp_home') + "?
> > signed_request=vlXgu64BQGFSQrY0ZcJBZASMvYvTHu9GQ0YM9rjPSso.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsIjAiOiJwYXlsb2FkIn0"
>
> > form = self.app.get(url).form
>
> > This is an example of a signed_request from the Facebook
> > documentation. Since, I am a bit lazy, is there a way to sort of
> > intercept all calls to reverse and add the signed_request parameter
> > every time?
>
> You probably just want to monkeypatch urlresolvers.reverse in your test
> setUp methods. Something like this would probably work.
>
>     from django.core import urlresolvers
>     reverse_original = urlresolvers.reverse
>     def reverse(*args, **kwargs):
>         url = reverse_original(*args, **kwargs)
>         url += whatever_you_want_to_add
>         return url
>     urlresolvers.reverse = reverse
>
> --
> DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" 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/django-users?hl=en.

Reply via email to