# HG changeset patch # User Brian Neal # Date 1749214975 18000 # Node ID 26be530e84558396906198f3578139790b9c66a3 # Parent 25739432af729165c9016af62db0cb717f0611f0 Add test for make_fixed_page command. diff -r 25739432af72 -r 26be530e8455 core/tests/management/commands/test_make_fixed_page.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/tests/management/commands/test_make_fixed_page.py Fri Jun 06 08:02:55 2025 -0500 @@ -0,0 +1,58 @@ +"""Test for the make_fixed_page management command.""" +import os.path +import shutil +from StringIO import StringIO +import tempfile +import textwrap +import unittest + +from django.core.management import call_command +from mock import patch + + +class MakeFixedPageTestCase(unittest.TestCase): + RST_SAMPLE = textwrap.dedent("""\ + ======== + Test RST + ======== + + Here is some sample text. + """) + + EXPECTED_HTML = textwrap.dedent("""\ +
+
+

Test RST

+

Here is some sample text.

+
+
+ """) + + def setUp(self): + # Create temp directory structure. + self.temp_root = tempfile.mkdtemp() + fixed_dir = os.path.join(self.temp_root, 'fixed') + os.mkdir(fixed_dir) + + self.template_dir = os.path.join(self.temp_root, 'templates', 'fixed') + os.makedirs(self.template_dir) + + # Create a sample .rst file to work with. + self.temp_rst = os.path.join(fixed_dir, 'sample.rst') + fp = open(self.temp_rst, mode='w') + fp.write(self.RST_SAMPLE) + fp.close() + + def tearDown(self): + shutil.rmtree(self.temp_root) + + def test_make_fixed_page(self): + out = StringIO() + with patch('core.management.commands.make_fixed_page.settings' + '.PROJECT_PATH', new=self.temp_root): + call_command('make_fixed_page', 'sample.rst', stdout=out) + self.assertEqual(out.getvalue(), + 'sample.rst -> templates/fixed/sample.html\n') + out.close() + with open(os.path.join(self.template_dir, 'sample.html')) as fp: + self.assertEqual(fp.read(), self.EXPECTED_HTML)