python - 为 Django URL Dispatcher 编写的测试不起作用

标签 python django testing http-status-code-404

我正在使用 django 开发一个简单的网络服务。这是我在 django/python 中的第一个网络应用程序,所以如果我在这里遗漏了一些明显的东西,我不会感到惊讶,但是......

我目前正在尝试测试我过滤 url 的逻辑。

            # Works as expected
            response = self.client.post("/mysite/goodurl/")
            self.assertEqual(response.status_code, 200)

            # Has an exception rather than a 404
            response = self.client.post("/mysite/badurl/")
            self.assertEqual(response.status_code, 404)

所以,badurl 的情况不仅仅是没有找到并抛出 404,而是我收到了这个错误:

Traceback (most recent call last):
  File "/home/user/me/mysite/tests.py", line 55, in test_add_tracker
    response = self.client.post("/mysite/badurl/")
  File "/home/path/to/some/bin/dir/freeware/Python/lib/python2.7/site-packages/django/test/client.py", line 449, in post
    response = super(Client, self).post(path, data=data, content_type=content_type, **extra)
  File "/home/path/to/some/bin/dir/freeware/Python/lib/python2.7/site-packages/django/test/client.py", line 262, in post
    return self.request(**r)
  File "/home/path/to/some/bin/dir/freeware/Python/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/home/path/to/some/bin/dir/freeware/Python/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 77, in wrapped_view
    return view_func(*args, **kwargs)
TypeError: EtimeFetcher() got an unexpected keyword argument 'alias'

我尝试用谷歌搜索 EtimeFetcher 消息,但没有成功。有什么想法吗?

最佳答案

你可能有一些观点来捕捉所有的 Http404 错误。然而,Django 似乎已经找到了一个针对/badurl 执行的 View 。在您的代码中搜索包含别名命名参数的语句,例如:“alias=yyyy”。或者可能是一些 url 模式,包含“别名”作为 urls.py 中的额外参数?

关于python - 为 Django URL Dispatcher 编写的测试不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10876029/

相关文章:

python - 在对象中存储计算值

python - IronPython - Linux 中的 DynamicWebServiceHelpers.dll?

django - 如何在不同服务器上缓存redis

python - 在 Django 项目中连接两个 Django 应用程序的可能性

android - 使用 Appium 通过一个 Android Activity 测试多个 fragment

java - 我怎样才能使 Java 方法对除测试之外的所有调用者都是私有(private)的?

testing - 使用 go test 跳过一些测试

python - 从另一个模型创建模型 - 使用 Many2one 字段 - Odoo v8

python - 多处理时 Pytorch 推理 CUDA 内存不足

Django:如何将我的基于函数的 View 重新创建为(通用编辑)基于类的 View