palindrome-django/web/palindromes/tests.py
2021-03-23 21:25:45 +01:00

20 lines
680 B
Python

from django.urls import resolve
from django.test import TestCase
from django.http import HttpRequest
from palindromes.views import caculate_palindromes
class HomePageTest(TestCase):
def test_root_url_resolves_to_calculate_palindrome_view(self):
found = resolve('/')
self.assertEqual(found.func, caculate_palindromes)
def test_home_page_returns_correct_html(self):
request = HttpRequest()
response = caculate_palindromes(request)
html = response.content.decode('utf8')
self.assertTrue(html.startswith('<html>'))
self.assertIn('<title>Palindromes!</title>', html)
self.assertTrue(html.endswith('</html>'))