Esempio n. 1
0
    def test_home_page_returns_correct_html(self):
        # Defines a request
        request = HttpRequest()
        # Sends it to home_page view
        response = home_page(request)

        # Check the content of the file
        expected_content = render_to_string('home.html')
        self.assertEqual(expected_content, response.content.decode('utf8'))
Esempio n. 2
0
 def test_home_page_content(self):
     request = HttpRequest()
     response = home_page(request)
     html = response.content.decode('utf8')
     redir = '/location'
     self.assertTrue(html.startswith('<!DOCTYPE html>'))
     self.assertIn('<title>Solar Panel Calculator</title>', html)
     self.assertIn('<h1>Welcome to the Solar Panel Calculator</h1>', html)
     self.assertIn(
         '<p>Here, you can figure out how many solar panels you would need to go off-grid according to your current power usage.</p><br>',
         html)
     self.assertIn(
         "<p>This is meant to be a ballpark figure. This uses data from the Nat'l Renewable Energy Laboratory to grab the amount of useable solar energy in your area, and is only one piece of the puzzle. Going off-grid involves many variables that are best answered by a certified installer.</p><br>",
         html)
     self.assertIn("<a href='/location'>Start!</a>", html)
     self.assertTrue(html.endswith('</html>'))
Esempio n. 3
0
    def test_home_page_returns_correct_html(self):

        # создали HttpRequest object, который использует Django когда пользователь запрашивает страницу.

        request = HttpRequest()

        # перенаправляем запрос на метод home_page view, который формирует response - экземпляр класса HttpResponse. Далее проверяем является ли .content в response HTML-текстом который мы отдаем пользователю.

        response = home_page(request)

        # HTML-текст должен начинаться с html тега, который должен закрываться вконце. response.content является сырым литералом (raw bytes), а не Python-строкой, поэтому мы используем b'' синтаксис.

        self.assertTrue(response.content.startswith(b'<html>'))

        # Мы хотим поместить тег title, содержащий наш заголовок.

        self.assertIn(
            b'<title>Welcome to Django. This is my cool Site!</title>',
            response.content)
        self.assertTrue(response.content.endswith(b'</html>'))
Esempio n. 4
0
 def test_home_page_returns_correct_html(self):
     request = HttpRequest()
     response = home_page(request)
     expected_html = render_to_string('home/home.html')
     self.assertEqual(response.content.decode(), expected_html)
Esempio n. 5
0
 def test_if_home_page_contains_returns_correct_content(self):
     """"""
     request = HttpRequest()
     response = home_page(request)
     html = render_to_string('home/index.html')
     self.assertEqual(response.content, html)
Esempio n. 6
0
 def test_home_page_returns_correct_html(self):
     request = HttpRequest()
     response = home_page(request)
     expected_html = render_to_string('home/home.html')
     self.assertEqual(response.content.decode(), expected_html)