tests: adapt tests to new TEMPLATES settings (#19578)
This commit is contained in:
parent
2a93c51780
commit
3fce425269
|
@ -5,6 +5,7 @@ import pytest
|
|||
import requests
|
||||
|
||||
from combo.data.models import Page, CellBase, TextCell, LinkCell, JsonCellBase, JsonCell, ConfigJsonCell
|
||||
from django.conf import settings
|
||||
from django.forms.widgets import Media
|
||||
from django.template import Context
|
||||
from django.test import override_settings
|
||||
|
@ -117,7 +118,9 @@ def test_variant_templates():
|
|||
ctx = Context()
|
||||
assert cell.render(ctx).strip() == '<p>foobar</p>'
|
||||
|
||||
with override_settings(TEMPLATE_DIRS=['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]):
|
||||
templates_settings = [settings.TEMPLATES[0].copy()]
|
||||
templates_settings[0]['DIRS'] = ['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]
|
||||
with override_settings(TEMPLATES=templates_settings):
|
||||
assert cell.render(ctx).strip() == '<p>foobar</p>'
|
||||
cell.slug = 'foobar'
|
||||
cell.save()
|
||||
|
@ -325,13 +328,15 @@ def test_config_json_cell_with_varnames(app):
|
|||
page = Page(title='example page', slug='index')
|
||||
page.save()
|
||||
|
||||
templates_settings = [settings.TEMPLATES[0].copy()]
|
||||
templates_settings[0]['DIRS'] = ['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]
|
||||
with override_settings(JSON_CELL_TYPES={
|
||||
'test-config-json-cell': {
|
||||
'name': 'Foobar',
|
||||
'url': 'http://foo?varone=[var1]&vartwo=[var2]',
|
||||
'varnames': ['var1', 'var2']
|
||||
}},
|
||||
TEMPLATE_DIRS=['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]):
|
||||
TEMPLATES=templates_settings):
|
||||
cell = ConfigJsonCell()
|
||||
cell.key = 'test-config-json-cell'
|
||||
cell.page = page
|
||||
|
@ -369,6 +374,8 @@ def test_config_json_cell_with_param_in_url(app):
|
|||
page = Page(title='example page', slug='index')
|
||||
page.save()
|
||||
|
||||
templates_settings = [settings.TEMPLATES[0].copy()]
|
||||
templates_settings[0]['DIRS'] = ['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]
|
||||
with override_settings(JSON_CELL_TYPES={
|
||||
'test-config-json-cell': {
|
||||
'name': 'Foobar',
|
||||
|
@ -383,7 +390,7 @@ def test_config_json_cell_with_param_in_url(app):
|
|||
}
|
||||
]
|
||||
}},
|
||||
TEMPLATE_DIRS=['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]):
|
||||
TEMPLATES=templates_settings):
|
||||
cell = ConfigJsonCell()
|
||||
cell.key = 'test-config-json-cell'
|
||||
cell.parameters = {'identifier': 'plop'}
|
||||
|
@ -438,6 +445,8 @@ def test_config_json_cell_additional_url(app):
|
|||
page = Page(title='example page', slug='index')
|
||||
page.save()
|
||||
|
||||
templates_settings = [settings.TEMPLATES[0].copy()]
|
||||
templates_settings[0]['DIRS'] = ['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]
|
||||
with override_settings(JSON_CELL_TYPES={
|
||||
'test-config-json-cell-2': {
|
||||
'name': 'Foobar',
|
||||
|
@ -446,7 +455,7 @@ def test_config_json_cell_additional_url(app):
|
|||
{'key': 'plop', 'url': 'http://bar', 'log_errors': False, 'timeout': 42},
|
||||
]
|
||||
}},
|
||||
TEMPLATE_DIRS=['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]):
|
||||
TEMPLATES=templates_settings):
|
||||
cell = ConfigJsonCell()
|
||||
cell.key = 'test-config-json-cell-2'
|
||||
cell.page = page
|
||||
|
@ -514,7 +523,7 @@ def test_config_json_cell_additional_url(app):
|
|||
'timeout': 10},
|
||||
]
|
||||
}},
|
||||
TEMPLATE_DIRS=['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]):
|
||||
TEMPLATES=templates_settings):
|
||||
cell = ConfigJsonCell()
|
||||
cell.key = 'test-config-json-cell-2'
|
||||
cell.page = page
|
||||
|
|
|
@ -5,6 +5,7 @@ import pytest
|
|||
import urlparse
|
||||
from webtest import TestApp
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test import override_settings
|
||||
|
@ -177,6 +178,8 @@ def test_reorder_dashboard(app, site):
|
|||
assert new_order == ','.join([str(x.id) for x in tiles])
|
||||
|
||||
def test_auto_tile(app, site):
|
||||
templates_settings = [settings.TEMPLATES[0].copy()]
|
||||
templates_settings[0]['DIRS'] = ['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]
|
||||
with override_settings(JSON_CELL_TYPES={
|
||||
'test-config-json-cell': {
|
||||
'name': 'Foobar',
|
||||
|
@ -187,7 +190,7 @@ def test_auto_tile(app, site):
|
|||
}
|
||||
]
|
||||
}},
|
||||
TEMPLATE_DIRS=['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]):
|
||||
TEMPLATES=templates_settings):
|
||||
with mock.patch('combo.utils.requests.get') as requests_get:
|
||||
# logged out
|
||||
requests_get.return_value = mock.Mock(content='<div>HELLO</div>', status_code=200)
|
||||
|
|
|
@ -490,8 +490,10 @@ def test_edit_config_json_cell(app, admin_user):
|
|||
options = [x.text for x in resp.html.find_all('option')]
|
||||
assert not 'Foobar' in options
|
||||
|
||||
templates_settings = [settings.TEMPLATES[0].copy()]
|
||||
templates_settings[0]['DIRS'] = ['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]
|
||||
with override_settings(JSON_CELL_TYPES={'test-config-json-cell': {'name': 'Foobar', 'url': 'http://test/'}},
|
||||
TEMPLATE_DIRS=['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]):
|
||||
TEMPLATES=templates_settings):
|
||||
resp = app.get('/manage/pages/%s/' % page.id)
|
||||
options = [x.text for x in resp.html.find_all('option')]
|
||||
assert 'Foobar' in options
|
||||
|
@ -530,7 +532,7 @@ def test_edit_config_json_cell(app, admin_user):
|
|||
'varname': 'test3',
|
||||
},
|
||||
]}},
|
||||
TEMPLATE_DIRS=['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]):
|
||||
TEMPLATES=templates_settings):
|
||||
resp = app.get('/manage/pages/%s/' % page.id)
|
||||
assert not 'There are no options for this cell.' in resp.form.text
|
||||
|
||||
|
|
|
@ -212,10 +212,11 @@ def test_style_demo(app, admin_user):
|
|||
TextCell.objects.all().delete()
|
||||
Page.objects.all().delete()
|
||||
app = login(app)
|
||||
resp = app.get('/__style__/', status=200)
|
||||
assert 'Lorem ipsum' in resp.body
|
||||
assert TextCell.objects.count() == 0
|
||||
assert Page.objects.count() == 0
|
||||
with override_settings(DEBUG=True):
|
||||
resp = app.get('/__style__/', status=200)
|
||||
assert 'Lorem ipsum' in resp.body
|
||||
assert TextCell.objects.count() == 0
|
||||
assert Page.objects.count() == 0
|
||||
|
||||
def test_page_async_cell(app):
|
||||
Page.objects.all().delete()
|
||||
|
@ -320,6 +321,8 @@ def test_post_cell(app):
|
|||
params={'hello': 'world'},
|
||||
status=403)
|
||||
|
||||
templates_settings = [settings.TEMPLATES[0].copy()]
|
||||
templates_settings[0]['DIRS'] = ['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]
|
||||
with override_settings(JSON_CELL_TYPES={
|
||||
'test-post-cell': {
|
||||
'name': 'Foobar',
|
||||
|
@ -330,7 +333,7 @@ def test_post_cell(app):
|
|||
}
|
||||
}
|
||||
}},
|
||||
TEMPLATE_DIRS=['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]
|
||||
TEMPLATES=templates_settings
|
||||
):
|
||||
cell = ConfigJsonCell(page=page, placeholder='content', order=0)
|
||||
cell.key = 'test-post-cell'
|
||||
|
|
|
@ -103,7 +103,9 @@ def test_search_cell(app):
|
|||
# TEMPLATE_VARS are accessible in template
|
||||
cell.slug = 'searchfoo'
|
||||
cell.save()
|
||||
with override_settings(TEMPLATE_DIRS=['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]):
|
||||
templates_settings = [settings.TEMPLATES[0].copy()]
|
||||
templates_settings[0]['DIRS'] = ['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]
|
||||
with override_settings(TEMPLATES=templates_settings):
|
||||
resp = client.get('/ajax/search/%s/?q=bar' % cell.pk, status=200)
|
||||
assert requests_get.call_args[0][0] == 'http://search.example.net/?q=bar'
|
||||
assert 'searchfoo results.data=[]' in resp.content
|
||||
|
|
Loading…
Reference in New Issue