def test_move(self): # create a "pre-existing" file draft_file = os.path.join(utils.TEST_ROOT, "drafts", "afile.rst") with open(draft_file, "w") as f: f.write("Content") # move file to post moved_post = post.move(draft_file, datetime.date(2010, 10, 1)) self.assertEquals("2010", moved_post.year) self.assertEquals("10", moved_post.month) self.assertEquals("01", moved_post.day) self.assertEquals( os.path.abspath(os.path.join( utils.TEST_ROOT, "2010", "10", "01", "afile.rst")), moved_post.path) self.assertTrue(os.path.exists(moved_post.path)) self.assertFalse(os.path.exists(draft_file)) self.assertEquals("2010/10/01/afile", moved_post.docname)
def create_post(title, date, template): ''' Creates a new post with the given title or makes an existing file a post. ''' move = os.path.exists(title) if move: new_post = post.move(title, date) else: new_post = post.create(title, date, template) output.filename.info(new_post.path) if move: output.write.info("Draft moved to post '%s'" % new_post.path) else: output.write.info("New post created as '%s'" % new_post.path)
def preview_draft(draft_file): ''' Rebuilds the blog, including the given draft. ''' if not os.path.exists(draft_file): raise Exception("Draft named '%s' does not exist" % draft_file) # promote draft preview_post = post.move(draft_file) try: # rebuild result = build() finally: # demote post back to draft draft.move(preview_post.path) return result
def test_move_duplicate(self): # create initial post post.create("Post1") # should raise post.move("Post1")