1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
# -*- coding: utf-8 -*-
from django.core.management import call_command
from django.test import TestCase
from io import StringIO
from unittest.mock import patch
class FindTemplateTests(TestCase):
@patch("sys.stdout", new_callable=StringIO)
def test_finding_template(self, m_stdout):
call_command("find_template", "admin/change_form.html")
self.assertIn("admin/change_form.html", m_stdout.getvalue())
@patch("sys.stderr", new_callable=StringIO)
def test_should_print_error_when_template_not_found(self, m_stderr):
call_command("find_template", "not_found_template.html")
self.assertIn("No template found", m_stderr.getvalue())
|