def test_create_jekyll_post_title(self): """ Tests the creation of Jekyll post title using the Jekyll format. """ actual_title = Hyde.create_jekyll_post_title('title for this unit test') expected_title = TestUtility.build_jekyll_post_title('title-for-this-unit-test') self.assertEquals(expected_title, actual_title)
def test_main_draft_post_with_title(self): args = MockArguments(sub_command='draft', draft_item_type='post', title="real title") Hyde.handle_sub_command(args) path = '_drafts/posts/' expected_title = TestUtility.build_jekyll_post_title('real-title') + '.md' self.assertTrue(os.path.isfile(path + expected_title)) os.remove(path + expected_title) shutil.rmtree(path) self.assertFalse(os.path.isfile(path + expected_title)) 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_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()