当前位置: 首页>>代码示例>>Python>>正文


Python utils.ContextList方法代码示例

本文整理汇总了Python中django.test.utils.ContextList方法的典型用法代码示例。如果您正苦于以下问题:Python utils.ContextList方法的具体用法?Python utils.ContextList怎么用?Python utils.ContextList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.test.utils的用法示例。


在下文中一共展示了utils.ContextList方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: store_rendered_templates

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import ContextList [as 别名]
def store_rendered_templates(store, signal, sender, template, context, **kwargs):
    """
    Stores templates and contexts that are rendered.

    The context is copied so that it is an accurate representation at the time
    of rendering.
    """
    store.setdefault('templates', []).append(template)
    store.setdefault('context', ContextList()).append(copy(context)) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:11,代码来源:client.py

示例2: store_rendered_templates

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import ContextList [as 别名]
def store_rendered_templates(store, signal, sender, template, context, **kwargs):
    """
    Store templates and contexts that are rendered.

    The context is copied so that it is an accurate representation at the time
    of rendering.
    """
    store.setdefault('templates', []).append(template)
    if 'context' not in store:
        store['context'] = ContextList()
    store['context'].append(copy(context)) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:13,代码来源:client.py

示例3: clean

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import ContextList [as 别名]
def clean(self, data):
        """Cleans up `data` before using it as a snapshot reference."""
        if isinstance(data, RequestContext):
            return self.clean(data.flatten())
        # XXX: maybe we can do something smarter than blacklisting when we
        # have a `ContextList`?
        elif isinstance(data, dict) or isinstance(data, ContextList):
            return {
                key: self.clean(data[key])
                for key in data.keys()
                if key not in BLACKLISTED_KEYS
            }
        elif isinstance(data, list):
            return [self.clean(item) for item in data]
        return data 
开发者ID:evernote,项目名称:zing,代码行数:17,代码来源:snapshot.py

示例4: store_rendered_templates

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import ContextList [as 别名]
def store_rendered_templates(store, signal, sender, template, context, **kwargs):
    """
    Stores templates and contexts that are rendered.

    The context is copied so that it is an accurate representation at the time
    of rendering.
    """
    store.setdefault('templates', []).append(template)
    if 'context' not in store:
        store['context'] = ContextList()
    store['context'].append(copy(context)) 
开发者ID:Yeah-Kun,项目名称:python,代码行数:13,代码来源:client.py

示例5: __init__

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import ContextList [as 别名]
def __init__(self, test_case, template_name):
        self.test_case = test_case
        self.template_name = template_name
        self.rendered_templates = []
        self.rendered_template_names = []
        self.context = ContextList() 
开发者ID:blackye,项目名称:luscan-devel,代码行数:8,代码来源:testcases.py

示例6: test_inherited_context

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import ContextList [as 别名]
def test_inherited_context(self):
        "Context variables can be retrieved from a list of contexts"
        response = self.client.get("/request_data_extended/", data={'foo': 'whiz'})
        self.assertEqual(response.context.__class__, ContextList)
        self.assertEqual(len(response.context), 2)
        self.assertIn('get-foo', response.context)
        self.assertEqual(response.context['get-foo'], 'whiz')
        self.assertEqual(response.context['data'], 'bacon')

        with self.assertRaises(KeyError) as cm:
            response.context['does-not-exist']
        self.assertEqual(cm.exception.args[0], 'does-not-exist') 
开发者ID:nesdis,项目名称:djongo,代码行数:14,代码来源:tests.py

示例7: test_contextlist_keys

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import ContextList [as 别名]
def test_contextlist_keys(self):
        c1 = Context()
        c1.update({'hello': 'world', 'goodbye': 'john'})
        c1.update({'hello': 'dolly', 'dolly': 'parton'})
        c2 = Context()
        c2.update({'goodbye': 'world', 'python': 'rocks'})
        c2.update({'goodbye': 'dolly'})

        k = ContextList([c1, c2])
        # None, True and False are builtins of BaseContext, and present
        # in every Context without needing to be added.
        self.assertEqual({'None', 'True', 'False', 'hello', 'goodbye', 'python', 'dolly'}, k.keys()) 
开发者ID:nesdis,项目名称:djongo,代码行数:14,代码来源:tests.py

示例8: test_contextlist_get

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import ContextList [as 别名]
def test_contextlist_get(self):
        c1 = Context({'hello': 'world', 'goodbye': 'john'})
        c2 = Context({'goodbye': 'world', 'python': 'rocks'})
        k = ContextList([c1, c2])
        self.assertEqual(k.get('hello'), 'world')
        self.assertEqual(k.get('goodbye'), 'john')
        self.assertEqual(k.get('python'), 'rocks')
        self.assertEqual(k.get('nonexistent', 'default'), 'default') 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:tests.py

示例9: request

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import ContextList [as 别名]
def request(self, **request):
        """
        The master request method. Composes the environment dictionary
        and passes to the handler, returning the result of the handler.
        Assumes defaults for the query environment, which can be overridden
        using the arguments to the request.
        """
        environ = self._base_environ(**request)

        # Curry a data dictionary into an instance of the template renderer
        # callback function.
        data = {}
        on_template_render = curry(store_rendered_templates, data)
        signals.template_rendered.connect(on_template_render, dispatch_uid="template-render")
        # Capture exceptions created by the handler.
        got_request_exception.connect(self.store_exc_info, dispatch_uid="request-exception")
        try:

            try:
                response = self.handler(environ)
            except TemplateDoesNotExist as e:
                # If the view raises an exception, Django will attempt to show
                # the 500.html template. If that template is not available,
                # we should ignore the error in favor of re-raising the
                # underlying exception that caused the 500 error. Any other
                # template found to be missing during view error handling
                # should be reported as-is.
                if e.args != ('500.html',):
                    raise

            # Look for a signalled exception, clear the current context
            # exception data, then re-raise the signalled exception.
            # Also make sure that the signalled exception is cleared from
            # the local cache!
            if self.exc_info:
                exc_info = self.exc_info
                self.exc_info = None
                six.reraise(*exc_info)

            # Save the client and request that stimulated the response.
            response.client = self
            response.request = request

            # Add any rendered template detail to the response.
            response.templates = data.get("templates", [])
            response.context = data.get("context")

            # Flatten a single context. Not really necessary anymore thanks to
            # the __getattr__ flattening in ContextList, but has some edge-case
            # backwards-compatibility implications.
            if response.context and len(response.context) == 1:
                response.context = response.context[0]

            # Update persistent cookie data.
            if response.cookies:
                self.cookies.update(response.cookies)

            return response
        finally:
            signals.template_rendered.disconnect(dispatch_uid="template-render")
            got_request_exception.disconnect(dispatch_uid="request-exception") 
开发者ID:blackye,项目名称:luscan-devel,代码行数:63,代码来源:client.py


注:本文中的django.test.utils.ContextList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。