我有一个功能来测试我的 URL,如下所示:
def test_URLs(self):
routes = [
'about/',
'archive/',
'index/',
'admin/',
''
'doesntExist/'
]
for route in routes:
response = self.client.get(route)
self.assertEqual(response.status_code, 200)
我的 URL 模式如下所示:
urlpatterns = patterns('',
#CMS url
url(r'^admin/', include(admin.site.urls)),
url(r'^$', 'core.views.index'),
url(r'^index/', 'core.views.index'),
url(r'about/', 'core.views.about'),
url(r'^archive/', 'core.views.archive'),
url(r'^talks/(?P<slug>[\w\-]+)/$', 'core.views.getTalk'),
在我的 test_URLs 函数中,路由 'doesntExist/' 不存在,相当恰当。当我运行我的服务器并尝试访问时,doesntExist/
我收到了日志消息
[04/Oct/2013 09:37:40] "GET /doesntExist/ HTTP/1.1" 404 2629
因此doesntExist/
,当我运行上述测试时,我得到的肯定还不存在:
Creating test database for alias 'default'...
..
----------------------------------------------------------------------
Ran 2 tests in 0.017s
OK
为什么我的测试认为它存在?