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))