Пример #1
0
    def get_context(context_dict=None, current_app='', request_path=None, user_data=None):

        user = user_data if hasattr(user_data, '_meta') else MockUser(user_data)

        context_dict = context_dict or {}
        context_updater = {
            'request': MockRequest(request_path, user),
        }
        if user_data:
            context_updater['user'] = user

        context_dict.update(context_updater)

        context = Context(context_dict)
        context.template = mock.MagicMock()
        context.template.engine.string_if_invalid = ''

        if VERSION >= (1, 10):
            match = mock.MagicMock()
            match.app_name = current_app
            context.resolver_match = match

        else:
            context._current_app = current_app

        return context
Пример #2
0
    def get_context(context_dict=None, current_app='', request_path=None, user_data=None):

        user = user_data if hasattr(user_data, '_meta') else MockUser(user_data)

        context_dict = context_dict or {}
        context_updater = {
            'request': MockRequest(request_path, user),
        }
        if user_data:
            context_updater['user'] = user

        context_dict.update(context_updater)

        context = Context(context_dict)
        context.template = mock.MagicMock()
        context.template.engine.string_if_invalid = ''

        if VERSION >= (1, 10):
            match = mock.MagicMock()
            match.app_name = current_app
            context.resolver_match = match

        else:
            context._current_app = current_app

        return context
Пример #3
0
def get_mock_context(app='', path=None, user_authorized=False, tree_item=None, put_var=None):

    ctx = Context(
        {
            'request': MockRequest(path, user_authorized),
            't2_root2_title': 'my_real_title', 'art_id': 10, 'tree_item': tree_item,
            'somevar_str': 'articles_list', 'somevar_list': ['a', 'b'], 'put_var': put_var
        }
    )
    ctx.template = mock.MagicMock()
    ctx.template.engine.string_if_invalid = ''

    if VERSION >= (1, 10):
        match = mock.MagicMock()
        match.app_name = app
        ctx.resolver_match = match

    else:
        ctx._current_app = app

    return ctx