English 中文(简体)
How can reverse( opensearch ) work in the shell, but fails in a Test?
原标题:

I m trying to install django-lean into my application.

Open search is used in my app App.

I can reverse( opensearch ) in the Python shell. However, in the test, reverse( opensearch ) * NoReverseMatch: Reverse for opensearch with arguments () and keyword arguments

In [47]: reverse( opensearch )
Out[47]:  /opensearch.xml 
In [48]: response = client.get( /opensearch.xml )
In [49]: response.status_code
Out[49]: 200

This is an attempt to do the same from the Test, stopped by pdb.set_trace()

No fixtures found.
> /usr/local/lib/python2.7/site-packages/django_lean-0.15-py2.7.egg/django_lean/experiments/tests/test_tags.py(72)doTestIntegration()
-> response = client.get("confirm_human") # this is where the Client can t find the url
(Pdb) reverse( opensearch )
*** NoReverseMatch: Reverse for  opensearch  with arguments  ()  and keyword arguments  {}  not found.

Here is the code from urls.py:

url(r ^opensearch.xml$ , app.meta.opensearch, name= opensearch ),

Finally, here is the traceroute for the failing test:

======================================================================
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
问题回答

Looks like it might be Bug 11077. If so, the problem is a TestCase overriding the urlconf, as noted there in this comment: "The problem lies with the fact that the tests for both django.contrib.auth and django-registration set their TestCase.urls setting to override the default URLConf."





相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签