I am new to Testing Driven Development as well as to Django and will appreciate some help please.
I have just worked through the tutorials of the official documentation for 1.11 and am trying
to get going with TDD and Django.
The app is wos_2017_2 and I get this in the shell (which is run in the project root)
in the app's urls.py I have
>>> from django.test import Client
>>> client = Client()
>>> response = client.get('/')
Not Found: /
>>> response = client.get('/wos_2017_2/')
>>> response
.status_code
200
from . import views
from django.conf.urls import url
urlpatterns = [
url(r'^$', views.index, name='index'),
]
and the in "wos_2017_2/test.py"
import unittest
from django.test import TestCase
from django.test import Client
# Create your tests here.
from .models import *
from .views import *
class SimpleTest(unittest.TestCase):
def test_index(self):
client = Client()
response = client.get('/')
self.assertEqual(response.status_code, 200)
And the test fails with
FAIL: test_index (wos_2017_2.tests.SimpleTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/js/django/wos/wos_2017_2/tests.py", line 16, in test_index
self.assertEqual(response.status_code, 200)
AssertionError: 404 != 200
----------------------------------------------------------------------
Ran 1 test in 0.006s
Using the url
http://localhost:8000/wos_2017_2/
in a browser works as expected.
Johann