tags:

views:

18

answers:

1

I'm confused why my tests won't pass for the Django-lean module.

======================================================================
ERROR: testIntegrationWithRegisteredUser (django_lean.experiments.tests.test_tags.ExperimentTagsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/django_lean-0.15-py2.7.egg/django_lean/experiments/tests/test_tags.py", line 55, in testIntegrationWithRegisteredUser
    client_factory=create_registered_user_client)
  File "/usr/local/lib/python2.7/site-packages/django_lean-0.15-py2.7.egg/django_lean/experiments/tests/test_tags.py", line 71, in doTestIntegration
    response = client.get(confirm_human_url)
  File "/usr/local/lib/python2.7/site-packages/Django-1.2.1-py2.7.egg/django/test/client.py", line 290, in get
    response = self.request(**r)
  File "/usr/local/lib/python2.7/site-packages/Django-1.2.1-py2.7.egg/django/test/client.py", line 230, in request
    response = self.handler(environ)
  File "/usr/local/lib/python2.7/site-packages/Django-1.2.1-py2.7.egg/django/test/client.py", line 74, in __call__
    response = self.get_response(request)
  File "/usr/local/lib/python2.7/site-packages/Django-1.2.1-py2.7.egg/django/core/handlers/base.py", line 142, in get_response
    return self.handle_uncaught_exception(request, resolver, exc_info)
  File "/usr/local/lib/python2.7/site-packages/Django-1.2.1-py2.7.egg/django/core/handlers/base.py", line 181, in handle_uncaught_exception
    return callback(request, **param_dict)
  File "/usr/local/lib/python2.7/site-packages/Django-1.2.1-py2.7.egg/django/views/defaults.py", line 24, in server_error
    return http.HttpResponseServerError(t.render(Context({})))
  File "/usr/local/lib/python2.7/site-packages/Django-1.2.1-py2.7.egg/django/template/__init__.py", line 173, in render
    return self._render(context)
  File "/usr/local/lib/python2.7/site-packages/Django-1.2.1-py2.7.egg/django/test/utils.py", line 29, in instrumented_test_render
    return self.nodelist.render(context)
  File "/usr/local/lib/python2.7/site-packages/Django-1.2.1-py2.7.egg/django/template/__init__.py", line 796, in render
    bits.append(self.render_node(node, context))
  File "/usr/local/lib/python2.7/site-packages/Django-1.2.1-py2.7.egg/django/template/__init__.py", line 809, in render_node
    return node.render(context)
  File "/usr/local/lib/python2.7/site-packages/Django-1.2.1-py2.7.egg/django/template/loader_tags.py", line 125, in render
    return compiled_parent._render(context)
  File "/usr/local/lib/python2.7/site-packages/Django-1.2.1-py2.7.egg/django/test/utils.py", line 29, in instrumented_test_render
    return self.nodelist.render(context)
  File "/usr/local/lib/python2.7/site-packages/Django-1.2.1-py2.7.egg/django/template/__init__.py", line 796, in render
    bits.append(self.render_node(node, context))
  File "/usr/local/lib/python2.7/site-packages/Django-1.2.1-py2.7.egg/django/template/__init__.py", line 809, in render_node
    return node.render(context)
  File "/usr/local/lib/python2.7/site-packages/Django-1.2.1-py2.7.egg/django/template/defaulttags.py", line 378, in render
    raise e
NoReverseMatch: Reverse for 'opensearch' with arguments '()' and keyword arguments '{}' not found.

----------------------------------------------------------------------
Ran 1 test in 1736.834s

Here is the test: class ExperimentTagsTest(TestCase): urls = 'django_lean.experiments.tests.urls'

def setUp(self):
    self.experiment = Experiment(name="test_experiment")
    self.experiment.save()
    self.experiment.state = Experiment.ENABLED_STATE
    self.experiment.save()

    self.other_experiment = Experiment(name="other_test_experiment")
    self.other_experiment.save()
    self.other_experiment.state = Experiment.ENABLED_STATE
    self.other_experiment.save()
    self.mox = mox.Mox()


def testIntegrationWithRegisteredUser(self):
    def create_registered_user_client(i):
        user = User(username="user%s" % i, email="user%[email protected]" % i)
        user.set_password("password")
        user.save()

        client = Client()

        if not client.login(username=user.username, password="password"):
            raise Exception("login failure")
        return client
    self.doTestIntegration(
        url=reverse('django_lean.experiments.tests.views.experiment_test',
                    args=[self.experiment.name]),
        client_factory=create_registered_user_client)

def doTestIntegration(self, url, client_factory):
    confirm_human_url = reverse('django_lean.experiments.views.confirm_human')
    # confirm_human_url set to '/main-app/confirm_human/' during test
    found_control = False
    found_test = False
    for i in range(100):
        client = client_factory(i)
        import pdb; pdb.set_trace()
        response = client.get(confirm_human_url) # this is where the Client can't find the url
        self.assertEquals(204, response.status_code)
        response = client.get(url)
        self.assertEquals(200, response.status_code)
        in_test = "test" in response.content.lower()
        in_control = "control" in response.content.lower()
        self.assertTrue(in_test != in_control)
        found_control = found_control or in_control
        found_test = found_test or in_test

    self.assertTrue(found_control)
    self.assertTrue(found_test)

This is the View, django_lean.experiments.views.confirm_human

@never_cache
def confirm_human(request):
    experiment_user = WebUser(request)
    experiment_user.confirm_human()
    return HttpResponse(status=204)

Finally, this is the URL patterns from django_lean.experiments.urls :

urlpatterns = patterns('django_lean.experiments.views',  
    url(r'^goal/(?P<goal_name>.*)$', 'record_experiment_goal'), 
    url(r'^confirm_human/$', 'confirm_human')  
)

I don't understand why the client.get request can't be followed.

+1  A: 

Update Couldn't find any reference to opensearch in Django-lean source. Are you using a Django opensearch plugin or is some other app referring to opensearch? Try searching for opensearch in your project.

Original Answer

At first blush it seems that one of the templates is using an {% url %} tag with argument opensearch. At least that is what I suspect based on the following lines in the error trace.

  File "/usr/local/lib/python2.7/site-packages/Django-1.2.1-py2.7.egg/django/template/__init__.py", line 809, in render_node
    return node.render(context)
  File "/usr/local/lib/python2.7/site-packages/Django-1.2.1-py2.7.egg/django/template/defaulttags.py", line 378, in render
    raise e

I am not familiar with Django-lean but I think it will be worrh checking if they have an URL named opensearch.

Manoj Govindan
Opensearch is used in the App.I can reverse('opensearch') in the Python shell. However, in the test, reverse('opensearch')*** NoReverseMatch: Reverse for 'opensearch' with arguments '()' and keyword arguments '{}' not found.
BryanWheelock