Example #1
0
	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))
Example #2
0
	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))
Example #3
0
	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)
Example #4
0
	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))
Example #5
0
	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))
Example #6
0
	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()
Example #7
0
	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))
Example #8
0
	def test_add_post_no_title(self):
		TestUtility.clear_sys_args()
		TestUtility.append_sys_args(["add", "post"])
		self.verify_system_exit(2)
		TestUtility.clear_sys_args()
Example #9
0
	def test_add_with_unknown_sub_command_with_title(self):
		TestUtility.clear_sys_args()
		TestUtility.append_sys_args(["add", "unknown", "cool title"])
		self.verify_system_exit(2)
		TestUtility.clear_sys_args()
Example #10
0
	def test_add_no_args(self):
		TestUtility.clear_sys_args()
		TestUtility.append_sys_args(["add"])
		self.verify_system_exit(2)
		TestUtility.clear_sys_args()
Example #11
0
	def test_unknown_sub_command_valid_args(self):
		TestUtility.clear_sys_args()
		TestUtility.append_sys_args(["unknown", "post", "cool title"])
		self.verify_system_exit(2)
		TestUtility.clear_sys_args()
Example #12
0
	def test_unknown_sub_command_invalid_post_no_title(self):
		TestUtility.clear_sys_args()
		TestUtility.append_sys_args(["unknown", "port"])
		self.verify_system_exit(2)
Example #13
0
	def test_draft_post_with_title(self):
		TestUtility.clear_sys_args()
		TestUtility.append_sys_args(['draft', 'post', 'draft post title'])
		args = Hyde().process_args()
		self.assertEqual("draft post title", args.title)
		TestUtility.clear_sys_args()
Example #14
0
	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()
Example #15
0
	def test_draft_directory_not_found(self):
		with self.assertRaises(CommandArgumentError) as err:
			TestUtility.append_sys_args(['publish', 'A Draft Post To Publish'])
			Hyde.main()
		self.assertEqual(err.exception.msg, "The drafts directory _drafts/posts/ does not exist.")
Example #16
0
	def test_no_args(self):
		TestUtility.clear_sys_args()
		self.verify_system_exit(2)
		TestUtility.clear_sys_args()
Example #17
0
	def test_draft_page_no_title(self):
		TestUtility.clear_sys_args()
		TestUtility.append_sys_args(["draft", "page"])
		self.verify_system_exit(2)
		TestUtility.clear_sys_args()
Example #18
0
	def test_short_version_option(self):
		TestUtility.clear_sys_args()
		TestUtility.append_sys_args(['-v'])
		self.verify_system_exit(0)
		TestUtility.clear_sys_args()
Example #19
0
	def test_add_page_with_title(self):
		TestUtility.clear_sys_args()
		TestUtility.append_sys_args(['add', 'page', 'page title'])
		args = Hyde().process_args()
		self.assertEqual("page title", args.title)
		TestUtility.clear_sys_args()
Example #20
0
	def test_unknown_sub_command_no_args(self):
		TestUtility.clear_sys_args()
		TestUtility.append_sys_args(["unknown"])
		self.verify_system_exit(2)
		TestUtility.clear_sys_args()