开发者

Django Test Client: Test that context is a RequestContext object

开发者 https://www.devze.com 2023-02-24 17:29 出处:网络
is there a way to test that the response.context object the test client returns, a RequestContext object i开发者_JS百科s? I checked the source code and it seems they wrap the context in a ContextList

is there a way to test that the response.context object the test client returns, a RequestContext object i开发者_JS百科s? I checked the source code and it seems they wrap the context in a ContextList object.


Check if the ContextList is not empty, then check the item which is a RequestContext object:

from django.template import RequestContext

response = client.post(...)
context_list = response.context

for context in context_list:
    if isinstance(context, RequestContext):
        # do some more test checks here
0

精彩评论

暂无评论...
验证码 换一张
取 消