次のような 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
なぜ私のテストはそれが存在すると思うのですか?