def test_create_with_template(self, render): page.create('with-template', template='the_template.rst') render.assert_called_once_with( 'the_template.rst', mock.ANY, mock.ANY, )
def build_theme(use_theme): # setup blog setup() # write conf file with given theme writer.write_conf_file(theme=use_theme) # load content lorem = load_content() # create posts post.create("This is a post", datetime.date(2010, 10, 1)).write(tags="tag #1, tag #2", content=lorem) post.create("This is another post", datetime.date(2010, 11, 2)).write(tags="tag #1", content=lorem) post.create("This is yet another post", datetime.date(2010, 12, 3)).write(tags="tag #2", content=lorem) # create pages page.create("First page").write() page.create("Second page").write() # build cmdline.build()
def test_landingpage(self): # set landing_page option in conf.py utils.update_conf( {"landing_page = None": 'landing_page = "%s"' % LANDING_PAGE}) # create some posts for new_post in [("Post1", "Post2", "Post3")]: post.create(new_post[0]).write() # create the landing page page.create(LANDING_PAGE) self.build() # index.html should redirect to landing page self.assertTrue( '<meta http-equiv="REFRESH" content="0; url=./pages/%s.html" />' % LANDING_PAGE in self.__get_index_text()) # there should be page1.html aggregated page self.assertTrue( os.path.exists(os.path.join( utils.TEST_ROOT, "blog", "html", "page1.html")))
def test_create_without_template(self, render): page.create('no-template') render.assert_called_once_with( paths.page_template, mock.ANY, mock.ANY, )
def build_theme(use_theme): # setup blog setup() # write conf file with given theme writer.write_conf_file(theme=use_theme) # load content lorem = load_content() # create posts post.create("This is a post", datetime.date(2010, 10, 1)).write( tags="tag #1, tag #2", content=lorem) post.create("This is another post", datetime.date(2010, 11, 2)).write( tags="tag #1", content=lorem) post.create("This is yet another post", datetime.date(2010, 12, 3)).write( tags="tag #2", content=lorem) # create pages page.create("First page").write() page.create("Second page").write() # build cmdline.build()
def test_master_update(self): page.create("Page 1") page.create("Page 2") with open(tinkerer.paths.master_file, "r") as f: lines = f.readlines() self.assertEquals(" pages/page_1\n", lines[-3]) self.assertEquals(" pages/page_2\n", lines[-2])
def test_ordering(self): utils.test = self # create some pages and posts page.create("First Page") post.create("Oldest Post", datetime.date(2010, 10, 1)) post.create("Newer Post", datetime.date(2010, 10, 1)) page.create("Another Page") post.create("Newest Post", datetime.date(2010, 10, 1)) utils.hook_extension("test_ordering") self.build()
def test_metadata(self): utils.test = self # create some posts for i in range(20): post.create("Post %d" % i, datetime.date(2010, 10, i + 1)).write(content=" ".join("a" * 100)) # ... and some pages for i in range(10): page.create("Page %d" % i) utils.hook_extension("test_metadata") self.build()
def test_metadata(self): utils.test = self # create some posts for i in range(20): post.create("Post %d" % i, datetime.date( 2010, 10, i + 1)).write(content=" ".join("a" * 100)) # ... and some pages for i in range(10): page.create("Page %d" % i) utils.hook_extension("test_metadata") self.build()
def test_move(self): # create a post and a page new_post = post.create("A post", datetime.datetime(2010, 10, 1)) new_page = page.create("A page") # page and posts should be in master doc (precondition) lines = master.read_master() self.assertTrue(" %s\n" % new_post.docname in lines) self.assertTrue(" %s\n" % new_page.docname in lines) new_draft = draft.move(os.path.join(utils.TEST_ROOT, "pages", "a_page.rst")) self.assertTrue(os.path.exists(new_draft)) # page should no longer be in TOC lines = master.read_master() self.assertTrue(" %s\n" % new_post.docname in lines) self.assertFalse(" %s\n" % new_page.docname in lines) new_draft = draft.move(os.path.join(utils.TEST_ROOT, "2010", "10", "01", "a_post.rst")) self.assertTrue(os.path.exists(new_draft)) # post should no longer be in TOC either lines = master.read_master() self.assertFalse(" %s\n" % new_post.docname in lines) self.assertFalse(" %s\n" % new_page.docname in lines)
def test_move(self): # create a post and a page new_post = post.create("A post", datetime.datetime(2010, 10, 1)) new_page = page.create("A page") # page and posts should be in master doc (precondition) lines = master.read_master() self.assertTrue(" %s\n" % new_post.docname in lines) self.assertTrue(" %s\n" % new_page.docname in lines) new_draft = draft.move( os.path.join(utils.TEST_ROOT, "pages", "a_page.rst")) self.assertTrue(os.path.exists(new_draft)) # page should no longer be in TOC lines = master.read_master() self.assertTrue(" %s\n" % new_post.docname in lines) self.assertFalse(" %s\n" % new_page.docname in lines) new_draft = draft.move( os.path.join(utils.TEST_ROOT, "2010", "10", "01", "a_post.rst")) self.assertTrue(os.path.exists(new_draft)) # post should no longer be in TOC either lines = master.read_master() self.assertFalse(" %s\n" % new_post.docname in lines) self.assertFalse(" %s\n" % new_page.docname in lines)
def test_content(self): new_page = page.create("My Page") # check expected empty page content with open(new_page.path) as f: self.assertEquals(f.readlines(), ["My Page\n", "=======\n", "\n"])
def test_nolandingpage(self): # create some posts for new_post in [("Post1", "Post2", "Post3")]: post.create(new_post[0]).write() # create the landing page page.create(LANDING_PAGE) self.build() # index.html should not redirect to landing page self.assertFalse( '<meta http-equiv="REFRESH" content="0; url=./pages/%s.html" />' % LANDING_PAGE in self.__get_index_text()) # there should be no page1.html aggregated page self.assertFalse( os.path.exists( os.path.join(utils.TEST_ROOT, "blog", "html", "page1.html")))
def test_create(self): # create page new_page = page.create("My Page") self.assertEquals( os.path.abspath( os.path.join(utils.TEST_ROOT, "pages", "my_page.rst")), new_page.path) self.assertTrue(os.path.exists(new_page.path)) self.assertEquals("pages/my_page", new_page.docname)
def test_nolandingpage(self): # create some posts for new_post in [("Post1", "Post2", "Post3")]: post.create(new_post[0]).write() # create the landing page page.create(LANDING_PAGE) self.build() # index.html should not redirect to landing page self.assertFalse( '<meta http-equiv="REFRESH" content="0; url=./pages/%s.html" />' % LANDING_PAGE in self.__get_index_text()) # there should be no page1.html aggregated page self.assertFalse( os.path.exists(os.path.join( utils.TEST_ROOT, "blog", "html", "page1.html")))
def test_create(self): # create page new_page = page.create("My Page") self.assertEquals( os.path.abspath(os.path.join( utils.TEST_ROOT, "pages", "my_page.rst")), new_page.path) self.assertTrue(os.path.exists(new_page.path)) self.assertEquals("pages/my_page", new_page.docname)
def create_page(title, template): ''' Creates a new page with the given title or makes an existing file a page. ''' move = os.path.exists(title) if move: new_page = page.move(title) else: new_page = page.create(title, template) output.filename.info(new_page.path) if move: output.write.info("Draft moved to page '%s'" % new_page.path) else: output.write.info("New page created as '%s'" % new_page.path)
def test_create_duplicate(self): # create initial post page.create("Page1") # should raise page.create("Page1")
def test_move_duplicate(self): # create initial page page.create("Page1") # should raise page.move("Page1")