本文整理汇总了Python中snippets.base.tests.SnippetTemplateFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python SnippetTemplateFactory.create方法的具体用法?Python SnippetTemplateFactory.create怎么用?Python SnippetTemplateFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类snippets.base.tests.SnippetTemplateFactory
的用法示例。
在下文中一共展示了SnippetTemplateFactory.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_basic
# 需要导入模块: from snippets.base.tests import SnippetTemplateFactory [as 别名]
# 或者: from snippets.base.tests.SnippetTemplateFactory import create [as 别名]
def test_basic(self):
variable1 = SnippetTemplateVariableFactory()
variable2 = SnippetTemplateVariableFactory()
template1 = SnippetTemplateFactory.create(
variable_set=[variable1, variable2])
variable3 = SnippetTemplateVariableFactory()
template2 = SnippetTemplateFactory.create(variable_set=[variable3])
choices = (('', 'blank'), (template1.pk, 't1'), (template2.pk, 't2'))
widget = TemplateSelect(choices=choices)
d = pq(widget.render('blah', None))
# Blank option should have no data attributes.
blank_option = d('option:contains("blank")')
eq_(blank_option.attr('data-variables'), None)
# Option 1 should have two variables in the data attribute.
option1 = d('option:contains("t1")')
variables = json.loads(option1.attr('data-variables'))
eq_(len(variables), 2)
ok_({'name': variable1.name, 'type': variable1.type,
'description': variable1.description} in variables)
ok_({'name': variable2.name, 'type': variable2.type,
'description': variable1.description} in variables)
# Option 2 should have just one variable.
option2 = d('option:contains("t2")')
variables = json.loads(option2.attr('data-variables'))
eq_(variables, [{'name': variable3.name, 'type': variable3.type,
'description': variable3.description}])
示例2: test_save_related_remove_old
# 需要导入模块: from snippets.base.tests import SnippetTemplateFactory [as 别名]
# 或者: from snippets.base.tests.SnippetTemplateFactory import create [as 别名]
def test_save_related_remove_old(self):
"""
save_related should delete TemplateVariables that don't exist in the
saved template anymore.
"""
template = SnippetTemplateFactory.create(code="""
<p>Testing {{ sample_var }}</p>
{% if not another_test_var %}
<p>Blah</p>
{% endif %}
""")
SnippetTemplateVariableFactory.create(
name='does_not_exist', template=template)
SnippetTemplateVariableFactory.create(
name='does_not_exist_2', template=template)
self.assertTrue(SnippetTemplateVariable.objects
.filter(template=template, name='does_not_exist').exists())
self.assertTrue(SnippetTemplateVariable.objects
.filter(template=template, name='does_not_exist_2').exists())
variables = self._save_related(template)
self.assertEqual(len(variables), 2)
self.assertTrue('sample_var' in variables)
self.assertTrue('another_test_var' in variables)
self.assertFalse(SnippetTemplateVariable.objects
.filter(template=template, name='does_not_exist').exists())
self.assertFalse(SnippetTemplateVariable.objects
.filter(template=template, name='does_not_exist_2').exists())
示例3: test_render_unicode
# 需要导入模块: from snippets.base.tests import SnippetTemplateFactory [as 别名]
# 或者: from snippets.base.tests.SnippetTemplateFactory import create [as 别名]
def test_render_unicode(self):
variable = SnippetTemplateVariableFactory(name='data')
template = SnippetTemplateFactory.create(code='{{ data }}',
variable_set=[variable])
snippet = SnippetFactory(template=template,
data='{"data": "\u03c6\u03bf\u03bf"}')
output = snippet.render()
eq_(pq(output)[0].text, u'\u03c6\u03bf\u03bf')
示例4: test_valid_args_activity_stream
# 需要导入模块: from snippets.base.tests import SnippetTemplateFactory [as 别名]
# 或者: from snippets.base.tests.SnippetTemplateFactory import create [as 别名]
def test_valid_args_activity_stream(self):
"""If template_id and data are both valid, return the preview page."""
template = SnippetTemplateFactory.create()
data = '{"a": "b"}'
response = self._preview_snippet(template_id=template.id, activity_stream=True, data=data)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['client'].startpage_version, 5)
self.assertTemplateUsed(response, 'base/preview_as.jinja')
示例5: test_snippets
# 需要导入模块: from snippets.base.tests import SnippetTemplateFactory [as 别名]
# 或者: from snippets.base.tests.SnippetTemplateFactory import create [as 别名]
def test_snippets(self):
instance = UploadedFileFactory.build()
instance.file = MagicMock()
instance.file.url = '/media/foo.png'
snippets = SnippetFactory.create_batch(2, data='lalala {0} foobar'.format(instance.url))
template = SnippetTemplateFactory.create(code='<foo>{0}</foo>'.format(instance.url))
more_snippets = SnippetFactory.create_batch(3, template=template)
self.assertEqual(set(instance.snippets), set(list(snippets) + list(more_snippets)))
示例6: test_invalid_data
# 需要导入模块: from snippets.base.tests import SnippetTemplateFactory [as 别名]
# 或者: from snippets.base.tests.SnippetTemplateFactory import create [as 别名]
def test_invalid_data(self):
"""If data is missing or invalid, return a 400 Bad Request."""
template = SnippetTemplateFactory.create()
response = self._preview_snippet(template_id=template.id)
eq_(response.status_code, 400)
response = self._preview_snippet(template_id=template.id,
data='{invalid."json]')
eq_(response.status_code, 400)
示例7: test_valid_args
# 需要导入模块: from snippets.base.tests import SnippetTemplateFactory [as 别名]
# 或者: from snippets.base.tests.SnippetTemplateFactory import create [as 别名]
def test_valid_args(self):
"""If template_id and data are both valid, return the preview page."""
template = SnippetTemplateFactory.create()
data = '{"a": "b"}'
response = self._preview_snippet(template_id=template.id, data=data)
self.assertEqual(response.status_code, 200)
snippet = response.context['snippets_json']
self.assertTrue(json.loads(snippet))
示例8: test_valid_args
# 需要导入模块: from snippets.base.tests import SnippetTemplateFactory [as 别名]
# 或者: from snippets.base.tests.SnippetTemplateFactory import create [as 别名]
def test_valid_args(self):
"""If template_id and data are both valid, return the preview page."""
template = SnippetTemplateFactory.create()
data = '{"a": "b"}'
response = self._preview_snippet(template_id=template.id, data=data)
eq_(response.status_code, 200)
snippet = response.context['snippet']
eq_(snippet.template, template)
eq_(snippet.data, data)
示例9: test_render_campaign
# 需要导入模块: from snippets.base.tests import SnippetTemplateFactory [as 别名]
# 或者: from snippets.base.tests.SnippetTemplateFactory import create [as 别名]
def test_render_campaign(self):
template = SnippetTemplateFactory.create()
template.render = Mock()
template.render.return_value = '<a href="asdf">qwer</a>'
data = '{"url": "asdf", "text": "qwer"}'
snippet = SnippetFactory.create(template=template, data=data, campaign='foo')
expected = Markup('<div data-snippet-id="{id}" data-weight="100" '
'data-campaign="foo" class="snippet-metadata">'
'<a href="asdf">qwer</a></div>'.format(id=snippet.id))
self.assertEqual(snippet.render().strip(), expected)
示例10: test_save_related_add_new
# 需要导入模块: from snippets.base.tests import SnippetTemplateFactory [as 别名]
# 或者: from snippets.base.tests.SnippetTemplateFactory import create [as 别名]
def test_save_related_add_new(self):
"""
save_related should add new TemplateVariables for any new variables in
the template code.
"""
template = SnippetTemplateFactory.create(code="""
<p>Testing {{ sample_var }}</p>
{% if not another_test_var %}
<p>Blah</p>
{% endif %}
""")
variables = self._save_related(template)
self.assertEqual(len(variables), 2)
self.assertTrue('sample_var' in variables)
self.assertTrue('another_test_var' in variables)
示例11: test_render_no_country
# 需要导入模块: from snippets.base.tests import SnippetTemplateFactory [as 别名]
# 或者: from snippets.base.tests.SnippetTemplateFactory import create [as 别名]
def test_render_no_country(self):
"""
If the snippet isn't geolocated, don't include the data-country
attribute.
"""
template = SnippetTemplateFactory.create()
template.render = Mock()
template.render.return_value = '<a href="asdf">qwer</a>'
data = '{"url": "asdf", "text": "qwer"}'
snippet = SnippetFactory.create(template=template, data=data)
expected = ('<div data-snippet-id="{0}" data-weight="100">'
'<a href="asdf">qwer</a></div>'
.format(snippet.id))
eq_(snippet.render().strip(), expected)
示例12: test_render_multiple_countries
# 需要导入模块: from snippets.base.tests import SnippetTemplateFactory [as 别名]
# 或者: from snippets.base.tests.SnippetTemplateFactory import create [as 别名]
def test_render_multiple_countries(self):
"""
Include multiple countries in data-countries
"""
template = SnippetTemplateFactory.create()
template.render = Mock()
template.render.return_value = '<a href="asdf">qwer</a>'
data = '{"url": "asdf", "text": "qwer"}'
snippet = SnippetFactory.create(template=template, data=data, countries=['us', 'el'])
expected = Markup(
'<div data-snippet-id="{0}" data-weight="100" data-campaign="" '
'class="snippet-metadata" data-countries="el,us">'
'<a href="asdf">qwer</a></div>'.format(snippet.id))
self.assertEqual(snippet.render().strip(), expected)
示例13: test_save_related_reserved_name
# 需要导入模块: from snippets.base.tests import SnippetTemplateFactory [as 别名]
# 或者: from snippets.base.tests.SnippetTemplateFactory import create [as 别名]
def test_save_related_reserved_name(self):
"""
save_related should not add new TemplateVariables for variables that
are in the RESERVED_VARIABLES list.
"""
template = SnippetTemplateFactory.create(code="""
<p>Testing {{ reserved_name }}</p>
{% if not another_test_var %}
<p>Blah</p>
{% endif %}
""")
variables = self._save_related(template)
self.assertEqual(len(variables), 1)
self.assertTrue('another_test_var' in variables)
self.assertFalse(SnippetTemplateVariable.objects
.filter(template=template, name='reserved_name').exists())
示例14: test_render
# 需要导入模块: from snippets.base.tests import SnippetTemplateFactory [as 别名]
# 或者: from snippets.base.tests.SnippetTemplateFactory import create [as 别名]
def test_render(self):
template = SnippetTemplateFactory.create()
template.render = Mock()
template.render.return_value = '<a href="asdf">qwer</a>'
data = '{"url": "asdf", "text": "qwer"}'
snippet = SnippetFactory.create(template=template, data=data,
country='us', weight=60)
expected = ('<div data-snippet-id="{0}" data-weight="60" data-country="us">'
'<a href="asdf">qwer</a></div>'.format(snippet.id))
eq_(snippet.render().strip(), expected)
template.render.assert_called_with({
'url': 'asdf',
'text': 'qwer',
'snippet_id': snippet.id
})
示例15: test_render_exclude_search_engines
# 需要导入模块: from snippets.base.tests import SnippetTemplateFactory [as 别名]
# 或者: from snippets.base.tests.SnippetTemplateFactory import create [as 别名]
def test_render_exclude_search_engines(self):
"""
If the snippet must get excluded from search engines,
include the data-exclude-from-search-engines attribute.
"""
template = SnippetTemplateFactory.create()
template.render = Mock()
template.render.return_value = '<a href="asdf">qwer</a>'
data = '{"url": "asdf", "text": "qwer"}'
snippet = SnippetFactory.create(template=template, data=data)
search_providers = SearchProviderFactory.create_batch(2)
snippet.exclude_from_search_providers.add(*search_providers)
engines = ','.join(map(lambda x: x.identifier, search_providers))
expected = Markup(
'<div data-snippet-id="{id}" data-weight="100" data-campaign="" '
'class="snippet-metadata" data-exclude-from-search-engines="{engines}">'
'<a href="asdf">qwer</a></div>'.format(id=snippet.id, engines=engines))
self.assertEqual(snippet.render().strip(), expected)