Fakultas Ilmu Komputer UI

tests.py 756 Bytes
Newer Older
1
2
from django.test import TestCase, Client
from django.urls import resolve
Samuel Dimas's avatar
Samuel Dimas committed
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class TemplateLoaderTest(TestCase):
    def test_template_loader_url_exist(self):
        url = "/test-page.html"
        response = Client().get(url)
        self.assertEqual(response.status_code,200)

    def test_template_loader_using_template_loader_template(self):
        url = "/test-page.html"
        response = Client().get(url)
        expected_template_name = "test-page.html"
        self.assertTemplateUsed(response, expected_template_name)

    def test_template_loader_using_template_loader_func(self):
        url = "/test-page.html"
        found = resolve(url)
        expected_view_name = "pages"
        self.assertEqual(found.func.__name__, expected_view_name)