def test_main_add_page_with_title(self): args = MockArguments(sub_command='add', add_item_type='page', title="RealPage") Hyde.handle_sub_command(args) path = args.title + '/' page_file = path + 'index.md' self.assertTrue(os.path.isfile(page_file)) TestUtility.remove_file(page_file) self.assertFalse(os.path.isfile(page_file)) TestUtility.remove_directory(path) self.assertFalse(os.path.exists(path))
def test_handle_add_post(self): post_title = 'a test title' path = '_posts/' Hyde._handle_add_post(post_title, path) actual_title = TestUtility.build_jekyll_post_title('a-test-title') + '.md' actual_file = path + actual_title self.assertTrue(os.path.exists(path)) self.assertTrue(os.path.isfile(actual_file)) expected_post_contents = JekyllPostTest.get_expected_post_contents(post_title) actual_post_contents = JekyllPostTest.get_actual_post_contents(actual_file) self.assertEqual(expected_post_contents, actual_post_contents) TestUtility.remove_file(actual_file) self.assertFalse(os.path.isfile(actual_file)) TestUtility.remove_directory(path) self.assertFalse(os.path.exists(path))
def test_handle_add_duplicate_post(self): post_title = 'a test title' Hyde._handle_add_post(post_title) path = '_posts/' actual_title = TestUtility.build_jekyll_post_title('a-test-title') + '.md' actual_file = path + actual_title self.assertTrue(os.path.exists(path)) self.assertTrue(os.path.isfile(actual_file)) with self.assertRaises(DuplicatePostError) as err: Hyde._handle_add_post(post_title) self.assertEqual("The file " + path + actual_title + " already exists. Nothing Created.", err.exception.msg) TestUtility.remove_file(actual_file) self.assertFalse(os.path.isfile(actual_file)) TestUtility.remove_directory(path) self.assertFalse(os.path.exists(path))
def test_handle_add_new_page(self): """ Tests adding a page and ensures the file is created. Then cleans up the file and the directory. """ page_name = 'TestPage' actual_file_name = 'index.md' Hyde._handle_add_page(page_name) actual_file = page_name + '/' + actual_file_name self.assertTrue(os.path.exists(page_name)) self.assertTrue(os.path.isfile(actual_file)) expected_page_contents = JekyllPageTest.get_expected_page_contents(page_name) actual_page_contents = JekyllPageTest.get_actual_page_contents(actual_file) self.assertEqual(expected_page_contents, actual_page_contents) TestUtility.remove_file(actual_file) self.assertFalse(os.path.isfile(actual_file)) TestUtility.remove_directory(page_name) self.assertFalse(os.path.exists(page_name))