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_draft_not_found(self): TestUtility.clear_sys_args() os.mkdir(Config.drafts_dir) os.mkdir(Config.posts_drafts_dir) with self.assertRaises(CommandArgumentError) as err: TestUtility.append_sys_args(['publish', 'A Draft Post To Publish']) Hyde.main() self.assertEqual(err.exception.msg, "No draft found with 'A-Draft-Post-To-Publish' in the title.") TestUtility.remove_directory(Config.drafts_dir) self.assertFalse(os.path.exists(Config.drafts_dir)) TestUtility.clear_sys_args()
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))
def test_publish_draft_post(self): TestUtility.clear_sys_args() TestUtility.append_sys_args(['draft', 'post', 'A Draft Post To Publish']) Hyde.main() actual_title = TestUtility.build_jekyll_post_title('a-draft-post-to-publish') + '.md' actual_file = Config.posts_drafts_dir + actual_title self.assertTrue(os.path.exists(Config.posts_drafts_dir)) self.assertTrue(os.path.isfile(actual_file)) os.mkdir(Config.posts_dir) TestUtility.clear_sys_args() TestUtility.append_sys_args(['publish', 'A Draft Post To Publish']) Hyde.main() self.assertTrue(os.path.exists(Config.posts_dir)) self.assertTrue(os.path.isfile(Config.posts_dir+actual_title)) TestUtility.remove_directory(Config.posts_dir) TestUtility.remove_directory(Config.posts_drafts_dir) TestUtility.remove_directory(Config.drafts_dir) self.assertFalse(os.path.exists(Config.posts_dir)) self.assertFalse(os.path.exists(Config.posts_drafts_dir)) self.assertFalse(os.path.exists(Config.drafts_dir)) TestUtility.clear_sys_args()