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

2016-10-12 22:23 GMT+02:00 James Schneider <jrschneide...@gmail.com>:
> In general, you would request the page and inspect the rendered output.
>
> https://docs.djangoproject.com/en/1.10/topics/testing/tools/#testing-responses
>
> -James
>
> On Wed, Oct 12, 2016 at 12:17 PM, <codemaster...@gmail.com> wrote:
>>
>>  How to Unit testing in django for django  template
>>
>>   please any one help me???
>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/c09dfbd9-82d3-4d08-832d-c1e00f78aeed%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CA%2Be%2BciWuP9jO5f3VExVduCLck2wPAaCtEkXKa%2B%3DTgmLEVd8E5g%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



-- 

Cordialement, Coues Ludovic
+336 148 743 42

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEuG%2BTaiByfaWQ1-C545PooEEtNL0FB6B3g2uWxb84Hz%3DqD4Rw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to