Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy are the Django project URLs not all available to the Django test client?
    primarykey
    data
    text
    <p>I've been trying to add the django-lean app to my project. The django-lean app is not located in the project I'm working on, it is on the PYTHONPATH.</p> <p>I have not been able to get the django-lean tests to pass.</p> <p>It seems the issue is that the TestCase defines a value for urls: </p> <pre><code> urls = 'django_lean.experiments.tests.urls' </code></pre> <p>As best as I can tell, the tests are only getting the urls located @ 'django_lean.experiments.tests.urls', but not the urls from the rest of the project.</p> <p>This is causing error messages like: </p> <pre><code>NoReverseMatch: Reverse for 'index' with arguments '()' and keyword arguments '{}' not found. </code></pre> <p>These are triggered by {% url %} template tags in the project.</p> <p>How can I make sure that the all the urls of the project are available for the tests?</p> <p>EDIT: Someone showed me a script to print the visible URLs: </p> <pre><code>import urls def show_urls(urllist, depth=0): for entry in urllist: print " " * depth, entry.regex.pattern if hasattr(entry, 'url_patterns'): show_urls(entry.url_patterns, depth + 1) </code></pre> <p>I called this script from <strong>ipdb</strong>, this was the output: </p> <pre><code> ipdb&gt; import urls ipdb&gt; show_urls(urls.urlpatterns) ^test-experiment/(?P&lt;experiment_name&gt;.*)$ ^test-clientsideexperiment/(?P&lt;experiment_name&gt;.*)$ ^admin/ ^(?P&lt;experiment_name&gt;.+)/$ ^$ ^main-app/ ^goal/(?P&lt;goal_name&gt;.*)$ ^confirm_human/$ </code></pre> <p>This corresponds to the urls located @ 'django_lean.experiments.tests.urls' </p> <pre><code>urlpatterns = patterns('django_lean.experiments.tests.views', url(r'^test-experiment/(?P&lt;experiment_name&gt;.*)$', 'experiment_test'), url(r'^test-clientsideexperiment/(?P&lt;experiment_name&gt;.*)$', 'clientsideexperiment_test')) urlpatterns += patterns('', url(r'^admin/', include('django_lean.experiments.admin_urls')), url(r'^main-app/', include('django_lean.experiments.urls')), </code></pre> <p>The issue that I'm having is that my tests all fail because of the named urls from other apps in the project are called by URL template tags are not accessible to the tests. </p> <p>I'm running Python 2.7 with Django 1.2.1</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload