本文整理汇总了Python中snippets.base.tests.SnippetFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python SnippetFactory.create方法的具体用法?Python SnippetFactory.create怎么用?Python SnippetFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类snippets.base.tests.SnippetFactory
的用法示例。
在下文中一共展示了SnippetFactory.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_match_client
# 需要导入模块: from snippets.base.tests import SnippetFactory [as 别名]
# 或者: from snippets.base.tests.SnippetFactory import create [as 别名]
def test_match_client(self):
params = {}
snippet = SnippetFactory.create(on_release=True, on_startpage_4=True,
locales=['en-us'])
SnippetFactory.create(on_release=False, on_startpage_4=True,
locales=['en-us'])
self._assert_client_matches_snippets(params, [snippet])
示例2: test_match_client_match_locale
# 需要导入模块: from snippets.base.tests import SnippetFactory [as 别名]
# 或者: from snippets.base.tests.SnippetFactory import create [as 别名]
def test_match_client_match_locale(self):
params = {}
snippet = SnippetFactory.create(on_release=True, on_startpage_4=True,
locale_set=[SnippetLocale(locale='en-US')])
SnippetFactory.create(on_release=True, on_startpage_4=True,
locale_set=[SnippetLocale(locale='fr')])
self._assert_client_matches_snippets(params, [snippet])
示例3: test_match_client_invalid_locale
# 需要导入模块: from snippets.base.tests import SnippetFactory [as 别名]
# 或者: from snippets.base.tests.SnippetFactory import create [as 别名]
def test_match_client_invalid_locale(self):
"""
If client sends invalid locale return snippets with no locales
specified.
"""
params = {'locale': 'foo'}
snippet = SnippetFactory.create(on_release=True, on_startpage_4=True, locales=[])
SnippetFactory.create(on_release=True, on_startpage_4=True, locales=['en-us'])
self._assert_client_matches_snippets(params, [snippet])
示例4: test_match_client_multiple_locales
# 需要导入模块: from snippets.base.tests import SnippetFactory [as 别名]
# 或者: from snippets.base.tests.SnippetFactory import create [as 别名]
def test_match_client_multiple_locales(self):
"""
If there are multiple locales that should match the client's
locale, include all of them.
"""
params = {'locale': 'es-mx'}
snippet_1 = SnippetFactory.create(on_release=True, on_startpage_4=True, locales=['es'])
snippet_2 = SnippetFactory.create(on_release=True, on_startpage_4=True, locales=['es-mx'])
self._assert_client_matches_snippets(params, [snippet_1, snippet_2])
示例5: test_match_client_match_channel_partially
# 需要导入模块: from snippets.base.tests import SnippetFactory [as 别名]
# 或者: from snippets.base.tests.SnippetFactory import create [as 别名]
def test_match_client_match_channel_partially(self):
"""
Client channels like "release-cck-mozilla14" should match
"release".
"""
params = {'channel': 'release-cck-mozilla14'}
snippet = SnippetFactory.create(on_release=True, on_startpage_4=True,
locale_set=[SnippetLocale(locale='en-US')])
SnippetFactory.create(on_release=False, on_startpage_4=True,
locale_set=[SnippetLocale(locale='en-US')])
self._assert_client_matches_snippets(params, [snippet])
示例6: test_base
# 需要导入模块: from snippets.base.tests import SnippetFactory [as 别名]
# 或者: from snippets.base.tests.SnippetFactory import create [as 别名]
def test_base(self):
snippets = SnippetFactory.create_batch(2)
jsonsnippets = JSONSnippetFactory.create_batch(2)
SnippetFactory.create(disabled=True)
JSONSnippetFactory.create(disabled=True)
response = views.ActiveSnippetsView.as_view()(self.request)
eq_(response.get('content-type'), 'application/json')
data = json.loads(response.content)
eq_(set([snippets[0].id, snippets[1].id,
jsonsnippets[0].id, jsonsnippets[1].id]),
set([x['id'] for x in data]))
示例7: test_base
# 需要导入模块: from snippets.base.tests import SnippetFactory [as 别名]
# 或者: from snippets.base.tests.SnippetFactory import create [as 别名]
def test_base(self):
# Matching snippets.
snippet_1 = SnippetFactory.create(on_nightly=True)
# Matching but disabled snippet.
SnippetFactory.create(on_nightly=True, disabled=True)
# Snippet that doesn't match.
SnippetFactory.create(on_nightly=False),
snippets_ok = [snippet_1]
params = self.client_params
response = self.client.get('/{0}/'.format('/'.join(params)))
eq_(set(snippets_ok), set(response.context['snippets']))
eq_(response.context['locale'], 'en-US')
示例8: test_no_locales
# 需要导入模块: from snippets.base.tests import SnippetFactory [as 别名]
# 或者: from snippets.base.tests.SnippetFactory import create [as 别名]
def test_no_locales(self):
"""
If the form being saved has no locale field, do not alter the snippet's
locale.
"""
en_us = SnippetLocale(locale='en-us')
fr = SnippetLocale(locale='fr')
snippet = SnippetFactory.create(locale_set=[en_us, fr])
data = {
'name': 'test',
'data': '{}',
'template': snippet.template.id,
'priority': 0,
'weight': 100,
}
# FormClass has no locale field.
class FormClass(ModelForm):
class Meta:
model = Snippet
fields = ('name', 'data', 'template', 'priority', 'weight')
form = FormClass(data, instance=snippet)
self._save_model(snippet, form)
snippet = Snippet.objects.get(pk=snippet.pk)
locales = (l.locale for l in snippet.locale_set.all())
self.assertEqual(set(locales), set(('en-us', 'fr')))
示例9: test_valid_disabled_snippet_authenticated
# 需要导入模块: from snippets.base.tests import SnippetFactory [as 别名]
# 或者: from snippets.base.tests.SnippetFactory import create [as 别名]
def test_valid_disabled_snippet_authenticated(self):
"""Test disabled snippet returns 200 to authenticated users."""
snippet = SnippetFactory.create(disabled=True)
User.objects.create_superuser('admin', '[email protected]', 'asdf')
self.client.login(username='admin', password='asdf')
response = self.client.get(reverse('base.show', kwargs={'snippet_id': snippet.id}))
eq_(response.status_code, 200)
示例10: test_publish_date_filters
# 需要导入模块: from snippets.base.tests import SnippetFactory [as 别名]
# 或者: from snippets.base.tests.SnippetFactory import create [as 别名]
def test_publish_date_filters(self, mock_datetime):
"""
If it is currently outside of the publish times for a snippet, it
should not be included in the response.
"""
mock_datetime.utcnow.return_value = datetime(2013, 4, 5)
# Passing snippets.
snippet_no_dates = SnippetFactory.create(on_release=True)
snippet_after_start_date = SnippetFactory.create(
on_release=True,
publish_start=datetime(2013, 3, 6)
)
snippet_before_end_date = SnippetFactory.create(
on_release=True,
publish_end=datetime(2013, 6, 6)
)
snippet_within_range = SnippetFactory.create(
on_release=True,
publish_start=datetime(2013, 3, 6),
publish_end=datetime(2013, 6, 6)
)
# Failing snippets.
SnippetFactory.create( # Before start date.
on_release=True,
publish_start=datetime(2013, 5, 6)
)
SnippetFactory.create( # After end date.
on_release=True,
publish_end=datetime(2013, 3, 6)
)
SnippetFactory.create( # Outside range.
on_release=True,
publish_start=datetime(2013, 6, 6),
publish_end=datetime(2013, 7, 6)
)
params = ('4', 'Firefox', '23.0a1', '20130510041606',
'Darwin_Universal-gcc3', 'en-US', 'release',
'Darwin%2010.8.0', 'default', 'default_version')
response = self.client.get('/{0}/'.format('/'.join(params)))
expected = set([snippet_no_dates, snippet_after_start_date,
snippet_before_end_date, snippet_within_range])
eq_(expected, set(response.context['snippets']))
示例11: test_default_is_same_as_nightly
# 需要导入模块: from snippets.base.tests import SnippetFactory [as 别名]
# 或者: from snippets.base.tests.SnippetFactory import create [as 别名]
def test_default_is_same_as_nightly(self):
""" Make sure that default channel follows nightly. """
# Snippets matching nightly (and therefor should match default).
nightly_snippet = SnippetFactory.create(on_nightly=True)
# Snippets that don't match nightly
SnippetFactory.create(on_beta=True)
nightly_client = self._build_client(channel='nightly')
nightly_snippets = Snippet.cached_objects.match_client(nightly_client)
default_client = self._build_client(channel='default')
default_snippets = Snippet.cached_objects.match_client(default_client)
# Assert that both the snippets returned from nightly and from default
# are the same snippets. Just `nightly_snippet` in this case.
eq_(set([nightly_snippet]), set(nightly_snippets))
eq_(set([nightly_snippet]), set(default_snippets))
示例12: test_match_client_multiple_locales_distinct
# 需要导入模块: from snippets.base.tests import SnippetFactory [as 别名]
# 或者: from snippets.base.tests.SnippetFactory import create [as 别名]
def test_match_client_multiple_locales_distinct(self):
"""
If a snippet has multiple locales and a client matches more
than one of them, the snippet should only be included in the
queryset once.
"""
params = {'locale': 'es-mx'}
snippet = SnippetFactory.create(on_release=True, on_startpage_4=True,
locales=['es', 'es-mx'])
self._assert_client_matches_snippets(params, [snippet])
示例13: test_render_campaign
# 需要导入模块: from snippets.base.tests import SnippetFactory [as 别名]
# 或者: from snippets.base.tests.SnippetFactory 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)
示例14: test_render_data_with_snippet_id
# 需要导入模块: from snippets.base.tests import SnippetFactory [as 别名]
# 或者: from snippets.base.tests.SnippetFactory import create [as 别名]
def test_render_data_with_snippet_id(self):
"""
Any strings included in the template context should have the
substring "[[snippet_id]]" replaced with the ID of the snippet.
"""
snippet = SnippetFactory.create(
template__code='<p>{{ code }}</p>',
data='{"code": "snippet id [[snippet_id]]", "foo": true}')
snippet.template.render = Mock()
snippet.render()
snippet.template.render.assert_called_with({'code': 'snippet id {0}'.format(snippet.id),
'snippet_id': snippet.id,
'foo': True})
示例15: test_match_client_multiple_locale_matches
# 需要导入模块: from snippets.base.tests import SnippetFactory [as 别名]
# 或者: from snippets.base.tests.SnippetFactory import create [as 别名]
def test_match_client_multiple_locale_matches(self):
"""
If a snippet has multiple locales and a client matches more than one of them, the snippet
should only be included in the queryset once.
"""
es_mx = SnippetLocale(locale='es-mx')
es = SnippetLocale(locale='es')
snippet = SnippetFactory.create(locale_set=[es_mx, es])
client = self._build_client(locale='es-MX')
snippets = Snippet.cached_objects.match_client(client)
# Filter out any snippets that aren't the one we made, and ensure there's only one.
eq_(len([s for s in snippets if s.pk == snippet.pk]), 1)