本文整理汇总了Python中fjord.translations.models.SuperModel类的典型用法代码示例。如果您正苦于以下问题:Python SuperModel类的具体用法?Python SuperModel怎么用?Python SuperModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SuperModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_translate_dennis
def test_translate_dennis(self):
obj = SuperModel(locale='fr', desc=u'This is a test string')
obj.save()
assert obj.trans_desc == u''
translate(obj, 'dennis', 'br', 'desc', 'en', 'trans_desc')
assert obj.trans_desc == u'\xabTHIS IS A TEST STRING\xbb'
示例2: test_translate_fake
def test_translate_fake(self):
obj = SuperModel(locale='br', desc=u'This is a test string')
obj.save()
assert obj.trans_desc == u''
translate(obj, 'fake', 'br', 'desc', 'en', 'trans_desc')
assert obj.trans_desc == u'THIS IS A TEST STRING'
示例3: test_translate_gengo_human_unsupported_pair
def test_translate_gengo_human_unsupported_pair(self):
obj = SuperModel(locale='el', desc=u'This is really greek.')
obj.save()
assert obj.trans_desc == u''
translate(obj, 'gengo_human', 'el', 'desc', 'en', 'trans_desc')
# el -> en is not a supported pair, so it shouldn't get translated.
assert obj.trans_desc == u''
示例4: test_translate_gengo_human_english_copy_over
def test_translate_gengo_human_english_copy_over(self):
obj = SuperModel(locale='es', desc=u'This is English.')
obj.save()
assert obj.trans_desc == u''
translate(obj, 'gengo_human', 'es', 'desc', 'en', 'trans_desc')
# If the guesser guesses English, then we just copy it over.
assert obj.trans_desc == u'This is English.'
示例5: test_gengo_push_translations
def test_gengo_push_translations(self):
"""Tests GengoOrders get created"""
ght = GengoHumanTranslator()
# Create a few jobs covering multiple languages
descs = [
('es', u'Facebook no se puede enlazar con peru'),
('es', u'No es compatible con whatsap'),
('de', u'Absturze und langsam unter Android'),
]
for lang, desc in descs:
obj = SuperModel(locale=lang, desc=desc)
obj.save()
job = GengoJob(
content_object=obj,
tier='standard',
src_field='desc',
dst_field='trans_desc',
src_lang=lang,
dst_lang='en'
)
job.save()
with patch('fjord.translations.gengo_utils.Gengo') as GengoMock:
mocker = GengoMock.return_value
mocker.getAccountBalance.return_value = {
u'opstat': u'ok',
u'response': {
u'credits': '400.00',
u'currency': u'USD'
}
}
# FIXME: This returns the same thing both times, but to
# make the test "more kosher" we'd have this return two
# different order_id values.
mocker.postTranslationJobs.return_value = {
u'opstat': u'ok',
u'response': {
u'order_id': u'1337',
u'job_count': 2,
u'credits_used': u'0.35',
u'currency': u'USD'
}
}
ght.push_translations()
assert GengoOrder.objects.count() == 2
order_by_id = dict(
[(order.id, order) for order in GengoOrder.objects.all()]
)
jobs = GengoJob.objects.all()
for job in jobs:
assert job.order_id in order_by_id
示例6: test_translate_gengo_human
def test_translate_gengo_human(self):
# Note: This just sets up the GengoJob--it doesn't create any
# Gengo human translation jobs.
obj = SuperModel(
locale='es', desc=u'Facebook no se puede enlazar con peru')
obj.save()
assert obj.trans_desc == u''
translate(obj, 'gengo_human', 'es', 'desc', 'en', 'trans_desc')
# Nothing should be translated
assert obj.trans_desc == u''
assert len(GengoJob.objects.all()) == 1
示例7: test_translate_gengo_machine_english_copy_over
def test_translate_gengo_machine_english_copy_over(self):
"""If the guesser guesses english, we copy it over"""
with patch('fjord.translations.gengo_utils.Gengo') as GengoMock:
gengo_mock_instance = GengoMock.return_value
obj = SuperModel(locale='es', desc=u'This is English.')
obj.save()
eq_(obj.trans_desc, u'')
translate(obj, 'gengo_machine', 'es', 'desc', 'en', 'trans_desc')
eq_(obj.trans_desc, u'This is English.')
# Make sure we don't call postTranslationJobs().
eq_(gengo_mock_instance.postTranslationJobs.call_count, 0)
示例8: test_translate_gengo_machine_unknown_language
def test_translate_gengo_machine_unknown_language(self):
"""Translation should handle unknown languages without erroring"""
with patch('fjord.translations.gengo_utils.Gengo') as GengoMock:
gengo_mock_instance = GengoMock.return_value
obj = SuperModel(locale='es', desc=u'Muy lento')
obj.save()
eq_(obj.trans_desc, u'')
translate(obj, 'gengo_machine', 'es', 'desc', 'en', 'trans_desc')
eq_(obj.trans_desc, u'')
# Make sure we don't call postTranslationJobs().
eq_(gengo_mock_instance.postTranslationJobs.call_count, 0)
示例9: test_one
def test_one(self):
"""Test the basic case"""
model_path = SuperModel.__module__ + '.' + SuperModel.__name__
obj = SuperModel(locale='br', desc=u'This is a test string')
obj.save()
# Verify no translation, yet
assert obj.trans_desc == u''
translate_tasks_by_id_list.delay(model_path, [obj.id])
# Fetch the object from the db to verify it's been translated.
obj = SuperModel.objects.get(id=obj.id)
assert obj.trans_desc == u'THIS IS A TEST STRING'
示例10: test_no_translate_if_disabled
def test_no_translate_if_disabled(self):
"""No GengoAPI calls if gengosystem switch is disabled"""
with patch('fjord.translations.models.waffle') as waffle_mock:
waffle_mock.switch_is_active.return_value = False
with patch('fjord.translations.gengo_utils.Gengo') as GengoMock:
obj = SuperModel(locale='es', desc=u'Muy lento')
obj.save()
eq_(obj.trans_desc, u'')
translate(obj, 'gengo_machine', 'es', 'desc', 'en',
'trans_desc')
eq_(obj.trans_desc, u'')
# We should not have used the API at all.
eq_(GengoMock.called, False)
示例11: test_gengo_machine_translation
def test_gengo_machine_translation(self):
# Note: This doesn't work in the sandbox, so we skip it if
# we're in sandbox mode. That is some happy horseshit, but so
# it goes.
# Note: This test might be brittle since it's calling out to
# Gengo to do a machine translation and it's entirely possible
# that they might return a different translation some day.
obj = SuperModel(
locale='es',
desc=u'Facebook no se puede enlazar con peru'
)
obj.save()
eq_(obj.trans_desc, u'')
translate(obj, 'gengo_machine', 'es', 'desc', 'en', 'trans_desc')
eq_(obj.trans_desc, u'Facebook can bind with peru')
示例12: test_many
def test_many(self):
model_path = SuperModel.__module__ + '.' + SuperModel.__name__
objs = []
for i in range(50):
obj = SuperModel(locale='br', desc=u'string %d' % i)
obj.save()
objs.append(obj)
translate_tasks_by_id_list.delay(
model_path, [obj_.id for obj_ in objs])
for obj in objs:
obj = SuperModel.objects.get(id=obj.id)
# Note: The fake translation just uppercases things. We're
# abusing inner knowledge of that here.
assert obj.trans_desc == obj.desc.upper()
示例13: test_no_translate_if_disabled
def test_no_translate_if_disabled(self):
"""No GengoAPI calls if gengosystem switch is disabled"""
with patch('fjord.translations.models.waffle') as waffle_mock:
waffle_mock.switch_is_active.return_value = False
with patch('fjord.translations.gengo_utils.Gengo') as GengoMock:
# Note: This just sets up the GengoJob--it doesn't
# create any Gengo human translation jobs.
obj = SuperModel(
locale='es', desc=u'Facebook no se puede enlazar con peru')
obj.save()
assert obj.trans_desc == u''
translate(obj, 'gengo_human', 'es', 'desc', 'en', 'trans_desc')
assert obj.trans_desc == u''
# Verify no jobs were created
assert len(GengoJob.objects.all()) == 0
# Verify we didn't call the API at all.
assert GengoMock.called == False
示例14: test_translate_gengo_machine_unsupported_language
def test_translate_gengo_machine_unsupported_language(self):
"""Translation should handle unsupported languages without erroring"""
gengo_utils.GENGO_LANGUAGE_CACHE = (
{u'opstat': u'ok',
u'response': [
{u'unit_type': u'word', u'localized_name': u'Deutsch',
u'lc': u'de', u'language': u'German'}
]},
(u'de',)
)
with patch('fjord.translations.gengo_utils.Gengo') as GengoMock:
gengo_mock_instance = GengoMock.return_value
obj = SuperModel(locale='es', desc=u'Muy lento')
obj.save()
eq_(obj.trans_desc, u'')
translate(obj, 'gengo_machine', 'es', 'desc', 'en', 'trans_desc')
eq_(obj.trans_desc, u'')
# Make sure we don't call postTranslationJobs().
eq_(gengo_mock_instance.postTranslationJobs.call_count, 0)
示例15: test_translate_gengo_machine
def test_translate_gengo_machine(self):
with patch('fjord.translations.gengo_utils.Gengo') as GengoMock:
# Note: We're mocking with "Muy lento" because it's
# short, but the Gengo language guesser actually can't
# figure out what language that is.
instance = GengoMock.return_value
instance.postTranslationJobs.return_value = {
u'opstat': u'ok',
u'response': {
u'jobs': {
u'job_1': {
u'status': u'approved',
u'job_id': u'NULL',
u'credits': 0,
u'unit_count': 7,
u'body_src': u'Muy lento',
u'mt': 1,
u'eta': -1,
u'custom_data': u'10101',
u'tier': u'machine',
u'lc_tgt': u'en',
u'lc_src': u'es',
u'body_tgt': u'Very slow',
u'slug': u'Input machine translation',
u'ctime': u'2014-05-21 15:09:50.361847'
}
}
}
}
obj = SuperModel(locale='es', desc=u'Muy lento')
obj.save()
eq_(obj.trans_desc, u'')
translate(obj, 'gengo_machine', 'es', 'desc', 'en', 'trans_desc')
eq_(obj.trans_desc, u'Very slow')