django.template.loader.render_to_string
python manage.py testCreating test database for alias 'default'....System check identified no issues (0 silenced).F.======================================================================FAIL: test_index_view_returns_correct_html (lists.tests.IndexViewTest)----------------------------------------------------------------------Traceback (most recent call last): File "tests.py", line 24, in test_index_view_returns_correct_html self.assertEqual(expected_html, actual_html)AssertionError: '<!DO[263 chars]lue="BJMT1b9fxuXOGugp00SDypeTYZxvlmc6KtBSYMDon[198 chars]l>\n' != '<!DO[263 chars]lue="R05ZiWMASEWMurA8Rdo8bnA0mTwqFTqA0KUYfxgJI[198 chars]l>\n'
----------------------------------------------------------------------Ran 3 tests in 0.006s
FAILED (failures=1)Destroying test database for alias 'default'...
Process finished with exit code 1
from django.http import HttpResponse
from django.shortcuts import render
# Create your views here.
def index(request):
if request.method == 'POST':
return HttpResponse(request.POST['item_text'])
return render(request, 'index.html')
from django.http import HttpRequest
from django.template.loader import render_to_string
from django.test import TestCase
from django.urls import resolve
from lists.views import index
# Create your tests here.
class IndexViewTest(TestCase):
def test_root_url_resolves_to_home_page_view(self):
[...]
def test_index_view_returns_correct_html(self):
request = HttpRequest()
response = index(request)
actual_html = response.content.decode()
expected_html = render_to_string('index.html', request=request)
self.assertEqual(expected_html, actual_html)
def test_index_view_can_save_a_post_request(self):
[...]
Django==2.1.7
pytz==2018.9
selenium==3.141.0
urllib3==1.24.
[...]
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'lists',
]
[...]
--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7f0f12be-fc3e-43c3-ba07-e48158def051%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAN7EoAb8Ov7GXZXV7Eao%3Dj_-w4bKKG75ebF0fnjbTzHO%2BxmB%3DA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMKMUjs28W%3Du-MEj4gUso_ffeK7JTz5EPRv9Qhbf4GdCA7%3DmAA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAN7EoAb8Ov7GXZXV7Eao%3Dj_-w4bKKG75ebF0fnjbTzHO%2BxmB%3DA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAD%3DM5eRFp%3DV6RT7ZTpVroxXyM5tosv9fJ-WQnRQm82AgOcNQ0Q%40mail.gmail.com.