コード例 #1
0
ファイル: __init__.py プロジェクト: B-Rich/douglas
    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.
        """
        UnitTestBase.setUp(self)

        # freeze time
        self.timestamp = TIMESTAMP
        self.frozen_time = self.freeze_douglas_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)

        plugin_file = os.path.dirname(plugin_module.__file__)
        self.config = Config.validate({
            'datadir': self.datadir,
            'themedir': self.themedir,
            'plugin_dirs': [plugin_file],
            'base_url': 'http://example.com',
        })

        # set up environment vars and http request
        self.environ = {'PATH_INFO': '/', 'REMOTE_ADDR': ''}
        self.form_data = ''
        self.request = app.Request(self.config, self.environ, {})
        self.http = self.request.get_http()

        # set up entries and data dict
        self.data = {
            'entry_list': self.generate_entry_list(self.request, 1),
            'bl_type': 'entry',
        }
        self.request._data = self.data

        # 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
        # Douglas'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
コード例 #2
0
ファイル: __init__.py プロジェクト: B-Rich/douglas
    def build_request(self, cfg=None, http=None, data=None, inputstream=""):
        """
        process_path_info uses:
        - req.pyhttp["PATH_INFO"]         - string

        - req.config["default_theme"]     - string
        - req.config["datadir"]           - string
        - req.config["blog_title"]        - string
        - req.config["base_url"]          - string
        - req.config["extensions"]        - dict of string -> func

        if using req.get_form():
        - req.pyhttp["wsgi.input"]        - StringIO instance
        - req.pyhttp["REQUEST_METHOD"]    - GET or POST
        - req.pyhttp["CONTENT_LENGTH"]    - integer
        """
        _config = {
            'default_theme': 'html',
            'datadir': self.datadir,
            'themedir': self.themedir,
            'blog_title': 'My blog',
            'base_url': 'http://www.example.com'
        }
        if cfg:
            _config.update(cfg)

        _config = Config.validate(_config)
        app.initialize(_config)

        _data = {}
        if data:
            _data.update(data)

        _http = {'wsgi.input': StringIO.StringIO(inputstream),
                 'REQUEST_METHOD': len(inputstream) and 'GET' or 'POST',
                 'CONTENT_LENGTH': len(inputstream)}
        if http:
            _http.update(http)

        return app.Request(_config, _http, _data)