當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。