I am trying to automate testing 404 pages using the Django 1.4 testing platform.
If I type 127.0.0.1:8000/something/really/weird/
in the address bar of a browser with a development server running, I see a 404 page with the correct status "404 NOT FOUND" (as Firebug shows).
But if I try to use this code for testing:
from django.test import TestCase class Sample404TestCase(TestCase): def test_wrong_uri_returns_404(self): response = self.client.get('something/really/weird/') self.assertEqual(response.status_code, 404)
the test does not work with this output:
$./manage.py test main Creating test database for alias 'default'... .F ====================================================================== FAIL: test_wrong_uri_returns_404 (main.tests.Sample404TestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File ".../main/tests.py", line 12, in test_wrong_uri_returns_404 self.assertEqual(response.status_code, 404) *AssertionError: 200 != 404* ---------------------------------------------------------------------- Ran 2 tests in 0.031s FAILED (failures=1) Destroying test database for alias 'default'...
I am seriously surprised that I got 200 codes here. Does anyone have any idea why this is happening on earth?
update:
here lies urls.py: http://pastebin.com/DikAVa8T and the actual failure test:
def test_wrong_uri_returns_404(self): response = self.client.get('/something/really/weird/') self.assertEqual(response.status_code, 404)
everything happens in the project https://github.com/gbezyuk/django-app-skeleton
source share