def test_new_post(self, l): with tmp_folder(project=True): cmd = Commands({'<name>': 'Hello World !'}) cmd.new_post() regex = re.compile(r"New post created : .*hello-world.*") self.assertTrue(regex.match(l.records[0].getMessage()))
def test_new_post_already_exists(self, l): with tmp_folder(project=True): cmd = Commands( {'<name>': 'Hello World !', '--force': False} ) with self.assertRaises(PostExists): for _ in range(2): cmd.new_post()
def test_new_post_exits_with_force(self, l): with tmp_folder(project=True): cmd = Commands( {'<name>': 'Hello World !', '--force': True} ) for _ in range(2): cmd.new_post() regex = re.compile( r"New post created : .*hello-world.*", re.DOTALL ) self.assertTrue(regex.match(l.records[0].getMessage())) self.assertTrue(regex.match(l.records[1].getMessage()))
def test_generate_with_drafted_posts(self, l): with tmp_folder(project=True): for post in POSTS_LIST.values(): cmd = Commands({'<name>': post}) cmd.new_post() cmd.generate() self.assertEqual( "Processed 1 post and 1 page", l.records[5].getMessage() ) self.assertEqual( "5 drafts remaining", l.records[6].getMessage() )