One of my applications has a view that uses a random number generator.
I am having some trouble passing a mock random generator to the view
for testing purposes.
I am relying on the mock object to get predictable results for testing
the view's logic.

After several attempts I came up with an URL that looks like this:

from project.app.lib import RandomNumberGenerator

urlpatterns = patterns('',
        (r'^total/$', 'project.app.views.sum_of_random_numbers',
{'generator': RandomNumberGenerator() }),
)

My view:

def sum_of_random_numbers(request, generator):
        random_number = generator().random_number()

        if random_number == 1:
                # Render etc.
        # elif etc.


Here is my test:

from django.test import Client

client = Client()
response = client.post('/total/', {'choice': 'random'})

I would like to pass a mock object as the 'generator' argument. How
should I go about this?
Are there any better ways to achieve what I am trying to do?

Any help would be welcome.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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