3
3
3ds2011-04-17 10:18:28
Django
3ds, 2011-04-17 10:18:28

django test client 404, 301 != 200

I write tests for the application. url.py: forum.urls:
urlpatterns = patterns('',
(r'^forum/', include('forum.urls')),
}



urlpatterns = patterns('',
(r'newtopic/(?P\d+)?$', 'forum.views.newtopic'),
(r'showtopic/(?P\d+)$', 'forum.views.showtopic'),
(r'showreplies/(?P\d+)$', 'forum.views.showreplies'),
(r'savereply/$', 'forum.views.savereply'),
(r'^$', 'forum.views.forum_list'),
)

Все конечно же работает (адреса 192.168.0.1:8000/forum/, .../forum ) Но когда пишу тесты:
from django.test import TestCase
from django.test.client import Client

class SimpleTest(TestCase):
def setUp(self):
self.client = Client()

def test_details(self):
response = self.client.get('/forum/')
self.assertEqual(response.status_code, 200)


и прогоняю их python manage.py test forum.SimpleTest
выдает TemplateDoesNotExist: 404.html
если в тесте написать
response = self.client.get('/forum') # без слэша на конце
выдает 301 != 200 ошибку.

В чем дело?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vlad Frolov, 2011-04-17
@frol

It is enough to start the Django test server and go to '/forum' - you will also get a 301 code that will redirect to '/forum/'.

E
Evgeny Kryukov, 2012-09-02
@dr013

Correct would be like this:
response = self.client.get('/forum/', follow=True)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question