def test_about_page(self): """Parsing basic page should work as with posts""" page = Page.from_file(self.pages_path.joinpath('about.md'), settings=self.settings) self.assertEqual(page.title, 'About majestic') self.assertEqual(page.slug, 'about') self.assertEqual( page.body, ('Majestic makes websites out of markdown files.\n\n' 'It is written in Python and was started by Rob Wells.'))
def test_Page_eq(self): """Two distinct Page objects with same attrs compare equal Page doesn't have its own __eq__ implementation as it's just a concrete version of Content, but Page does properly handle calls to self.output_path and self.url, while Content raises NotImplementedError (correctly). Since Content is not meant to be instantiated, it's fair to test the superclass's implementation of __eq__ through a subclass. (And __eq__ belongs on the superclass because otherwise both Page and Post would have to implement almost exactly the same method.) """ page_a = Page(title=self.title, body=self.body, settings=self.settings) page_b = Page(title=self.title, body=self.body, settings=self.settings) page_c = Page(title='different', body=self.body, settings=self.settings) self.assertEqual(page_a, page_b) self.assertNotEqual(page_a, page_c)
def setUp(self): os.chdir(str(TEST_BLOG_DIR)) self.settings = load_settings() ext_dir_name = self.settings['paths']['extensions root'] self.ext_dir = TEST_BLOG_DIR.joinpath(ext_dir_name) self.posts = [ Post(title='test', body='test', date=datetime.now(), settings=self.settings) ] self.pages = [Page(title='test', body='test', settings=self.settings)]
def setUp(self): os.chdir(TEST_BLOG_DIR) settings_path = TEST_BLOG_DIR.joinpath('settings.json') self.settings = load_settings(files=[settings_path], local=False) self.output_dir = Path(self.settings['paths']['output root']) self.files = [ Post(title='', slug='post', date=datetime(2015, 1, 1), body='', settings=self.settings), Page(title='', slug='page', body='', settings=self.settings), Index(posts=[], settings=self.settings, page_number=1), ] # Make dummy files and directories for f in self.files: f.output_path.parent.mkdir(parents=True, exist_ok=True) f.output_path.touch()
def test_page_path_part(self): """path_part correctly formats and stores Page's path part Path part here refers to the 'path' section of a URL, for example: http://example.com/path/part.html This is the same as the path underneath the output root directory: /.../blog/output/path/part.html Since both are identical it is sensible for the path to be created in one place in the class and stored, with .output_path and .url both looking in one place for them. """ page = Page(title=self.title, body=self.body, settings=self.settings, slug='abc') path_template = self.settings['paths']['page path template'] path = path_template.format(content=page) self.assertEqual(path, page.path_part)
def test_page_output_path_and_url(self): """Page defines output_path and url properties Output path should be a pathlib.Path object, url a str """ page = Page(title=self.title, body=self.body, settings=self.settings, slug='abc') path_template = self.settings['paths']['page path template'] path = path_template.format(content=page) output_dir = self.settings['paths']['output root'] site_url = self.settings['site']['url'] expected_output = Path(output_dir, path) expected_url = site_url + '/' + path self.assertEqual(expected_output, page.output_path) self.assertEqual(expected_url, page.url)
def test_page_inheritance(self): """Page instances are also an instance of Content""" page = Page(title=self.title, body=self.body, settings=self.settings) self.assertTrue(isinstance(page, Content))