general: update context usage for Django 1.11 (#20935)
This commit is contained in:
parent
75968b27b6
commit
0558d9b091
|
@ -21,7 +21,6 @@ import shutil
|
|||
import zipfile
|
||||
|
||||
from django.core.files.storage import default_storage
|
||||
from django.template import RequestContext
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
import ckeditor
|
||||
|
@ -60,13 +59,13 @@ def get_page_dict(request, page, manifest):
|
|||
cells = [x for x in cells if not (isinstance(x, LinkCell) or isinstance(x, FeedCell))]
|
||||
|
||||
if cells:
|
||||
context = RequestContext(request, {
|
||||
context = {
|
||||
'synchronous': True,
|
||||
'page': page,
|
||||
'page_cells': cells,
|
||||
'request': request,
|
||||
'site_base': request.build_absolute_uri('/')[:-1],
|
||||
})
|
||||
}
|
||||
page_dict['content'] = '\n'.join([render_cell(cell, context) for cell in cells])
|
||||
|
||||
if link_cells:
|
||||
|
@ -161,13 +160,13 @@ def generate_manifest(request):
|
|||
# footer
|
||||
footer_cells = CellBase.get_cells(page_id=homepage.id, placeholder='footer')
|
||||
if footer_cells:
|
||||
context = RequestContext(request, {
|
||||
context = {
|
||||
'synchronous': True,
|
||||
'page': homepage,
|
||||
'page_cells': footer_cells,
|
||||
'request': request,
|
||||
'site_base': request.build_absolute_uri('/')[:-1],
|
||||
})
|
||||
}
|
||||
manifest['footer'] = '\n'.join([
|
||||
'<div id="footer-%s">%s</div>' % (cell.slug, cell.render(context)) for cell in footer_cells])
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ from django.core.exceptions import PermissionDenied
|
|||
from django.core.urlresolvers import reverse
|
||||
from django.forms import models as model_forms, Select
|
||||
from django.utils.http import quote
|
||||
from django.template import RequestContext
|
||||
|
||||
from combo.utils import requests
|
||||
from combo.data.models import CellBase
|
||||
|
@ -115,6 +114,5 @@ class SearchCell(CellBase):
|
|||
if cell.slug:
|
||||
template_names.insert(0, 'combo/cells/%s/search-cell-results.html' % cell.slug)
|
||||
tmpl = template.loader.select_template(template_names)
|
||||
context = RequestContext(request)
|
||||
context.push({'request': request, 'cell': cell, 'results': results})
|
||||
return HttpResponse(tmpl.render(context), content_type='text/html')
|
||||
context= {'cell': cell, 'results': results}
|
||||
return HttpResponse(tmpl.render(context, request), content_type='text/html')
|
||||
|
|
|
@ -409,4 +409,4 @@ class TrackingCodeInputCell(CellBase):
|
|||
if not self.wcs_site:
|
||||
self.wcs_site = get_wcs_services().keys()[0]
|
||||
context['url'] = get_wcs_services().get(self.wcs_site).get('url')
|
||||
return tmpl.render(context)
|
||||
return tmpl.render(context, context.get('request'))
|
||||
|
|
|
@ -41,7 +41,7 @@ from django.utils.safestring import mark_safe
|
|||
from django.utils.text import slugify
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.forms.widgets import MediaDefiningClass
|
||||
from django.template import Context, RequestContext, Template
|
||||
from django.template import Context, engines
|
||||
from django.test.client import RequestFactory
|
||||
|
||||
from .fields import RichTextField
|
||||
|
@ -206,15 +206,15 @@ class Page(models.Model):
|
|||
tmpl = template.loader.select_template([template_name])
|
||||
request = RequestFactory(SERVER_NAME=request.get_host()).get(self.get_online_url())
|
||||
request.user = None
|
||||
context = RequestContext(request, {
|
||||
context = {
|
||||
'page': self,
|
||||
'request': request,
|
||||
'synchronous': True,
|
||||
'placeholder_search_mode': True,
|
||||
'placeholders': placeholders,
|
||||
'traverse_cells': traverse_cells,
|
||||
})
|
||||
tmpl.render(context)
|
||||
}
|
||||
tmpl.render(context, request)
|
||||
return placeholders
|
||||
|
||||
def get_next_page(self, user=None):
|
||||
|
@ -512,7 +512,7 @@ class CellBase(models.Model):
|
|||
template_names.append('combo/cells/%s/%s' % (self.slug, base_template_name))
|
||||
template_names.reverse()
|
||||
tmpl = template.loader.select_template(template_names)
|
||||
return tmpl.render(context)
|
||||
return tmpl.render(context, context.get('request'))
|
||||
|
||||
def modify_global_context(self, context, request=None):
|
||||
'''Apply changes to the template context that must visible to all cells in the page'''
|
||||
|
@ -527,9 +527,11 @@ class CellBase(models.Model):
|
|||
return ''
|
||||
if not self.is_visible(user=None):
|
||||
return ''
|
||||
context = RequestContext(RequestFactory().get(self.page.get_online_url()), {'synchronous': True})
|
||||
context['request'] = context.request # for compatibility
|
||||
context['user'] = None # compat
|
||||
context = {
|
||||
'synchronous': True,
|
||||
'request': RequestFactory().get(self.page.get_online_url()),
|
||||
'user': None, # compat
|
||||
}
|
||||
if not self.is_relevant(context):
|
||||
return ''
|
||||
from HTMLParser import HTMLParser
|
||||
|
@ -1004,10 +1006,9 @@ class JsonCellBase(CellBase):
|
|||
continue
|
||||
content[key] = value
|
||||
|
||||
context_dict = copy.copy(content)
|
||||
context_dict['request'] = request
|
||||
context_dict['synchronous'] = True
|
||||
context = RequestContext(request, context_dict)
|
||||
context = copy.copy(content)
|
||||
context['request'] = request
|
||||
context['synchronous'] = True
|
||||
|
||||
try:
|
||||
url = utils.get_templated_url(self.actions[action]['url'], context)
|
||||
|
@ -1032,9 +1033,9 @@ class JsonCellBase(CellBase):
|
|||
if self.force_async and not context.get('synchronous'):
|
||||
raise NothingInCacheException()
|
||||
if self.template_string:
|
||||
tmpl = Template(self.template_string)
|
||||
tmpl = engines['django'].from_string(self.template_string)
|
||||
context.update(self.get_cell_extra_context(context))
|
||||
return tmpl.render(context)
|
||||
return tmpl.render(context, context.get('request'))
|
||||
return super(JsonCellBase, self).render(context)
|
||||
|
||||
|
||||
|
|
|
@ -31,5 +31,6 @@ def cell_form(context, cell):
|
|||
context['cell'] = cell
|
||||
cell_form_template = template.loader.get_template(cell.manager_form_template)
|
||||
with context.push():
|
||||
context = context.flatten()
|
||||
context.update(cell.get_extra_manager_context())
|
||||
return cell_form_template.render(context)
|
||||
|
|
|
@ -20,14 +20,13 @@ import datetime
|
|||
|
||||
from django import template
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.template import RequestContext
|
||||
from django.template.base import TOKEN_BLOCK, TOKEN_VAR
|
||||
from django.template.defaultfilters import stringfilter
|
||||
from django.utils import dateparse
|
||||
|
||||
from combo.data.models import Placeholder
|
||||
from combo.public.menu import get_menu_context
|
||||
from combo.utils import NothingInCacheException
|
||||
from combo.utils import NothingInCacheException, flatten_context
|
||||
from combo.apps.dashboard.models import DashboardCell, Tile
|
||||
|
||||
register = template.Library()
|
||||
|
@ -60,7 +59,7 @@ def placeholder(context, placeholder_name, **options):
|
|||
context['cells'] = [x for x in page_cells if
|
||||
x.placeholder == placeholder_name and
|
||||
(context.get('render_skeleton') or x.is_relevant(context) and
|
||||
x.is_visible(context.request.user))]
|
||||
x.is_visible(context['request'].user))]
|
||||
if context.get('render_skeleton') and not context['cells']:
|
||||
context['skeleton'] = skeleton_text(context, placeholder_name)
|
||||
else:
|
||||
|
@ -84,18 +83,18 @@ def render_cell(context, cell):
|
|||
raise PermissionDenied()
|
||||
in_dashboard = True
|
||||
|
||||
with context.push():
|
||||
context['in_dashboard'] = in_dashboard
|
||||
if 'placeholder' in context and context['placeholder'].force_synchronous:
|
||||
context['synchronous'] = True
|
||||
try:
|
||||
return cell.render(context)
|
||||
except NothingInCacheException:
|
||||
return template.loader.get_template('combo/deferred-cell.html').render(context)
|
||||
except:
|
||||
if context.get('placeholder_search_mode'):
|
||||
return ''
|
||||
raise
|
||||
context = flatten_context(context)
|
||||
context['in_dashboard'] = in_dashboard
|
||||
if 'placeholder' in context and context['placeholder'].force_synchronous:
|
||||
context['synchronous'] = True
|
||||
try:
|
||||
return cell.render(context)
|
||||
except NothingInCacheException:
|
||||
return template.loader.get_template('combo/deferred-cell.html').render(context)
|
||||
except:
|
||||
if context.get('placeholder_search_mode'):
|
||||
return ''
|
||||
raise
|
||||
|
||||
@register.tag
|
||||
def skeleton_extra_placeholder(parser, token):
|
||||
|
@ -143,10 +142,10 @@ class ExtraPlaceholderNode(template.Node):
|
|||
def show_menu(context, level=0, current_page=None, depth=1, reduce_depth=False):
|
||||
if reduce_depth:
|
||||
depth -= 1
|
||||
new_context = RequestContext(context['request'], {
|
||||
new_context = {
|
||||
'page': context['page'],
|
||||
'render_skeleton': context.get('render_skeleton'),
|
||||
'request': context['request']})
|
||||
'request': context['request']}
|
||||
return get_menu_context(new_context, level=level, current_page=current_page,
|
||||
depth=depth)
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ from django.db import transaction
|
|||
from django.http import (Http404, HttpResponse, HttpResponseRedirect,
|
||||
HttpResponsePermanentRedirect)
|
||||
from django.shortcuts import render, resolve_url
|
||||
from django.template import RequestContext, Template
|
||||
from django.template import engines
|
||||
from django.utils import lorem_ipsum, timezone
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
|
@ -102,13 +102,13 @@ def ajax_page_cell(request, page_pk, cell_reference):
|
|||
return response
|
||||
|
||||
def render_cell(request, cell):
|
||||
context = RequestContext(request, {
|
||||
context = {
|
||||
'page': cell.page if cell.page_id else None,
|
||||
'request': request,
|
||||
'cell': cell,
|
||||
'synchronous': True,
|
||||
'site_base': request.build_absolute_uri('/')[:-1],
|
||||
})
|
||||
}
|
||||
|
||||
if cell.page_id:
|
||||
other_cells = CellBase.get_cells(page_id=cell.page_id)
|
||||
|
@ -120,8 +120,8 @@ def render_cell(request, cell):
|
|||
# Cell can pass data through its own __dict__
|
||||
cell.modify_global_context(context, request)
|
||||
|
||||
template = Template('{% load combo %}{% render_cell cell %}')
|
||||
return HttpResponse(template.render(context), content_type='text/html')
|
||||
template = engines['django'].from_string('{% load combo %}{% render_cell cell %}')
|
||||
return HttpResponse(template.render(context, request), content_type='text/html')
|
||||
|
||||
|
||||
def extend_with_parent_cells(cells):
|
||||
|
@ -382,7 +382,7 @@ def error404(request, *args, **kwargs):
|
|||
|
||||
|
||||
def menu_badges(request):
|
||||
context = RequestContext(request, {'request': request})
|
||||
context = {'request': request}
|
||||
page_ids = request.GET.getlist('page[]')
|
||||
cells = CellBase.get_cells(
|
||||
cell_filter=lambda x: bool(x.get_badge),
|
||||
|
|
|
@ -36,6 +36,7 @@ from requests import Response, Session as RequestsSession
|
|||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.template import Context, Template, TemplateSyntaxError, VariableDoesNotExist
|
||||
from django.template.context import BaseContext
|
||||
from django.utils.html import strip_tags
|
||||
from django.utils.http import urlencode, quote
|
||||
|
||||
|
@ -340,3 +341,15 @@ def cache_during_request(func):
|
|||
request.cache[cache_key] = result
|
||||
return result
|
||||
return inner
|
||||
|
||||
|
||||
def flatten_context(context):
|
||||
# flatten a context to a dictionary, with full support for embedded Context
|
||||
# objects.
|
||||
flat_context = {}
|
||||
if isinstance(context, BaseContext):
|
||||
for ctx in context.dicts:
|
||||
flat_context.update(flatten_context(ctx))
|
||||
else:
|
||||
flat_context.update(context)
|
||||
return flat_context
|
||||
|
|
|
@ -81,8 +81,7 @@ def test_link_cell():
|
|||
|
||||
assert cell.get_additional_label() == 'Example Site'
|
||||
|
||||
from django.template import Context
|
||||
ctx = Context()
|
||||
ctx = {}
|
||||
assert cell.render(ctx).strip() == '<a href="http://example.net/">Example Site</a>'
|
||||
|
||||
cell.title = ''
|
||||
|
@ -116,8 +115,7 @@ def test_variant_templates():
|
|||
cell.order = 0
|
||||
cell.save()
|
||||
|
||||
from django.template import Context
|
||||
ctx = Context()
|
||||
ctx = {}
|
||||
assert cell.render(ctx).strip() == '<p>foobar</p>'
|
||||
|
||||
templates_settings = [settings.TEMPLATES[0].copy()]
|
||||
|
@ -217,18 +215,18 @@ def test_json_cell():
|
|||
data = {'data': [{'url': 'http://a.b', 'text': 'xxx'}]}
|
||||
requests_get.return_value = mock.Mock(content=json.dumps(data), status_code=200)
|
||||
cell.url = 'http://test4'
|
||||
result = cell.render(Context({'synchronous': True}))
|
||||
result = cell.render({'synchronous': True})
|
||||
assert 'http://a.b' in result
|
||||
assert requests_get.call_count == 1
|
||||
|
||||
cell.template_string = '{{json.data.0.text}}'
|
||||
result = cell.render(Context({'synchronous': True}))
|
||||
result = cell.render({'synchronous': True})
|
||||
assert result == 'xxx'
|
||||
|
||||
with mock.patch('combo.utils.requests.get') as requests_get:
|
||||
requests_get.return_value = mock.Mock(content='garbage', status_code=200)
|
||||
cell.url = 'http://test5'
|
||||
result = cell.render(Context({'synchronous': True}))
|
||||
result = cell.render({'synchronous': True})
|
||||
assert result == ''
|
||||
|
||||
context = cell.get_cell_extra_context({})
|
||||
|
@ -243,7 +241,7 @@ def test_json_cell():
|
|||
cell.url = 'http://testuser?[foobar]'
|
||||
with mock.patch('combo.utils.requests.get') as requests_get:
|
||||
requests_get.return_value = mock.Mock(content=json.dumps(data), status_code=200)
|
||||
context = cell.get_cell_extra_context(Context({'foobar': 'barfoo'}))
|
||||
context = cell.get_cell_extra_context({'foobar': 'barfoo'})
|
||||
assert context['json'] == data
|
||||
assert context['json_url'] == 'http://testuser?barfoo'
|
||||
assert context['json_status'] == 200
|
||||
|
@ -251,7 +249,7 @@ def test_json_cell():
|
|||
assert requests_get.call_args[1]['cache_duration'] == 10
|
||||
assert requests_get.call_count == 1
|
||||
with mock.patch('combo.utils.requests.get') as requests_get:
|
||||
context = cell.get_cell_extra_context(Context({}))
|
||||
context = cell.get_cell_extra_context({})
|
||||
# can't get URL, 'foobar' variable is missing
|
||||
assert context['json'] == None
|
||||
assert requests_get.call_count == 0
|
||||
|
@ -260,7 +258,7 @@ def test_json_cell():
|
|||
cell.url = 'http://testuser?email=[user_email]'
|
||||
with mock.patch('combo.utils.requests.get') as requests_get:
|
||||
requests_get.return_value = mock.Mock(content=json.dumps(data), status_code=200)
|
||||
context = cell.get_cell_extra_context(Context({'request': request}))
|
||||
context = cell.get_cell_extra_context({'request': request})
|
||||
assert context['json'] == data
|
||||
assert context['json_url'] == 'http://testuser?email=foo%40example.net'
|
||||
assert requests_get.call_count == 1
|
||||
|
@ -309,7 +307,7 @@ def test_config_json_cell():
|
|||
|
||||
with mock.patch('combo.utils.requests.get') as requests_get:
|
||||
requests_get.return_value = mock.Mock(content=json.dumps({'hello': 'world'}), status_code=200)
|
||||
context = cell.get_cell_extra_context(Context({'request': request}))
|
||||
context = cell.get_cell_extra_context({'request': request})
|
||||
assert context['json'] == {'hello': 'world'}
|
||||
assert context['json_url'] == 'http://test/'
|
||||
assert context['json_status'] == 200
|
||||
|
@ -420,14 +418,14 @@ def test_json_force_async():
|
|||
with mock.patch('combo.utils.RequestsSession.request') as requests_get:
|
||||
requests_get.return_value = mock.Mock(content=json.dumps({'hello': 'world'}), status_code=200)
|
||||
with pytest.raises(NothingInCacheException):
|
||||
cell.render(Context({}))
|
||||
assert cell.render(Context({'synchronous': True})) == 'world'
|
||||
cell.render({})
|
||||
assert cell.render({'synchronous': True}) == 'world'
|
||||
# check force async is effective
|
||||
with pytest.raises(NothingInCacheException):
|
||||
cell.render(Context({}))
|
||||
cell.render({})
|
||||
# disable force_async
|
||||
cell.force_async = False
|
||||
assert cell.render(Context({})) == 'world'
|
||||
assert cell.render({}) == 'world'
|
||||
|
||||
cell = JsonCellBase()
|
||||
cell.url = 'http://example.net/test-force-async-2'
|
||||
|
@ -437,11 +435,11 @@ def test_json_force_async():
|
|||
requests_get.return_value = mock.Mock(content=json.dumps({'hello': 'world2'}), status_code=200)
|
||||
# raise if nothing in cache
|
||||
with pytest.raises(NothingInCacheException):
|
||||
cell.render(Context({}))
|
||||
cell.render({})
|
||||
# force stuff in cache
|
||||
assert cell.render(Context({'synchronous': True})) == 'world2'
|
||||
assert cell.render({'synchronous': True}) == 'world2'
|
||||
# rerun with stuff in cache
|
||||
assert cell.render(Context({})) == 'world2'
|
||||
assert cell.render({}) == 'world2'
|
||||
|
||||
def test_config_json_cell_additional_url(app):
|
||||
page = Page(title='example page', slug='index')
|
||||
|
|
|
@ -5,7 +5,6 @@ import pytest
|
|||
|
||||
from django.contrib.auth.models import User
|
||||
from django.test.client import RequestFactory
|
||||
from django.template import Context
|
||||
from django.utils import timezone
|
||||
|
||||
from combo.data.models import Page
|
||||
|
@ -49,7 +48,7 @@ def test_basket_cell(regie, user):
|
|||
page.save()
|
||||
cell = LingoBasketCell(page=page, placeholder='content', order=0)
|
||||
|
||||
context = Context({'request': RequestFactory().get('/')})
|
||||
context = {'request': RequestFactory().get('/')}
|
||||
context['request'].user = None
|
||||
assert cell.is_relevant(context) is False
|
||||
assert cell.get_badge(context) is None
|
||||
|
@ -90,7 +89,7 @@ def test_recent_transaction_cell(regie, user):
|
|||
page.save()
|
||||
cell = LingoRecentTransactionsCell(page=page, placeholder='content', order=0)
|
||||
|
||||
context = Context({'request': RequestFactory().get('/')})
|
||||
context = {'request': RequestFactory().get('/')}
|
||||
context['request'].user = None
|
||||
assert cell.is_relevant(context) is False
|
||||
|
||||
|
@ -127,7 +126,7 @@ def test_basket_link_cell(regie, user):
|
|||
page.save()
|
||||
cell = LingoBasketLinkCell(page=page, placeholder='content', order=0)
|
||||
|
||||
context = Context({'request': RequestFactory().get('/')})
|
||||
context = {'request': RequestFactory().get('/')}
|
||||
context['request'].user = None
|
||||
assert cell.is_relevant(context) is False
|
||||
context['request'].user = user
|
||||
|
@ -165,7 +164,7 @@ def test_tipi_cell():
|
|||
assert cell.control_protocol == 'pesv2'
|
||||
assert cell.url == 'https://www.tipi.budget.gouv.fr/tpa/paiement.web'
|
||||
assert cell.template_name == 'lingo/tipi_form.html'
|
||||
html = cell.render(Context({}))
|
||||
html = cell.render({})
|
||||
assert "<h2>TIPI Payment</h2>" in html
|
||||
assert "Community identifier" in html
|
||||
assert 'id="exer"' in html
|
||||
|
@ -179,7 +178,7 @@ def test_tipi_cell():
|
|||
cell.control_protocol = 'rolmre'
|
||||
cell.test_mode = True
|
||||
cell.save()
|
||||
html = cell.render(Context({}))
|
||||
html = cell.render({})
|
||||
assert 'id="rolrec"' in html
|
||||
assert 'id="roldeb"' in html
|
||||
assert 'id="roldet"' in html
|
||||
|
|
|
@ -6,7 +6,6 @@ from decimal import Decimal
|
|||
from requests.exceptions import ConnectionError
|
||||
|
||||
from django.test.client import RequestFactory
|
||||
from django.template import Context
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.conf import settings
|
||||
from django.core.management import call_command
|
||||
|
@ -76,7 +75,7 @@ def test_remote_regie_active_invoices_cell(mock_request, remote_regie):
|
|||
page = Page(title='xxx', slug='test_basket_cell', template_name='standard')
|
||||
page.save()
|
||||
cell = ActiveItems(regie='remote', page=page, placeholder='content', order=0)
|
||||
context = Context({'request': RequestFactory().get('/')})
|
||||
context = {'request': RequestFactory().get('/')}
|
||||
context['synchronous'] = True # to get fresh content
|
||||
|
||||
user = MockUser()
|
||||
|
@ -121,7 +120,7 @@ def test_remote_regie_past_invoices_cell(mock_request, remote_regie):
|
|||
page = Page(title='xxx', slug='test_basket_cell', template_name='standard')
|
||||
page.save()
|
||||
cell = ItemsHistory(regie='remote', page=page, placeholder='content', order=0)
|
||||
context = Context({'request': RequestFactory().get('/')})
|
||||
context = {'request': RequestFactory().get('/')}
|
||||
context['synchronous'] = True # to get fresh content
|
||||
|
||||
user = MockUser()
|
||||
|
|
|
@ -5,7 +5,6 @@ import pytest
|
|||
|
||||
from django.contrib.auth.models import User
|
||||
from django.test.client import RequestFactory
|
||||
from django.template import Context
|
||||
from django.test import Client
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.contrib.auth.models import Group
|
||||
|
@ -87,7 +86,7 @@ def test_cell_rendering(layer):
|
|||
cell = Map(page=page, placeholder='content', order=0, title='Map with points')
|
||||
cell.save()
|
||||
cell.layers.add(layer)
|
||||
context = Context({'request': RequestFactory().get('/')})
|
||||
context = {'request': RequestFactory().get('/')}
|
||||
rendered = cell.render(context)
|
||||
assert 'data-init-zoom="13"' in rendered
|
||||
assert 'data-min-zoom="0"' in rendered
|
||||
|
|
|
@ -4,7 +4,6 @@ import pytest
|
|||
|
||||
from django.contrib.auth.models import User
|
||||
from django.test.client import RequestFactory
|
||||
from django.template import Context
|
||||
from django.utils.timezone import timedelta, now
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
|
@ -81,7 +80,7 @@ def test_notification_cell(user, user2):
|
|||
page.save()
|
||||
cell = NotificationsCell(page=page, placeholder='content', order=0)
|
||||
|
||||
context = Context({'request': RequestFactory().get('/')})
|
||||
context = {'request': RequestFactory().get('/')}
|
||||
context['synchronous'] = True # to get fresh content
|
||||
|
||||
context['request'].user = None
|
||||
|
|
|
@ -6,7 +6,6 @@ import mock
|
|||
from django.conf import settings
|
||||
from django.test import Client, override_settings
|
||||
from django.test.client import RequestFactory
|
||||
from django.template import Context
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
from haystack.exceptions import SkipDocument
|
||||
|
@ -53,13 +52,12 @@ def test_search_cell(app):
|
|||
cell._search_service = 'search1'
|
||||
cell.save()
|
||||
|
||||
context = Context({})
|
||||
resp = cell.render(context)
|
||||
resp = cell.render({})
|
||||
assert 'input' in resp
|
||||
assert 'id="combo-search-input-%s"' % cell.pk in resp
|
||||
|
||||
cell.slug = 'var-name'
|
||||
context = Context({'request': RequestFactory().get('/?q_var_name=searchme')})
|
||||
context = {'request': RequestFactory().get('/?q_var_name=searchme')}
|
||||
resp = cell.render(context)
|
||||
assert "combo_search_input_%s.val('searchme');" % cell.pk in resp
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ import os
|
|||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.test.client import RequestFactory
|
||||
from django.template import Context
|
||||
|
||||
from combo.data.models import Page
|
||||
from combo.apps.wcs.models import (WcsFormCell, WcsCurrentFormsCell,
|
||||
|
@ -210,7 +209,7 @@ def check_wcs_open(url):
|
|||
|
||||
@pytest.fixture
|
||||
def context():
|
||||
ctx = Context({'request': RequestFactory().get('/')})
|
||||
ctx = {'request': RequestFactory().get('/')}
|
||||
ctx['request'].user = None
|
||||
ctx['request'].session = {}
|
||||
return ctx
|
||||
|
@ -262,7 +261,7 @@ def test_form_cell_render():
|
|||
cell = WcsFormCell(page=page, placeholder='content', order=0)
|
||||
cell.formdef_reference = u'default:form-title'
|
||||
cell.save()
|
||||
result = cell.render(Context())
|
||||
result = cell.render({})
|
||||
assert 'http://127.0.0.1:8999/form-title/tryauth' in result
|
||||
assert 'form title' in result
|
||||
|
||||
|
|
Loading…
Reference in New Issue