我很困惑为什么我的测试不能通过Django-lean模块。
======================================================================
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
以下是测试: 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%s@example.com" % 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)
这是视图,django_lean.experiments.views.confirm_human
@never_cache
def confirm_human(request):
experiment_user = WebUser(request)
experiment_user.confirm_human()
return HttpResponse(status=204)
最后,这是来自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')
)
我不明白为什么无法遵循client.get请求。
答案 0 :(得分:1)
更新在Django-lean源中找不到对opensearch
的任何引用。您使用的是Django opensearch插件还是其他一些引用opensearch的应用?尝试在项目中搜索opensearch
。
原始答案
乍一看,似乎其中一个模板使用带有参数{% url %}
的{{1}}标记。至少这是我怀疑基于错误跟踪中的以下几行。
opensearch
我不熟悉Django-lean,但我认为如果他们有一个名为 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
的网址,将会进行检查。