From 62d0aa159fc046a27bed47e337d787a08f4687d0 Mon Sep 17 00:00:00 2001 From: Sunaina Pai Date: Sat, 17 Mar 2018 14:45:21 +0530 Subject: Add makesite: A simple static site generator --- test/test_main.py | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 test/test_main.py (limited to 'test/test_main.py') diff --git a/test/test_main.py b/test/test_main.py new file mode 100644 index 0000000..50f1cc5 --- /dev/null +++ b/test/test_main.py @@ -0,0 +1,73 @@ +import unittest +import makesite +import os +import shutil +import json + +from test import path + + +class MainTest(unittest.TestCase): + def setUp(self): + path.move('_site', '_site.backup') + path.move('params.json', 'params.json.backup') + + def tearDown(self): + path.move('_site.backup', '_site') + path.move('params.json.backup', 'params') + + def test_site_missing(self): + makesite.main() + + def test_site_exists(self): + os.mkdir('_site') + with open('_site/foo.txt', 'w') as f: + f.write('foo') + + self.assertTrue(os.path.isfile('_site/foo.txt')) + makesite.main() + self.assertFalse(os.path.isfile('_site/foo.txt')) + + def test_default_params(self): + makesite.main() + + with open('_site/blog/proin-quam/index.html') as f: + s1 = f.read() + + with open('_site/blog/rss.xml') as f: + s2 = f.read() + + shutil.rmtree('_site') + + self.assertIn('Home', s1) + self.assertIn('Proin Quam - Lorem Ipsum', s1) + self.assertIn('Published on 2018-01-01 by Admin', s1) + + self.assertIn('http://localhost:8000/', s2) + self.assertIn('http://localhost:8000/blog/proin-quam/', s2) + + def test_json_params(self): + params = { + 'base_path': '/base', + 'subtitle': 'Foo', + 'author': 'Bar', + 'site_url': 'http://localhost/base' + } + with open('params.json', 'w') as f: + json.dump(params, f) + makesite.main() + + with open('_site/blog/proin-quam/index.html') as f: + s1 = f.read() + + with open('_site/blog/rss.xml') as f: + s2 = f.read() + + shutil.rmtree('_site') + + self.assertIn('Home', s1) + self.assertIn('Proin Quam - Foo', s1) + self.assertIn('Published on 2018-01-01 by Bar', s1) + + self.assertIn('http://localhost/base/', s2) + self.assertIn('http://localhost/base/blog/proin-quam/', s2) -- cgit v1.2.3