Re: Unit testing - self.assertEqual("Break it!", resp.content)

2014-07-06 Thread Pepsodent Cola
Hi,
I have been using assertEqual lately in my unit testing to deliberately 
make coverage break.  By comparing *Something False* with the 
complete HTML returned (*resp.content*).

self.assertEqual("Something False", *resp.content*)

In order to reveal and debug these 3 links.

self.assertNotContains(resp, 'Documentation')
self.assertNotContains(resp, 'Change 
password')
self.assertNotContains(resp, 'Log out')


But the unit test debug output of the complete HTML returned doesn't reveal 
those 3 links.  Why is that?

unit test output
http://dpaste.com/23XGR4M.txt

Compared to the HTML returned that I can see by manually checking the 
source page from my browser.

html source page
http://dpaste.com/0PCZJ0D

 Welcome, joe. 


*Documentation / Change password / Log out *



Is there something wrong with my overridden template file?  Where I have 
removed *{% block userlinks %}* in order to reveal Django admins above 3 
default links.

password_reset_form.html
http://dpaste.com/0T3N3JK

{% extends "admin/base_site.html" %}
{% load i18n %}





*{% comment %}{% block userlinks %}{% trans "Change password" %} / {% trans "Log out" %}{% endblock %}{% 
endcomment %}*


{% comment %}
{% block breadcrumbs %}

{% trans "Home" %}
› {% trans "Password reset" %}

{% endblock %}
{% endcomment %}

{% block title %}{% trans "Password reset - v.2" %}{% endblock %}


{% block content %}
{% trans "Password reset" %}
{% trans "Forgotten your password? Enter your email address below, and 
we'll email instructions for setting a new one." %}

{% csrf_token %}
{{ form.email.errors }}
{% trans "Email address:" %} {{ form.email 
}} 

{% endblock %}












On Monday, July 7, 2014 6:08:20 AM UTC+2, mitesh_django wrote:
>
> Hi,
>
> You are trying to compare  break it!  with the complete HTML 
> returned. Instead of assertEqual, use assertIn.
>
> self.assertIn("Break it!", resp.content)
>
> Regards, 
> Mitesh
> On 7 Jul 2014 01:44, "Pepsodent Cola" > 
> wrote:
>
>> When I run this unit test to make it break so it can output a bunch of 
>> html data.
>>
>> self.assertEqual("Break it!", *resp.content*)
>>
>>
>> test.py
>> # Reset password no login
>>
>> def test_Reset_no_login(self):
>> self.assertTrue(isinstance(self.user, User))
>> login = self.client.login(username='captain', password='america')
>>
>> self.assertEqual("Profile", *resp.content*)
>>
>> self.assertNotContains(resp, '> href="/admin/doc/">Documentation')
>> self.assertNotContains(resp, '> href="/admin/password_change/">Change password')
>> self.assertNotContains(resp, 'Log out')
>>
>>
>>
>> Then I can't find these html tags in unit test's *resp.content* but when 
>> I manually check the html source page from the web browser then I see those 
>> 3 html tags.
>> Why isn't unit test *resp.content* output displaying these 3 html lines?
>>
>>
>> html source page
>> http://dpaste.com/0PCZJ0D
>>
>>  Welcome, joe. 
>>
>>
>> *Documentation / > href="/admin/password_change/">Change password / > href="/admin/logout/">Log out *
>> 
>>
>>
>> unit test output
>> http://dpaste.com/23XGR4M.txt
>>
>> ==
>> FAIL: test_Reset_no_login (userprofile.tests.PasswordResetTest)
>> --
>> Traceback (most recent call last):
>>   File "/home/Python/Projects/Navi/Django/navi/userprofile/tests.py", 
>> line 132, in test_Reset_no_login
>>
>> self.assertEqual("Profile", resp.content)
>>
>> AssertionError: 'Profile' != '\n> lang="en-us" >\n\nPassword reset - v.2\n> rel="stylesheet" type="text/css" href="/static/admin/css/base.css" 
>> />\n\n\n\n> type="text/javascript">window.__admin_media_prefix__ = 
>> "/static/admin/";\n\n> />\n\n\n\n\n\n\n> id="container">\n\n\n\n> id="header">\n\n\n> id="site-name">Navi administration - v.1\n\n\n
>> \nAdmin navigation\n\n\n
>> \n\nHome\n\n
>> \n\n\n\n\n\n\n\n\n
>> \n\n\n\nPassword 
>> reset\nForgotten your password? Enter your email address below, and 
>> we\'ll email instructions for setting a new one.\n\n> method="post">> value=\'iXJku3wGmCRg95SlHqC5QfHEH48XCRRZ\' />\n\n> for="id_email">Email address: > name="email" type="text" /> > />\n\n\n\n\n\n
>> \n\n\n\n\n\n\n\n'
>>
>> --
>> Ran 36 tests in 5.981s
>>
>> FAILED (failures=1)
>> Destroying test database for alias 'default' (':memory:')...
>>
>>
>>  -- 
>> 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 .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/dj

Re: Unit testing - self.assertEqual("Break it!", resp.content)

2014-07-06 Thread Mitesh Patel
Hi,

You are trying to compare  break it!  with the complete HTML
returned. Instead of assertEqual, use assertIn.

self.assertIn("Break it!", resp.content)

Regards,
Mitesh
On 7 Jul 2014 01:44, "Pepsodent Cola"  wrote:

> When I run this unit test to make it break so it can output a bunch of
> html data.
>
> self.assertEqual("Break it!", *resp.content*)
>
>
> test.py
> # Reset password no login
>
> def test_Reset_no_login(self):
> self.assertTrue(isinstance(self.user, User))
> login = self.client.login(username='captain', password='america')
>
> self.assertEqual("Profile", *resp.content*)
>
> self.assertNotContains(resp, 'Documentation')
> self.assertNotContains(resp, 'Change
> password')
> self.assertNotContains(resp, 'Log out')
>
>
>
> Then I can't find these html tags in unit test's *resp.content* but when
> I manually check the html source page from the web browser then I see those
> 3 html tags.
> Why isn't unit test *resp.content* output displaying these 3 html lines?
>
>
> html source page
> http://dpaste.com/0PCZJ0D
>
>  Welcome, joe.
>
>
> *Documentation /  href="/admin/password_change/">Change password /  href="/admin/logout/">Log out *
> 
>
>
> unit test output
> http://dpaste.com/23XGR4M.txt
>
> ==
> FAIL: test_Reset_no_login (userprofile.tests.PasswordResetTest)
> --
> Traceback (most recent call last):
>   File "/home/Python/Projects/Navi/Django/navi/userprofile/tests.py", line
> 132, in test_Reset_no_login
>
> self.assertEqual("Profile", resp.content)
>
> AssertionError: 'Profile' != '\n >\n\nPassword reset - v.2\n type="text/css" href="/static/admin/css/base.css" />\n\n\n\n type="text/javascript">window.__admin_media_prefix__ =
> "/static/admin/";\n\n />\n\n\n\n\n\n\n id="container">\n\n\n\n id="header">\n\n\n id="site-name">Navi administration - v.1\n\n\n
> \nAdmin navigation\n\n\n
> \n\nHome\n\n
> \n\n\n\n\n\n\n\n\n
> \n\n\n\nPassword
> reset\nForgotten your password? Enter your email address below, and
> we\'ll email instructions for setting a new one.\n\n method="post"> value=\'iXJku3wGmCRg95SlHqC5QfHEH48XCRRZ\' />\n\n for="id_email">Email address:  name="email" type="text" />  />\n\n\n\n\n\n
> \n\n\n\n\n\n\n\n'
>
> --
> Ran 36 tests in 5.981s
>
> FAILED (failures=1)
> Destroying test database for alias 'default' (':memory:')...
>
>
>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c20a58c5-fad3-4ba6-906e-ca99158f9db6%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD3RGrSygOn%3D_J2hmMFB87QezLwZSMNfLoN27WL5fwHjvKwi%3Dg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Unit testing - self.assertEqual("Break it!", resp.content)

2014-07-06 Thread Pepsodent Cola
When I run this unit test to make it break so it can output a bunch of html 
data.

self.assertEqual("Break it!", *resp.content*)


test.py
# Reset password no login

def test_Reset_no_login(self):
self.assertTrue(isinstance(self.user, User))
login = self.client.login(username='captain', password='america')

self.assertEqual("Profile", *resp.content*)

self.assertNotContains(resp, 'Documentation')
self.assertNotContains(resp, 'Change 
password')
self.assertNotContains(resp, 'Log out')



Then I can't find these html tags in unit test's *resp.content* but when I 
manually check the html source page from the web browser then I see those 3 
html tags.
Why isn't unit test *resp.content* output displaying these 3 html lines?


html source page
http://dpaste.com/0PCZJ0D

 Welcome, joe. 


*Documentation / Change password / Log out *



unit test output
http://dpaste.com/23XGR4M.txt

==
FAIL: test_Reset_no_login (userprofile.tests.PasswordResetTest)
--
Traceback (most recent call last):
  File "/home/Python/Projects/Navi/Django/navi/userprofile/tests.py", line 
132, in test_Reset_no_login

self.assertEqual("Profile", resp.content)

AssertionError: 'Profile' != '\n\n\nPassword reset - v.2\n\n\n\n\nwindow.__admin_media_prefix__ = 
"/static/admin/";\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nNavi administration - v.1\n\n\n
\nAdmin navigation\n\n\n
\n\nHome\n\n
\n\n\n\n\n\n\n\n\n
\n\n\n\nPassword 
reset\nForgotten your password? Enter your email address below, and 
we\'ll email instructions for setting a new one.\n\n\n\nEmail address:  \n\n\n\n\n\n
\n\n\n\n\n\n\n\n'

--
Ran 36 tests in 5.981s

FAILED (failures=1)
Destroying test database for alias 'default' (':memory:')...


-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c20a58c5-fad3-4ba6-906e-ca99158f9db6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.