# Check some response details
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'Profile View')
But I'm getting errors related to the project settings, most
specifically this one:
File "/Users/bshaurette/Code/django_trunk/django/core/handlers/
base.py", line 126, in get_response
subject = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR')
in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), request.path)
TypeError: 'in <string>' requires string as left operand
I tried setting an INTERNAL_IPS value to get around that, but there
are other settings errors that pop up. Ultimately, it looks like the
test is having trouble reconciling paths between the project urls.py
and the app urls.py ... ?
DoesNotExist: Site matching query does not exist.
I'm not new to writing tests, just to unit testing in Django/Python -
what would *really* help is if I could see some other examples of view
testing. I feel like I've been banging my head against a wall for a
few days now. Has anyone got any recommendations?
On Tue, Jul 15, 2008 at 8:28 AM, bshaurette <bshaure...@gmail.com> wrote:
> Writing tests for models has been a snap, but I'm having a lot harder > time with the views. ... > I'm not new to writing tests, just to unit testing in Django/Python - > what would *really* help is if I could see some other examples of view > testing. I feel like I've been banging my head against a wall for a > few days now. Has anyone got any recommendations?
The Django system tests contain a lot of examples of Django view tests. In particular, modeltests/test_client and regressiontests/test_client_regress show how to exercise most of the features of the Django test system.
----------------------------------------------------------------------
account/tests.py", line 37, in test_account_register
self.client.post('/account/register/', user_data_dict)
File "/usr/lib/python2.5/site-packages/django/test/client.py", line
243, in post
return self.request(**r)
File "/usr/lib/python2.5/site-packages/django/test/client.py", line
171, in request
response = self.handler(environ)
File "/usr/lib/python2.5/site-packages/django/test/client.py", line
40, in __call__
response = self.get_response(request)
File "/usr/lib/python2.5/site-packages/django/core/handlers/
base.py", line 126, in get_response
subject = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR')
in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), request.path)
TypeError: 'in <string>' requires string as left operand
> But I'm getting errors related to the project settings, most
> specifically this one:
> File "/Users/bshaurette/Code/django_trunk/django/core/handlers/
> base.py", line 126, in get_response
> subject = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR')
> in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), request.path)
> TypeError: 'in <string>' requires string as left operand
> I tried setting an INTERNAL_IPS value to get around that, but there
> are other settings errors that pop up. Ultimately, it looks like the
> test is having trouble reconciling paths between the project urls.py
> and the app urls.py ... ?
> DoesNotExist: Site matching query does not exist.
> I'm not new to writing tests, just to unit testing in Django/Python -
> what would *really* help is if I could see some other examples of view
> testing. I feel like I've been banging my head against a wall for a
> few days now. Has anyone got any recommendations?
For what it's worth, I finally came up with a simple working test for
views. My tests were written correctly all along, I just had to take
care of those errors related to the project settings. It never
occurred me to just set constants at the top of the test file, but
that's what worked.
import os
from django.test import Client, TestCase
On 15 Lip, 20:54, bshaurette <bshaure...@gmail.com> wrote:
> For what it's worth, I finally came up with a simple working test forviews. Mytestswere written correctly all along, I just had to take
> care of those errors related to the project settings. It never
> occurred me to just set constants at the top of the test file, but
> that's what worked.
> import os
> from django.test import Client, TestCase