This is a best-practices question.
When writing tests in Django, is it better to hard code urls in your tests.py, or to use the dispatch's reverse() function to retrieve the correct url?
Using hard-coded urls for testing only feels like the right way, but at the same time I can't think of a good enough argument for not using reverse().
Option A. reverse()
# Data has already been loaded through a fixture
def test_view_blog(self):
url = reverse('blog', kwargs={'blog_slug':'test-blog'})
response = self.client.get(url)
self.failUnlessEqual(response.status_code, 200)
Option B. hard-coded
# Data has already been loaded through a fixture
def test_view_blog(self):
url = '/blog/test-blog/'
response = self.client.get(url)
self.failUnlessEqual(response.status_code, 200)