def test_flavour(self): # flavour var tests # The flavour is the default flavour, the extension of the request, # or the flav= querystring. root = self.get_temp_dir() tools.initialize({}) entries = self.build_file_set(["2007/entry1.txt", "2007/05/entry3.txt", "cata/entry2.txt"]) self.setup_files(entries) try: self._basic_test("/", {"flavour": "html"}) self._basic_test("/index.xml", {"flavour": "xml"}) self._basic_test("/cata/index.foo", {"flavour": "foo"}) # FIXME - need a test for querystring # self._basic_test( "/cata/index.foo", http={ "QUERY_STRING": "flav=bar" }, # expected={ "flavour": "bar" } ) # test that we pick up the default_flavour config variable self._basic_test("/", cfg={"default_flavour": "foo"}, expected={"flavour": "foo"}) # FIXME - need tests for precedence of flavour indicators finally: self.tearDown()
def test_categories_and_dates(self): tools.initialize({}) entries = self.build_file_set(["cata/entry1.txt", "cata/suba/entry1.txt", "catb/entry1.txt"]) self.setup_files(entries) try: # /2006/cata/ self._basic_test("/2006/cata/", {"bl_type": "dir", "pi_yr": "2006", "pi_mo": "", "pi_da": "", "flavour": "html"}) # /2006/04/cata/ self._basic_test("/2006/04/cata/", {"bl_type": "dir", "pi_yr": "2006", "pi_mo": "04", "pi_da": "", "flavour": "html"}) # /2006/04/02/cata/ self._basic_test("/2006/04/02/cata/", {"bl_type": "dir", "pi_yr": "2006", "pi_mo": "04", "pi_da": "02", "flavour": "html"}) # /2006/04/02/cata/suba/ self._basic_test("/2006/04/02/cata/suba/", {"bl_type": "dir", "pi_yr": "2006", "pi_mo": "04", "pi_da": "02", "flavour": "html"}) finally: self.tearDown()
def test_date_categories(self): tools.initialize({}) entries = self.build_file_set(["2007/entry1.txt", "2007/05/entry3.txt", "cata/entry2.txt"]) self.setup_files(entries) try: # /2007/ 2007 here is a category self._basic_test("/2007/", {"bl_type": "dir", "pi_yr": "", "pi_mo": "", "pi_da": "", "flavour": "html"}) # /2007/05 2007/05 here is a category self._basic_test("/2007/05", {"bl_type": "dir", "pi_yr": "", "pi_mo": "", "pi_da": "", "flavour": "html"}) # /2007/05/entry3 2007/05/entry3 is a file self._basic_test("/2007/05/entry3.html", {"bl_type": "file", "pi_yr": "", "pi_mo": "", "pi_da": "", "flavour": "html"}) finally: self.tearDown()
def test_dates(self): tools.initialize({}) self._basic_test( "/2002", { "bl_type": "dir", "pi_yr": "2002", "pi_mo": "", "pi_da": "", "flavour": "html" }) self._basic_test( "/2002/02", { "bl_type": "dir", "pi_yr": "2002", "pi_mo": "02", "pi_da": "", "flavour": "html" }) self._basic_test( "/2002/02/04", { "bl_type": "dir", "pi_yr": "2002", "pi_mo": "02", "pi_da": "04", "flavour": "html" })
def initialize(self): """The initialize step further initializes the Request by setting additional information in the ``data`` dict, registering plugins, and entryparsers. """ data = self._request.get_data() pyhttp = self._request.get_http() config = self._request.get_configuration() # initialize the locale, if wanted (will silently fail if locale # is not available) if config.get('locale', None): try: locale.setlocale(locale.LC_ALL, config['locale']) except locale.Error: # invalid locale pass # initialize the tools module tools.initialize(config) data["pyblosxom_version"] = __version__ data['pi_bl'] = '' # if the user specifies base_url in config, we use that. # otherwise we compose it from SCRIPT_NAME in the environment # or we leave it blank. if not "base_url" in config: if pyhttp.has_key('SCRIPT_NAME'): # allow http and https config['base_url'] = '%s://%s%s' % \ (pyhttp['wsgi.url_scheme'], pyhttp['HTTP_HOST'], pyhttp['SCRIPT_NAME']) else: config["base_url"] = "" # take off the trailing slash for base_url if config['base_url'].endswith("/"): config['base_url'] = config['base_url'][:-1] datadir = config["datadir"] if datadir.endswith("/") or datadir.endswith("\\"): datadir = datadir[:-1] config['datadir'] = datadir # import and initialize plugins plugin_utils.initialize_plugins(config.get("plugin_dirs", []), config.get("load_plugins", None)) # entryparser callback is run here first to allow other # plugins register what file extensions can be used data['extensions'] = tools.run_callback("entryparser", {'txt': blosxom_entry_parser}, mappingfunc=lambda x,y:y, defaultfunc=lambda x:x)
def initialize(self): """The initialize step further initializes the Request by setting additional information in the ``data`` dict, registering plugins, and entryparsers. """ data = self._request.get_data() py_http = self._request.get_http() config = self._request.get_configuration() # initialize the locale, if wanted (will silently fail if locale # is not available) if config.get('locale', None): try: locale.setlocale(locale.LC_ALL, config['locale']) except locale.Error: # invalid locale pass # initialize the tools module tools.initialize(config) data["pyblosxom_version"] = __version__ data['pi_bl'] = '' # if the user specifies base_url in config, we use that. # otherwise we compose it from SCRIPT_NAME in the environment # or we leave it blank. if not "base_url" in config: if py_http.has_key('SCRIPT_NAME'): # allow http and https config['base_url'] = '%s://%s%s' % \ (py_http['wsgi.url_scheme'], py_http['HTTP_HOST'], py_http['SCRIPT_NAME']) else: config["base_url"] = "" # take off the trailing slash for base_url if config['base_url'].endswith("/"): config['base_url'] = config['base_url'][:-1] data_dir = config["datadir"] if data_dir.endswith("/") or data_dir.endswith("\\"): data_dir = data_dir[:-1] config['datadir'] = data_dir # import and initialize plugins plugin_utils.initialize_plugins(config.get("plugin_dirs", []), config.get("load_plugins", None)) # entryparser callback is run here first to allow other # plugins register what file extensions can be used data['extensions'] = tools.run_callback("entryparser", {'txt': blosxom_entry_parser}, mappingfunc=lambda x, y: y, defaultfunc=lambda x: x)
def test_dates(self): tools.initialize({}) self._basic_test("/2002", {"bl_type": "dir", "pi_yr": "2002", "pi_mo": "", "pi_da": "", "flavour": "html"}) self._basic_test("/2002/02", {"bl_type": "dir", "pi_yr": "2002", "pi_mo": "02", "pi_da": "", "flavour": "html"}) self._basic_test("/2002/02/04", {"bl_type": "dir", "pi_yr": "2002", "pi_mo": "02", "pi_da": "04", "flavour": "html"})
def test_url(self): # url var tests # The url is the HTTP PATH_INFO env variable. tools.initialize({}) entries = self.build_file_set(["2007/entry1.txt", "2007/05/entry3.txt", "cata/entry2.txt"]) self.setup_files(entries) try: self._basic_test("/", {"url": "http://www.example.com/"}) self._basic_test("/index.xml", {"url": "http://www.example.com/index.xml"}) self._basic_test("/cata/index.foo", {"url": "http://www.example.com/cata/index.foo"}) finally: self.tearDown()
def test_pi_bl(self): # pi_bl var tests # pi_bl is the entry the user requested to see if the request indicated # a specific entry. It's the empty string otherwise. tools.initialize({}) entries = self.build_file_set( ["2007/entry1.txt", "2007/05/entry3.txt", "cata/entry2.txt"]) self.setup_files(entries) try: self._basic_test("", {"pi_bl": ""}) self._basic_test("/", {"pi_bl": "/"}) self._basic_test("/index.xml", {"pi_bl": "/index.xml"}) self._basic_test("/2007/index.xml", {"pi_bl": "/2007/index.xml"}) self._basic_test("/cata/entry2", {"pi_bl": "/cata/entry2"}) finally: self.tearDown()
def test_pi_bl(self): # pi_bl var tests # pi_bl is the entry the user requested to see if the request indicated # a specific entry. It's the empty string otherwise. tools.initialize({}) entries = self.build_file_set(["2007/entry1.txt", "2007/05/entry3.txt", "cata/entry2.txt"]) self.setup_files(entries) try: self._basic_test("", {"pi_bl": ""}) self._basic_test("/", {"pi_bl": "/"}) self._basic_test("/index.xml", {"pi_bl": "/index.xml"}) self._basic_test("/2007/index.xml", {"pi_bl": "/2007/index.xml"}) self._basic_test("/cata/entry2", {"pi_bl": "/cata/entry2"}) finally: self.tearDown()
def setUp(self, plugin_module): """Subclasses should call this in their setUp() methods. The plugin_module arg is the plugin module being tested. This is used to set the plugin_dir config variable. """ # freeze time self.timestamp = TIMESTAMP self.frozen_time = self.freeze_pyblosxom_time(self.timestamp) self.timestamp_asc = time.ctime(self.timestamp) gmtime = time.gmtime(self.timestamp) self.timestamp_date = time.strftime('%a %d %b %Y', gmtime) self.timestamp_w3c = time.strftime('%Y-%m-%dT%H:%M:%SZ', gmtime) # set up config, including datadir and plugin_dirs self.datadir = tempfile.mkdtemp(prefix='pyblosxom_test_datadir') plugin_file = os.path.dirname(plugin_module.__file__) self.config_base = { 'datadir': self.datadir, 'plugin_dirs': [plugin_file], 'base_url': 'http://bl.og/', } self.config = self.config_base tools.initialize(self.config) # set up environment vars and http request self.environ = {'PATH_INFO': '/', 'REMOTE_ADDR': ''} self.form_data = '' self.request = pyblosxom.Request(self.config, self.environ, {}) self.http = self.request.get_http() # set up entries and data dict self.entry_name = 'test_entry' entry_properties = {'absolute_path': '.', 'fn': self.entry_name} self.entry = entries.base.generate_entry(self.request, entry_properties, {}, gmtime) self.entry_list = [self.entry] self.data = { 'entry_list': self.entry_list, 'bl_type': 'file', } self.request._data = self.data # set up renderer and templates self.renderer = Renderer(self.request) self.renderer.set_content(self.entry_list) templates = ('content_type', 'head', 'story', 'foot', 'date_head', 'date_foot') self.renderer.flavour = dict([(t, t) for t in templates]) # populate args dict self.args = { 'request': self.request, 'renderer': self.renderer, 'entry': self.entry, 'template': 'template starts:', } # this stores the callbacks that have been injected. it maps # callback names to the injected methods to call. any # callbacks that haven't been injected are passed through to # pyblosxom's callback chain. # # use inject_callback() to inject a callback. self.injected_callbacks = {} orig_run_callback = tools.run_callback def intercept_callback(name, args, **kwargs): if name in self.injected_callbacks: return self.injected_callbacks[name]() else: return orig_run_callback(name, args, **kwargs) tools.run_callback = intercept_callback
def setUp(self, plugin_module): """Subclasses should call this in their setUp() methods. The plugin_module arg is the plugin module being tested. This is used to set the plugin_dir config variable. """ # freeze time self.timestamp = TIMESTAMP self.frozen_time = self.freeze_pyblosxom_time(self.timestamp) self.timestamp_asc = time.ctime(self.timestamp) gmtime = time.gmtime(self.timestamp) self.timestamp_date = time.strftime('%a %d %b %Y', gmtime) self.timestamp_w3c = time.strftime('%Y-%m-%dT%H:%M:%SZ', gmtime) # set up config, including datadir and plugin_dirs self.datadir = tempfile.mkdtemp(prefix='pyblosxom_test_datadir') plugin_file = os.path.dirname(plugin_module.__file__) self.config_base = {'datadir': self.datadir, 'plugin_dirs': [plugin_file], 'base_url': 'http://bl.og/', } self.config = self.config_base tools.initialize(self.config) # set up environment vars and http request self.environ = {'PATH_INFO': '/', 'REMOTE_ADDR': ''} self.form_data = '' self.request = pyblosxom.Request(self.config, self.environ, {}) self.http = self.request.get_http() # set up entries and data dict self.entry_name = 'test_entry' entry_properties = {'absolute_path': '.', 'fn': self.entry_name} self.entry = entries.base.generate_entry( self.request, entry_properties, {}, gmtime) self.entry_list = [self.entry] self.data = {'entry_list': self.entry_list, 'bl_type': 'file', } self.request._data = self.data # set up renderer and templates self.renderer = Renderer(self.request) self.renderer.set_content(self.entry_list) templates = ('content_type', 'head', 'story', 'foot', 'date_head', 'date_foot') self.renderer.flavour = dict([(t, t) for t in templates]) # populate args dict self.args = {'request': self.request, 'renderer': self.renderer, 'entry': self.entry, 'template': 'template starts:', } # this stores the callbacks that have been injected. it maps # callback names to the injected methods to call. any # callbacks that haven't been injected are passed through to # pyblosxom's callback chain. # # use inject_callback() to inject a callback. self.injected_callbacks = {} orig_run_callback = tools.run_callback def intercept_callback(name, args, **kwargs): if name in self.injected_callbacks: return self.injected_callbacks[name]() else: return orig_run_callback(name, args, **kwargs) tools.run_callback = intercept_callback