本文整理汇总了Python中snippets.base.tests.SnippetFactory类的典型用法代码示例。如果您正苦于以下问题:Python SnippetFactory类的具体用法?Python SnippetFactory怎么用?Python SnippetFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SnippetFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_match_client
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])
开发者ID:glogiotatidis,项目名称:snippets-service,代码行数:7,代码来源:test_managers.py
示例2: test_match_client_match_locale
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])
开发者ID:ckprice,项目名称:snippets-service,代码行数:7,代码来源:test_managers.py
示例3: test_snippets
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)))
开发者ID:akatsoulas,项目名称:snippets-service,代码行数:8,代码来源:test_models.py
示例4: test_render_unicode
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')
开发者ID:hoosteeno,项目名称:snippets-service,代码行数:8,代码来源:test_models.py
示例5: test_match_client_invalid_locale
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])
开发者ID:glogiotatidis,项目名称:snippets-service,代码行数:9,代码来源:test_managers.py
示例6: test_match_client_multiple_locales
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])
开发者ID:glogiotatidis,项目名称:snippets-service,代码行数:9,代码来源:test_managers.py
示例7: test_snippet
def test_snippet(self):
nightly_snippets = SnippetFactory.create_batch(
2, on_release=False, on_nightly=True)
SnippetFactory.create_batch(2, on_release=False, on_beta=True)
filtr = ChannelFilter(None, {'channel': 'on_nightly'}, Snippet, SnippetAdmin)
result = filtr.queryset(None, Snippet.objects.all())
self.assertTrue(result.count(), 2)
self.assertEqual(set(result.all()), set(nightly_snippets))
开发者ID:glogiotatidis,项目名称:snippets-service,代码行数:10,代码来源:test_filters.py
示例8: test_base
def test_base(self):
snippet_without_end_date = SnippetFactory(published=True, publish_end=None)
snippet_that_has_ended = SnippetFactory(published=True, publish_end=datetime.utcnow())
snippet_ending_in_the_future = SnippetFactory(
published=True, publish_end=datetime.utcnow() + timedelta(days=1))
call_command('disable_snippets_past_publish_date', stdout=Mock())
snippet_without_end_date.refresh_from_db()
snippet_that_has_ended.refresh_from_db()
snippet_ending_in_the_future.refresh_from_db()
self.assertFalse(snippet_that_has_ended.published)
self.assertTrue(snippet_without_end_date.published)
self.assertTrue(snippet_ending_in_the_future.published)
asrsnippet_without_end_date = ASRSnippetFactory(
status=STATUS_CHOICES['Published'],
publish_end=None)
asrsnippet_that_has_ended = ASRSnippetFactory(
status=STATUS_CHOICES['Published'],
publish_end=datetime.utcnow())
asrsnippet_ending_in_the_future = ASRSnippetFactory(
status=STATUS_CHOICES['Published'],
publish_end=datetime.utcnow() + timedelta(days=1))
call_command('disable_snippets_past_publish_date', stdout=Mock())
asrsnippet_without_end_date.refresh_from_db()
asrsnippet_that_has_ended.refresh_from_db()
asrsnippet_ending_in_the_future.refresh_from_db()
self.assertEqual(asrsnippet_that_has_ended.status, STATUS_CHOICES['Approved'])
self.assertEqual(asrsnippet_without_end_date.status, STATUS_CHOICES['Published'])
self.assertEqual(asrsnippet_ending_in_the_future.status, STATUS_CHOICES['Published'])
开发者ID:glogiotatidis,项目名称:snippets-service,代码行数:35,代码来源:test_commands.py
示例9: test_match_client_match_channel_partially
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])
开发者ID:ckprice,项目名称:snippets-service,代码行数:11,代码来源:test_managers.py
示例10: test_base
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]))
开发者ID:alicoding,项目名称:snippets-service,代码行数:11,代码来源:test_views.py
示例11: test_no_locales
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')))
开发者ID:schalkneethling,项目名称:snippets-service,代码行数:27,代码来源:test_admin.py
示例12: test_base
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')
开发者ID:Osmose,项目名称:snippets-service,代码行数:16,代码来源:test_views.py
示例13: test_valid_disabled_snippet_authenticated
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)
开发者ID:alicoding,项目名称:snippets-service,代码行数:7,代码来源:test_views.py
示例14: test_publish_date_filters
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']))
开发者ID:hoosteeno,项目名称:snippets-service,代码行数:46,代码来源:test_views.py
示例15: test_default_is_same_as_nightly
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))
开发者ID:ckprice,项目名称:snippets-service,代码行数:18,代码来源:test_managers.py
示例16: test_render_no_snippet_id
def test_render_no_snippet_id(self):
"""
If a snippet that hasn't been saved to the database yet is rendered, the snippet ID
shouldn't be included in the template context.
"""
snippet = SnippetFactory.build(template__code='<p>{{ snippet_id }}</p>')
snippet.template.render = Mock()
snippet.render()
snippet.template.render.assert_called_with({})
开发者ID:hoosteeno,项目名称:snippets-service,代码行数:9,代码来源:test_models.py
示例17: test_match_client_multiple_locales_distinct
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])
开发者ID:glogiotatidis,项目名称:snippets-service,代码行数:10,代码来源:test_managers.py
示例18: test_render_data_with_snippet_id
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.build(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', 'snippet_id': 0,
'foo': True})
开发者ID:koddsson,项目名称:snippets-service,代码行数:11,代码来源:test_models.py
示例19: test_render_campaign
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)
开发者ID:akatsoulas,项目名称:snippets-service,代码行数:12,代码来源:test_models.py
示例20: test_render_data_with_snippet_id
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})
开发者ID:akatsoulas,项目名称:snippets-service,代码行数:13,代码来源:test_models.py
注:本文中的snippets.base.tests.SnippetFactory类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论