Personally, I use lxml to check the presence of HTML element based on
xpath. Here is an exemple of how I do it:
from django.core.urlresolvers import reverse
from django.test import TestCase
from lxml import etree
class UserUrlTestCase(TestCase):
""" Test for the user app """
def test_login_view(self):
""" The view display a form with username and password fields """
rep = self.client.get(reverse('user:login'))
# No need to continue if we don't get a 200 OK
self.assertEqual(rep.status_code, 200)
# Use xpath to check presence of element
doc = etree.HTML(rep.content)
self.assertEqual(len(doc.findall('.//input[@name="username"]')), 1)
self.assertEqual(len(doc.findall('.//input[@name="password"]')), 1)
You'll need to install the package lxml for the import to work
>> email to
django-users...@googlegroups.com.
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
django-users...@googlegroups.com.
>
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciWuP9jO5f3VExVduCLck2wPAaCtEkXKa%2B%3DTgmLEVd8E5g%40mail.gmail.com.
--
Cordialement, Coues Ludovic
+336 148 743 42