def test_conf(self): r = Request({"foo": "bar"}, {}, {}) conf = r.get_configuration() for mem in (r.conf, r.config, r.configuration): yield self.eq_, mem, conf
def test_generate_calendar(self): entry1 = dict(PyCalendarTest.entry1) from Pyblosxom.pyblosxom import Request req = Request({"datadir": self.get_datadir()}, {}, { "entry_list": [entry1], "extensions": {} }) cb_prepare({"request": req}) data = req.get_data() cal = data["calendar"] cal.generate_calendar()
def test_generate_calendar(self): entry1 = dict(PyCalendarTest.entry1) from Pyblosxom.pyblosxom import Request req = Request({"datadir": self.get_datadir()}, {}, {"entry_list": [entry1], "extensions": {}}) cb_prepare({"request": req}) data = req.get_data() cal = data["calendar"] cal.generate_calendar()
def test_story_no_break(self): req = Request({"base_url": "/"}, {}, {"bl_type": "file"}) args = {"entry": {"body": "no break", "file_path": ""}, "request": req} readmore.cb_story(args) self.assertEquals(args["entry"]["body"], "no break")
def category_to_tags(command, argv): """Goes through all entries and converts the category to tags metadata. It adds the tags line as the second line. It maintains the mtime for the file. """ import config datadir = config.py.get("datadir") if not datadir: raise ValueError("config.py has no datadir property.") sep = config.py.get("tags_separator", ",") from Pyblosxom.pyblosxom import Request from Pyblosxom.blosxom import blosxom_entry_parser from Pyblosxom import tools data = {} # register entryparsers so that we parse all possible file types. data["extensions"] = tools.run_callback("entryparser", {"txt": blosxom_entry_parser}, mappingfunc=lambda x, y: y, defaultfunc=lambda x: x) req = Request(config.py, {}, data) # grab all the entries in the datadir filelist = tools.walk(req, datadir) if not datadir.endswith(os.sep): datadir = datadir + os.sep for mem in filelist: print "working on %s..." % mem category = os.path.dirname(mem)[len(datadir):] tags = category.split(os.sep) print " adding tags %s" % tags tags = "#tags %s\n" % (sep.join(tags)) atime, mtime = os.stat(mem)[7:9] fp = open(mem, "r") data = fp.readlines() fp.close() data.insert(1, tags) fp = open(mem, "w") fp.write("".join(data)) fp.close() os.utime(mem, (atime, mtime)) return 0
def test_head_and_foot(self): from Pyblosxom.pyblosxom import Request gfd = get_formatted_date entry1 = dict(W3CDateTest.entry1) entry2 = dict(W3CDateTest.entry2) entry3 = dict(W3CDateTest.entry3) req = Request({}, {}, {"entry_list": [entry1, entry2, entry3]}) entry = {} args = {"entry": entry, "request": req} cb_head(args) self.assertEquals(entry["w3cdate"], gfd(self.entry1)) req = Request({}, {}, {"entry_list": [entry3, entry2, entry1]}) entry = {} args = {"entry": entry, "request": req} cb_head(args) self.assertEquals(entry["w3cdate"], gfd(self.entry3))
def test_get_tagsfile(self): req = Request({"datadir": self.get_datadir()}, {}, {}) cfg = {"datadir": self.get_datadir()} self.assertEquals( tags.get_tagsfile(cfg), os.path.join(self.get_datadir(), os.pardir, "tags.index")) tags_filename = os.path.join(self.get_datadir(), "tags.db") cfg = {"datadir": self.get_datadir(), "tags_filename": tags_filename} self.assertEquals(tags.get_tagsfile(cfg), tags_filename)
def test_story_break_single_file(self): # if showing a single file, then we nix the BREAK bit. req = Request({"base_url": "/"}, {}, {"bl_type": "file"}) args = { "entry": { "body": "no BREAK break\n", "file_path": "" }, "request": req } readmore.cb_story(args) self.assertEquals(args["entry"]["body"], "no break\n")
def test_story_break_index(self): # if showing the entry in an index, then we replace the BREAK # with the template and nix everything after BREAK. req = Request({ "readmore_template": "FOO", "base_url": "/" }, {}, {"bl_type": "dir"}) args = { "entry": { "body": "no BREAK break", "file_path": "" }, "request": req } readmore.cb_story(args) self.assertEquals(args["entry"]["body"], "no FOO")
def buildtags(command, argv): """Command for building the tags index.""" import config datadir = config.py.get("datadir") if not datadir: raise ValueError("config.py has no datadir property.") sep = config.py.get("tags_separator", ",") tagsfile = get_tagsfile(config.py) from Pyblosxom.pyblosxom import blosxom_entry_parser, Request from Pyblosxom import tools from Pyblosxom.entries import fileentry data = {} # register entryparsers so that we parse all possible file types. data["extensions"] = tools.run_callback("entryparser", {"txt": blosxom_entry_parser}, mappingfunc=lambda x, y:y, defaultfunc=lambda x: x) req = Request(config.py, {}, data) # grab all the entries in the datadir filelist = tools.walk(req, datadir) entrylist = [fileentry.FileEntry(req, e, datadir) for e in filelist] tags_to_files = {} for mem in entrylist: tagsline = mem["tags"] if not tagsline: continue tagsline = [t.strip() for t in tagsline.split(sep)] for t in tagsline: tags_to_files.setdefault(t, []).append(mem["filename"]) savefile(tagsfile, tags_to_files) return 0
####################################################################### # This file is part of Pyblosxom. # # Copyright (C) 2011 by the Pyblosxom team. See AUTHORS. # # Pyblosxom is distributed under the MIT license. See the file # LICENSE for distribution details. ####################################################################### from StringIO import StringIO from Pyblosxom.tests import UnitTestBase from Pyblosxom.pyblosxom import Request from Pyblosxom.renderers import blosxom req = Request({}, {}, {}) class TestBlosxomRenderer(UnitTestBase): def test_dollar_parse_problem(self): output = StringIO() renderer = blosxom.BlosxomRenderer(req, output) renderer.flavour = {"story": "$(body)"} # mocking out _run_callback to just return the args dict renderer._run_callback = lambda c, args: args entry = {"body": r'PS1="\u@\h \[\$foo \]\W\[$RST\] \$"'} # the rendered template should be exactly the same as the body # in the entry--no \$ -> $ silliness.
def test_data(self): r = Request({}, {}, {"foo": "bar"}) self.eq_(r.data, r.get_data())
def test_http(self): r = Request({}, {"foo": "bar"}, {}) self.eq_(r.http, r.get_http())