Fakultas Ilmu Komputer UI

Commit 851c8cd9 authored by Kevin Albert Simanjuntak's avatar Kevin Albert Simanjuntak
Browse files

refactor home page view to use a template

parent 4b9b3dc6
Pipeline #20370 passed with stage
in 43 seconds
<html>
<title>To-Do lists</title>
</html>
\ No newline at end of file
<html>
<head>
<meta charset="UTF-8">
<title>Tutorial PMPL</title>
</head>
<body>
<h1>Name: {{ name }}</h1>
<h2> NPM: {{npm}} </h2>
</body>
</html>
\ No newline at end of file
......@@ -3,21 +3,21 @@ from django.test import TestCase
from django.http import HttpRequest
from django.test import Client
from lists.views import home_page
from django.template.loader import render_to_string
class HomePageTest(TestCase):
def test_home_page_returns_correct_html(self):
response = self.client.get('/homepage/')
html = response.content.decode('utf8')
self.assertTrue(html.startswith('<html>'))
self.assertIn('<title>To-Do lists</title>', html)
self.assertTrue(html.strip().endswith('</html>'))
self.assertTemplateUsed(response, 'home.html')
def test_home_page_is_exist(self):
response = Client().get('/homepage/')
self.assertEqual(response.status_code,200)
def test_root_url_resolves_to_home_page_view(self):
found = resolve('/homepage/')
self.assertEqual(found.func, home_page)
def test_home_page_returns_correct_html(self):
request = HttpRequest()
response = home_page(request)
html = response.content.decode('utf8')
self.assertTrue(html.startswith('<html>'))
self.assertIn('<title>Tutorial PMPL</title>', html)
self.assertIn('Kevin Albert Simanjuntak', html)
self.assertTrue(html.endswith('</html>'))
\ No newline at end of file
def test_uses_home_template(self):
response = self.client.get('/homepage/')
self.assertTemplateUsed(response, 'home.html')
\ No newline at end of file
from django.http import HttpResponse
from django.shortcuts import render
# Create your views here.
name = "Kevin Albert Simanjuntak"
npm = "1606835595"
def home_page(request):
response = {"name" : name, "npm" : npm}
return render(request, 'homepage.html', response)
\ No newline at end of file
return render(request, 'home.html')
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment