def test_create_without_template(self, render): post.create("no-template") render.assert_called_once_with( paths.post_template, mock.ANY, mock.ANY, )
def test_create_with_template(self, render): post.create("with-template", template="the_template.rst") render.assert_called_once_with( "the_template.rst", mock.ANY, mock.ANY, )
def benchmark(post_count, iterations): print("Running benchmark with %d posts, %d iterations" % (post_count, iterations)) times = [] # setup blog setup() # load content lorem = load_content() # create posts for i in range(post_count): post.create("Post %d" % i).write(tags="tag #%d" % i, content=lorem) for i in range(iterations): print("Iteration %d..." % i) start = datetime.datetime.now() cmdline.build() times.append(datetime.datetime.now() - start) print(times[-1]) # cleanup test dir cleanup() print("Average time: %s" % (sum(times, datetime.timedelta(0)) / len(times)))
def test_readmore(self): post.create("post1", datetime.date(2010, 10, 1)).write( content="Text\n\n.. more::\n\nMore text") self.build() post_path = os.path.join( utils.TEST_ROOT, "blog", "html", "2010", "10", "01", "post1.html") post_html = open(post_path, "r").read() # ensure readmore div is added to post self.assertTrue('<div id="more"> </div>' in post_html) # ensure readmore is patched in aggregated page index_path = os.path.join( utils.TEST_ROOT, "blog", "html", "index.html") index_html = open(index_path, "r").read() expected = ( '<p class="readmorewrapper"><a class="readmore"' ' href="2010/10/01/post1.html#more">Read more...</a></p>' ) self.assertTrue(expected in index_html)
def check_posts(self, filenames, posts, expected): # helper function which creates given list of files and posts, runs a # build, then ensures expected content exists in each file for filename in filenames: with open(os.path.join(paths.root, filename), "w") as f: f.write("content not important") # posts are tuples consisting of post title and content # all posts are created on 2010/10/1 as date is not relevant here for new_post in posts: post.create(new_post[0], datetime.date(2010, 10, 1)).write( content = new_post[1]) # build and check output self.build() # tests are tuples consisting of file path (as a list) and the list of # expected content for test in expected: with open(os.path.join(paths.html, *test[0]), "r") as f: content = f.read() for data in test[1]: if data not in content: print(data) print(content) self.assertTrue(data in content)
def check_posts(self, filenames, posts, expected): # helper function which creates given list of files and posts, runs a # build, then ensures expected content exists in each file for filename in filenames: with open(os.path.join(paths.root, filename), "w") as f: f.write("content not important") # posts are tuples consisting of post title and content # all posts are created on 2010/10/1 as date is not relevant here for new_post in posts: post.create(new_post[0], datetime.date(2010, 10, 1)).write(content=new_post[1]) # build and check output self.build() # tests are tuples consisting of file path (as a list) and the list of # expected content for test in expected: with open(os.path.join(paths.html, *test[0]), "r") as f: content = f.read() for data in test[1]: if data not in content: print(data) print(content) self.assertTrue(data in content)
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 benchmark(post_count, iterations): print("Running benchmark with %d posts, %d iterations" % (post_count, iterations)) times = [] # setup blog setup() # load content lorem = load_content() # create posts for i in range(post_count): post.create("Post %d" % i).write( tags="tag #%d" % i, content=lorem) for i in range(iterations): print("Iteration %d..." % i) start = datetime.datetime.now() cmdline.build() times.append(datetime.datetime.now() - start) print(times[-1]) # cleanup test dir cleanup() print("Average time: %s" % (sum(times, datetime.timedelta(0)) / len(times)))
def test_create(self): # create post with current date new_post = post.create("My Post") year, month, day = tinkerer.utils.split_date() self.assertEquals(year, new_post.year) self.assertEquals(month, new_post.month) self.assertEquals(day, new_post.day) self.assertEquals( os.path.abspath( os.path.join(utils.TEST_ROOT, year, month, day, "my_post.rst")), new_post.path) self.assertTrue(os.path.exists(new_post.path)) # create post with given date new_post = post.create("Date Post", datetime.date(2010, 10, 1)) self.assertEquals("2010", new_post.year) self.assertEquals("10", new_post.month) self.assertEquals("01", new_post.day) self.assertEquals( os.path.abspath( os.path.join(utils.TEST_ROOT, "2010", "10", "01", "date_post.rst")), new_post.path) self.assertTrue(os.path.exists(new_post.path)) self.assertEquals("2010/10/01/date_post", new_post.docname)
def test_disqus(self): TEST_SHORTNAME = "test_shortname" # add disqus_shortname in conf.py utils.update_conf({ "disqus_shortname = None": 'disqus_shortname = "%s"' % TEST_SHORTNAME }) # create a post post.create("post1", datetime.date(2010, 10, 1)) POST_ID = "2010/10/01/post1" POST_LINK = "http://127.0.0.1/blog/html/" + POST_ID + ".html" # build blog self.build() # ensure disqus script is added to html output output = os.path.join(utils.TEST_ROOT, "blog", "html", "2010", "10", "01", "post1.html") output_html = open(output, "r").read() self.assertTrue( disqus.create_thread(TEST_SHORTNAME, POST_ID) in output_html) output = os.path.join(utils.TEST_ROOT, "blog", "html", "index.html") output_html = open(output, "r").read() # ensure script to enable comment count is added to aggregated page self.assertTrue(disqus.enable_count(TEST_SHORTNAME) in output_html) # ensure comment count is added to aggregated page self.assertTrue(disqus.get_count(POST_LINK, POST_ID) in output_html)
def test_disqus(self): TEST_SHORTNAME = "test_shortname" # add disqus_shortname in conf.py utils.update_conf( {"disqus_shortname = None": 'disqus_shortname = "%s"' % TEST_SHORTNAME}) # create a post post.create("post1", datetime.date(2010, 10, 1)) POST_ID = "2010/10/01/post1" POST_LINK = "http://127.0.0.1/blog/html/" + POST_ID + ".html" # build blog self.build() # ensure disqus script is added to html output output = os.path.join(utils.TEST_ROOT, "blog", "html", "2010", "10", "01", "post1.html") output_html = open(output, "r").read() self.assertTrue( disqus.create_thread(TEST_SHORTNAME, POST_ID) in output_html) output = os.path.join(utils.TEST_ROOT, "blog", "html", "index.html") output_html = open(output, "r").read() # ensure script to enable comment count is added to aggregated page self.assertTrue( disqus.enable_count(TEST_SHORTNAME) in output_html) # ensure comment count is added to aggregated page self.assertTrue( disqus.get_count(POST_LINK, POST_ID) in output_html)
def test_build(self): # create a new post post.create("My Post", datetime.date(2010, 10, 1)) self.build() # assert html is produced self.assertTrue(os.path.exists( os.path.join(utils.TEST_ROOT, "blog", "html", "2010", "10", "01", "my_post.html")))
def test_tags(self): utils.test = self # create some tagged posts for new_post in [("Post1", "tag #1"), ("Post2", "tag #2"), ("Post12", "tag #1, tag #2")]: post.create(new_post[0], datetime.date(2010, 10, 1)).write(tags=new_post[1]) utils.hook_extension("test_tags") self.build()
def test_categories(self): utils.test = self # create some posts with categories for new_post in [("Post1", "category #1"), ("Post2", "category #2"), ("Post12", "category #1, category #2")]: post.create(new_post[0], datetime.date(2010, 10, 1)).write( categories=new_post[1]) utils.hook_extension("test_categories") self.build()
def test_missing(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() # hide Sphinx stderr output for the extension exception with mock.patch.object(sys, "stderr"): # build should fail self.build(expected_return=1)
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_categories(self): utils.test = self # create some posts with categories # missing category for Post1 ("cateogry #1,") should work, just issue a warning for new_post in [("Post1", "category #1,"), ("Post2", "category #2"), ("Post12", "category #1, category #2")]: post.create(new_post[0], datetime.date(2010, 10, 1)).write( categories=new_post[1]) utils.hook_extension("test_categories") self.build()
def test_categories(self): utils.test = self # create some posts with categories # missing category for Post1 ("cateogry #1,") should work, just issue a warning for new_post in [("Post1", "category #1,"), ("Post2", "category #2"), ("Post12", "category #1, category #2")]: post.create(new_post[0], datetime.date(2010, 10, 1)).write(categories=new_post[1]) utils.hook_extension("test_categories") 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_master_update(self): post.create("Post 1", datetime.date(2010, 10, 1)) post.create("Post 2", datetime.date(2010, 11, 2)) with open(tinkerer.paths.master_file, "r") as f: lines = f.readlines() for lineno, line in enumerate(lines): if "maxdepth" in line: break self.assertEquals("\n", lines[lineno + 1]) self.assertEquals(" 2010/11/02/post_2\n", lines[lineno + 2]) self.assertEquals(" 2010/10/01/post_1\n", lines[lineno + 3]) self.assertEquals("\n", lines[lineno + 4])
def test_master_update(self): post.create("Post 1", datetime.date(2010, 10, 1)) post.create("Post 2", datetime.date(2010, 11, 2)) with open(tinkerer.paths.master_file, "r") as f: lines = f.readlines() for lineno, line in enumerate(lines): if "maxdepth" in line: break self.assertEquals("\n", lines[lineno+1]) self.assertEquals(" 2010/11/02/post_2\n", lines[lineno+2]) self.assertEquals(" 2010/10/01/post_1\n", lines[lineno+3]) self.assertEquals("\n", lines[lineno+4])
def test_content(self): # create post with no content new_post = post.create("My Post") year, month, day = tinkerer.utils.split_date() # check expected empty post content with open(new_post.path) as f: self.assertEquals(f.readlines(), ["My Post\n", "=======\n", "\n", "\n", "\n", ".. author:: default\n", ".. categories:: none\n", ".. tags:: none\n", ".. comments::\n"]) # update post new_post.write(author="Mr. Py", categories="category 1, category 2", tags="tag 1, tag 2", content="Lorem ipsum") with open(new_post.path) as f: self.assertEquals(f.readlines(), ["My Post\n", "=======\n", "\n", "Lorem ipsum\n", "\n", ".. author:: Mr. Py\n", ".. categories:: category 1, category 2\n", ".. tags:: tag 1, tag 2\n", ".. comments::\n"])
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): # create post with no content new_post = post.create("My Post") year, month, day = tinkerer.utils.split_date() # check expected empty post content with open(new_post.path) as f: self.assertEquals(f.readlines(), [ "My Post\n", "=======\n", "\n", "\n", "\n", ".. author:: default\n", ".. categories:: none\n", ".. tags:: none\n", ".. comments::\n" ]) # update post new_post.write(author="Mr. Py", categories="category 1, category 2", tags="tag 1, tag 2", content="Lorem ipsum") with open(new_post.path) as f: self.assertEquals(f.readlines(), [ "My Post\n", "=======\n", "\n", "Lorem ipsum\n", "\n", ".. author:: Mr. Py\n", ".. categories:: category 1, category 2\n", ".. tags:: tag 1, tag 2\n", ".. comments::\n" ])
def test_create_dashed(self): # chdir to test root and create a dummy conf.py to set the # slug_word_separator cwd = os.getcwd() os.chdir(utils.TEST_ROOT) with open("conf.py", "w") as f: f.write("slug_word_separator = '-'") # create post with current date and dash as word separator new_post = post.create("My __Second Post.") os.chdir(cwd) year, month, day = tinkerer.utils.split_date() self.assertEquals(year, new_post.year) self.assertEquals(month, new_post.month) self.assertEquals(day, new_post.day) self.assertEquals( os.path.abspath( os.path.join(utils.TEST_ROOT, year, month, day, "my-second-post.rst")), new_post.path) self.assertTrue(os.path.exists(new_post.path))
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_create_dashed(self): # chdir to test root and create a dummy conf.py to set the # slug_word_separator cwd = os.getcwd() os.chdir(utils.TEST_ROOT) with open("conf.py", "w") as f: lines = f.write("slug_word_separator = '-'") # create post with current date and dash as word separator new_post = post.create("My __Second Post.") os.chdir(cwd) year, month, day = tinkerer.utils.split_date() self.assertEquals(year, new_post.year) self.assertEquals(month, new_post.month) self.assertEquals(day, new_post.day) self.assertEquals( os.path.abspath(os.path.join( utils.TEST_ROOT, year, month, day, "my-second-post.rst")), new_post.path) self.assertTrue(os.path.exists(new_post.path))
def test_firstpagetitle(self): utils.update_conf({ "first_page_title = None": 'first_page_title = "%s"' % FIRST_PAGE_TITLE }) # create a post post.create("Post1").write() self.build() index_path = os.path.join(utils.TEST_ROOT, "blog", "html", "index.html") index_text = open(index_path, "r").read() # index.html should contain the title self.assertTrue('<a href="#">%s</a>' % FIRST_PAGE_TITLE in index_text)
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_firstpagetitle(self): utils.update_conf( {"first_page_title = None": 'first_page_title = "%s"' % FIRST_PAGE_TITLE}) # create a post post.create("Post1").write() self.build() index_path = os.path.join(utils.TEST_ROOT, "blog", "html", "index.html") index_text = open(index_path, "r").read() # index.html should contain the title self.assertTrue( '<a href="#">%s</a>' % FIRST_PAGE_TITLE in index_text)
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 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_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 post with current date new_post = post.create("My Post") year, month, day = tinkerer.utils.split_date() self.assertEquals(year, new_post.year) self.assertEquals(month, new_post.month) self.assertEquals(day, new_post.day) self.assertEquals( os.path.abspath(os.path.join( utils.TEST_ROOT, year, month, day, "my_post.rst")), new_post.path) self.assertTrue(os.path.exists(new_post.path)) # create post with given date new_post = post.create("Date Post", datetime.date(2010, 10, 1)) self.assertEquals("2010", new_post.year) self.assertEquals("10", new_post.month) self.assertEquals("01", new_post.day) self.assertEquals( os.path.abspath(os.path.join( utils.TEST_ROOT, "2010", "10", "01", "date_post.rst")), new_post.path) self.assertTrue(os.path.exists(new_post.path)) self.assertEquals("2010/10/01/date_post", new_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 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_preview(self): # create a post new_post = post.create("A post", datetime.datetime(2010, 10, 1)) # post should be in master doc (precondition) lines = master.read_master() self.assertTrue(" %s\n" % new_post.docname in lines) # create a draft new_draft = draft.create("draft") self.assertTrue(os.path.exists(new_draft)) # preview it (build should succeed) self.assertEqual(0, cmdline.main(["--preview", new_draft, "-q"])) # draft should not be in TOC for line in master.read_master(): self.assertFalse("draft" in line)
def test_preview(self): # create a post new_post = post.create("A post", datetime.datetime(2010, 10, 1)) # post should be in master doc (precondition) lines = master.read_master() self.assertTrue(" %s\n" % new_post.docname in lines) # create a draft new_draft = draft.create("draft") self.assertTrue(os.path.exists(new_draft)) # preview it (build should succeed) self.assertEquals(0, cmdline.main(["--preview", new_draft, "-q"])) # draft should not be in TOC for line in master.read_master(): self.assertFalse("draft" in line)
def test_create_dashed(self): # create post with current date and dash as word separator new_post = post.create("My __Second Post.", word_sep='-') year, month, day = tinkerer.utils.split_date() self.assertEquals(year, new_post.year) self.assertEquals(month, new_post.month) self.assertEquals(day, new_post.day) self.assertEquals( os.path.abspath(os.path.join( utils.TEST_ROOT, year, month, day, "my-second-post.rst")), new_post.path) self.assertTrue(os.path.exists(new_post.path))
def test_rss(self): # create some posts for new_post in [ ("Post 1", datetime.date(2010, 10, 1), "Lorem ipsum", "category 1"), ("Post 2", datetime.date(2010, 11, 2), "dolor sit", "category 2"), ("Post 3", datetime.date(2010, 12, 3), "amet, consectetuer", "category 3") ]: post.create(new_post[0], new_post[1]).write(content=new_post[2], categories=new_post[3]) self.build() feed_path = os.path.join(paths.html, "rss.html") # check feed was created self.assertTrue(os.path.exists(feed_path)) # check feed content parsed = xml.dom.minidom.parse(feed_path) rss = parsed.getElementsByTagName("rss")[0] channel = rss.getElementsByTagName("channel") doc = channel[0] # validate XML channel data against expected content data = { "title": None, "link": None, "description": None, "language": None, "pubDate": None } data = self.get_data(doc, data) self.assertEquals("My blog", data["title"]) self.assertEquals("http://127.0.0.1/blog/html/", data["link"]) self.assertEquals("Add intelligent tagline here", data["description"]) self.assertEquals("en-us", data["language"]) self.assertEquals(expected_pubdate(2010, 12, 3), data["pubDate"]) # validate XML "item" node content against expected content data = { "link": None, "guid": None, "title": None, "description": None, "category": None, "pubDate": None } for item in [{ "index": 0, "link": "http://127.0.0.1/blog/html/2010/12/03/post_3.html", "title": "Post 3", "description": "amet, consectetuer", "category": "category 3", "pubDate": expected_pubdate(2010, 12, 3) }, { "index": 1, "link": "http://127.0.0.1/blog/html/2010/11/02/post_2.html", "title": "Post 2", "description": "dolor sit", "category": "category 2", "pubDate": expected_pubdate(2010, 11, 2) }, { "index": 2, "link": "http://127.0.0.1/blog/html/2010/10/01/post_1.html", "title": "Post 1", "description": "Lorem ipsum", "category": "category 1", "pubDate": expected_pubdate(2010, 10, 1) }]: data = self.get_data( doc.getElementsByTagName("item")[item["index"]], data) self.assertEquals(item["link"], data["link"]) self.assertEquals(item["link"], data["guid"]) self.assertEquals(item["title"], data["title"]) self.assertTrue(item["description"] in data["description"]) self.assertTrue(item["category"] in data["category"]) self.assertEquals(item["pubDate"], data["pubDate"])
def test_rss(self): # create some posts for new_post in [ ("Post 1", datetime.date(2010, 10, 1), "Lorem ipsum", "category 1"), ("Post 2", datetime.date(2010, 11, 2), "dolor sit", "category 2"), ("Post 3", datetime.date(2010, 12, 3), "amet, consectetuer", "category 3")]: post.create(new_post[0], new_post[1]).write( content=new_post[2], categories=new_post[3]) self.build() feed_path = os.path.join(paths.html, "rss.html") # check feed was created self.assertTrue(os.path.exists(feed_path)) # check feed content doc = xml.dom.minidom.parse(feed_path) doc = doc.getElementsByTagName("rss")[0].getElementsByTagName("channel")[0] # validate XML channel data against expected content data = { "title": None, "link": None, "description": None, "language": None, "pubDate": None } data = self.get_data(doc, data) self.assertEquals("My blog", data["title"]) self.assertEquals("http://127.0.0.1/blog/html/", data["link"]) self.assertEquals("Add intelligent tagline here", data["description"]) self.assertEquals("en-us", data["language"]) self.assertEquals(expected_pubdate(2010, 12, 3), data["pubDate"]) # validate XML "item" node content against expected content data = { "link": None, "guid": None, "title": None, "description": None, "category": None, "pubDate": None } for item in [{"index": 0, "link" : "http://127.0.0.1/blog/html/2010/12/03/post_3.html", "title": "Post 3", "description": "amet, consectetuer", "category": "category 3", "pubDate": expected_pubdate(2010, 12, 3)}, {"index": 1, "link" : "http://127.0.0.1/blog/html/2010/11/02/post_2.html", "title": "Post 2", "description": "dolor sit", "category": "category 2", "pubDate": expected_pubdate(2010, 11, 2)}, {"index": 2, "link" : "http://127.0.0.1/blog/html/2010/10/01/post_1.html", "title": "Post 1", "description": "Lorem ipsum", "category": "category 1", "pubDate": expected_pubdate(2010, 10, 1)}]: data = self.get_data( doc.getElementsByTagName("item")[item["index"]], data) self.assertEquals(item["link"], data["link"]) self.assertEquals(item["link"], data["guid"]) self.assertEquals(item["title"], data["title"]) self.assertTrue(item["description"] in data["description"]) self.assertTrue(item["category"] in data["category"]) self.assertEquals(item["pubDate"], data["pubDate"])
def test_move_duplicate(self): # create initial post post.create("Post1") # should raise post.move("Post1")