本文整理汇总了Python中snippets.base.tests.SnippetFactory类的典型用法代码示例。如果您正苦于以下问题:Python SnippetFactory类的具体用法?Python SnippetFactory怎么用?Python SnippetFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SnippetFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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])
示例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])
示例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)))
示例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')
示例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])
示例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])
示例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))
示例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'])
示例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])
示例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]))
示例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')))
示例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')
示例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)
示例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']))
示例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))