FAIL: test_home_page_can_save_request_POST (lists.tests.HomePageTest)----------------------------------------------------------------------Traceback (most recent call last): File "D:\superlists\lists\tests.py", line 32, in test_home_page_can_save_request_POST self.assertEqual(response.content.decode(),excepted_html)AssertionError: '<htm[206 chars]t\t\t<input type=\'hidden\' name=\'csrfmiddlew[179 chars]tml>' != '<htm[206 chars]t\t\t\n\t\t</form>\n\t\t\n\t\t<table id="id_li[82 chars]tml>'
======================================================================FAIL: test_home_page_return_correct_html (lists.tests.HomePageTest)----------------------------------------------------------------------Traceback (most recent call last): File "D:\superlists\lists\tests.py", line 19, in test_home_page_return_correct_html self.assertEqual(response.content.decode(),excepted_html)AssertionError: '<htm[206 chars]t\t\t<input type=\'hidden\' name=\'csrfmiddlew[164 chars]tml>' != '<htm[206 chars]t\t\t\n\t\t</form>\n\t\t\n\t\t<table id="id_li[67 chars]tml>'
----------------------------------------------------------------------Ran 4 tests in 0.016s
FAILED (failures=2, errors=1)
D:\superlists>python manage.py testCreating test database for alias 'default'......----------------------------------------------------------------------Ran 3 tests in 0.016s
OKDestroying test database for alias 'default'...
--
You received this message because you are subscribed to the Google Groups "Obey the testing goat! Test-Driven Web Development with Python book" group.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-go...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Obey the testing goat! Test-Driven Web Development with Python book" group.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-go...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
def test_home_page_returns_correct_html(self):[...]- expected_html = render_to_string('home.html')- self.assertEqual(response.content.decode(), expected_html)+ expected_response = render(request, 'home.html')
+ self.assertEqual(response.content.decode(), expected_response.content.decode())
self.assertEqual(response.content, expected_response.content)Ok, I ran into this as well. I did some research, and couldn't find much information about render_to_string, especially not in the context used in ch 5. Before this, I had quietly wondered how the test would handle the CSRF token, given that it should be different between instances of the rendered response.What I found online were references to render_to_response, which was introduced back in django 1.3. render came later, and per the docs, render_to_response may be deprecated in the future. Render is part of the django.shortcuts package.Some things to know about render:- It returns an HttpResponse object, whose content is a byte string- it requires a request object as well as the template to render- if the request object is different from that used to generate the response we are testing against, the CSRF token will be different between the two responsesAs far as I can tell, render seems to be the preferred way to accomplish the test we are trying to write. Here's the changes I made to my code to get it to work:- from django.template.loader import render_to_string+ from django.shortcuts import renderdef test_home_page_returns_correct_html(self):[...]- expected_html = render_to_string('home.html')- self.assertEqual(response.content.decode(), expected_html)+ expected_response = render(request, 'home.html')
--
You received this message because you are subscribed to the Google Groups "Obey the testing goat! Test-Driven Web Development with Python book" group.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-go...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Harry Percival
+44 78877 02511
Glad you got something out of it anyway vinz! For info the book is now upgraded to python 3.6 and django 1.11beta. The online version is live, pdf should follow in a couple of weeks.
Hp
--
You received this message because you are subscribed to the Google Groups "Obey the testing goat! Test-Driven Web Development with Python book" group.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-go...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
def remove_csrf_tag(text):
"""Remove csrf tag from TEXT""" return re.sub(r'<[^>]*csrfmiddlewaretoken[^>]*>', '', text)
...
# then change assertion to
self.assertEqual( remove_csrf_tag(response.content), remove_csrf_tag(expected_html) )Y'all have me worried now. I thought this problem was comprehensively fixed in the new edition. Are you still using the old version of the book?
--
You received this message because you are subscribed to the Google Groups "Obey the testing goat! Test-Driven Web Development with Python book" group.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-go...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-goat-book+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-go...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
----
Harry Percival
+44 78877 02511
--
You received this message because you are subscribed to the Google Groups "Obey the testing goat! Test-Driven Web Development with Python book" group.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-go...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-goat-book+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
----
Harry Percival
+44 78877 02511
--
You received this message because you are subscribed to the Google Groups "Obey the testing goat! Test-Driven Web Development with Python book" group.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-goat-book+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I love it that Harry negotiated to make it available free online for everyone!
They are good, O'Reilly. I'm sad they stopped selling pdfs directly, because amazon are all drm-ey and google's pdfs are completely broken. But I found out that ebooks.com has nice drm-free editions, so the book is available to buy in good formats to buy. I've linked to them on obeythetestinggoat.com.
And the print edition is due out in 2 days time!
Help yourselves to the free edition in the meantime :)
HP
Publishers consider new editions of a book to be a whole new book, new ISBN and everything, rather than an update. Kinda sucks, but I think that's what you're running into.
I love it that Harry negotiated to make it available free online for everyone!
--
You received this message because you are subscribed to the Google Groups "Obey the testing goat! Test-Driven Web Development with Python book" group.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-go...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
They are good, O'Reilly. I'm sad they stopped selling pdfs directly, because amazon are all drm-ey and google's pdfs are completely broken. But I found out that ebooks.com has nice drm-free editions, so the book is available to buy in good formats to buy. I've linked to them on obeythetestinggoat.com.
And the print edition is due out in 2 days time!
Help yourselves to the free edition in the meantime :)
HP
On Sat, 26 Aug 2017, 01:21 Jeffrey Allman <jallm...@gmail.com> wrote:
Publishers consider new editions of a book to be a whole new book, new ISBN and everything, rather than an update. Kinda sucks, but I think that's what you're running into.
I love it that Harry negotiated to make it available free online for everyone!
--
You received this message because you are subscribed to the Google Groups "Obey the testing goat! Test-Driven Web Development with Python book" group.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-goat-book+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-go...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
----
Harry Percival
+44 78877 02511
--
You received this message because you are subscribed to the Google Groups "Obey the testing goat! Test-Driven Web Development with Python book" group.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-go...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Obey the testing goat! Test-Driven Web Development with Python book" group.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-go...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.