当前位置: 首页>>代码示例>>Python>>正文


Python test_utils.trans_eq函数代码示例

本文整理汇总了Python中test_utils.trans_eq函数的典型用法代码示例。如果您正苦于以下问题:Python trans_eq函数的具体用法?Python trans_eq怎么用?Python trans_eq使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了trans_eq函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_fetch_translation_de_locale

 def test_fetch_translation_de_locale(self):
     """Check that locale fallbacks work."""
     try:
         translation.activate('de')
         o = TranslatedModel.objects.get(id=1)
         trans_eq(o.name, 'German!! (unst unst)', 'de')
         trans_eq(o.description, 'some description', 'en-US')
     finally:
         translation.deactivate()
开发者ID:almosteverywhere,项目名称:zamboni,代码行数:9,代码来源:test_models.py

示例2: test_get_fallback

    def test_get_fallback(self):
        """Return the translation for the locale fallback."""
        user = UserProfile.objects.create(
            lang='fr', bio={'en-US': 'my bio', 'fr': 'ma bio'})
        trans_eq(user.bio, 'my bio', 'en-US')  # Uses current locale.

        with self.activate(locale='de'):
            user = UserProfile.objects.get(pk=user.pk)  # Reload.
            trans_eq(user.bio, 'ma bio', 'fr')  # Uses the default fallback.
开发者ID:arpitnigam,项目名称:olympia,代码行数:9,代码来源:test_models.py

示例3: test_update_translation

    def test_update_translation(self):
        o = TranslatedModel.objects.get(id=1)
        translation_id = o.name.autoid

        o.name = 'new name'
        o.save()

        o = TranslatedModel.objects.get(id=1)
        trans_eq(o.name, 'new name', 'en-US')
        # Make sure it was an update, not an insert.
        eq_(o.name.autoid, translation_id)
开发者ID:almosteverywhere,项目名称:zamboni,代码行数:11,代码来源:test_models.py

示例4: test_post

 def test_post(self):
     assert self.client.login(username='[email protected]',
                              password='password')
     url = reverse('localizers.categories', kwargs=dict(locale_code='es-ES'))
     data = {
         'form-TOTAL_FORMS': 2,
         'form-INITIAL_FORMS': 2,
         'form-0-id': self.cat1.id,
         'form-0-name': u'Nada',
         'form-1-id': self.cat2.id,
         'form-1-name': u'Amigo',
     }
     res = self.client.post(url, data, follow=True)
     self.assertRedirects(res, url, status_code=302)
     doc = pq(res.content.decode('utf-8'))
     eq_(doc('#id_form-0-name').val(), u'Nada')
     eq_(doc('#id_form-1-name').val(), u'Amigo')
     cat = Category.objects.get(pk=self.cat1.id)
     trans_eq(cat.name, u'Nada', 'es-ES')
开发者ID:pennyfx,项目名称:zamboni,代码行数:19,代码来源:test_views.py

示例5: test_translations

    def test_translations(self):
        translation.activate('en-US')

        # There's en-US and de translations.  We should get en-US.
        r1 = Review.objects.get(id=1)
        test_utils.trans_eq(r1.title, 'r1 title en', 'en-US')

        # There's only a de translation, so we get that.
        r2 = Review.objects.get(id=2)
        test_utils.trans_eq(r2.title, 'r2 title de', 'de')

        translation.activate('de')

        # en and de exist, we get de.
        r1 = Review.objects.get(id=1)
        test_utils.trans_eq(r1.title, 'r1 title de', 'de')

        # There's only a de translation, so we get that.
        r2 = Review.objects.get(id=2)
        test_utils.trans_eq(r2.title, 'r2 title de', 'de')
开发者ID:AALEKH,项目名称:zamboni,代码行数:20,代码来源:test_models.py

示例6: test_translations

    def test_translations(self):
        translation.activate('en-US')

        # There's en-US and de translations.  We should get en-US.
        r1 = Rating.objects.get(id=1)
        trans_eq(r1.body, 'r1 body en', 'en-US')

        # There's only a de translation, so we get that.
        r2 = Rating.objects.get(id=2)
        trans_eq(r2.body, 'r2 body de', 'de')

        translation.activate('de')

        # en and de exist, we get de.
        r1 = Rating.objects.get(id=1)
        trans_eq(r1.body, 'r1 body de', 'de')

        # There's only a de translation, so we get that.
        r2 = Rating.objects.get(id=2)
        trans_eq(r2.body, 'r2 body de', 'de')
开发者ID:gkoberger,项目名称:zamboni,代码行数:20,代码来源:test_models.py

示例7: test_create_with_dict

    def test_create_with_dict(self):
        # Set translations with a dict.
        strings = {'en-US': 'right language', 'de': 'wrong language'}
        o = TranslatedModel.objects.create(name=strings)

        # Make sure we get the English text since we're in en-US.
        trans_eq(o.name, 'right language', 'en-US')

        # Check that de was set.
        translation.activate('de')
        o = TranslatedModel.objects.get(id=o.id)
        trans_eq(o.name, 'wrong language', 'de')

        # We're in de scope, so we should see the de text.
        de = TranslatedModel.objects.create(name=strings)
        trans_eq(o.name, 'wrong language', 'de')

        # Make sure en-US was still set.
        translation.deactivate()
        o = TranslatedModel.objects.get(id=de.id)
        trans_eq(o.name, 'right language', 'en-US')
开发者ID:almosteverywhere,项目名称:zamboni,代码行数:21,代码来源:test_models.py

示例8: test_update_with_dict

    def test_update_with_dict(self):
        # There's existing en-US and de strings.
        strings = {'de': None, 'fr': 'oui'}
        get_model = lambda: TranslatedModel.objects.get(id=1)

        # Don't try checking that the model's name value is en-US.  It will be
        # one of the other locales, but we don't know which one.  You just set
        # the name to a dict, deal with it.
        get_model().name = strings

        # en-US was not touched.
        trans_eq(get_model().name, 'some name', 'en-US')

        # de was updated to NULL, so it falls back to en-US.
        translation.activate('de')
        trans_eq(get_model().name, 'some name', 'en-US')

        # fr was added.
        translation.activate('fr')
        trans_eq(get_model().name, 'oui', 'fr')
开发者ID:mccammos,项目名称:zamboni,代码行数:20,代码来源:test_models.py

示例9: test_fetch_translations

 def test_fetch_translations(self):
     """Basic check of fetching translations in the current locale."""
     o = TranslatedModel.objects.get(id=1)
     trans_eq(o.name, 'some name', 'en-US')
     trans_eq(o.description, 'some description', 'en-US')
开发者ID:almosteverywhere,项目名称:zamboni,代码行数:5,代码来源:test_models.py

示例10: test_create_translation

    def test_create_translation(self):
        o = TranslatedModel.objects.create(name='english name')
        get_model = lambda: TranslatedModel.objects.get(id=o.id)
        trans_eq(o.name, 'english name', 'en-US')
        eq_(o.description, None)

        # Make sure the translation id is stored on the model, not the autoid.
        eq_(o.name.id, o.name_id)

        # Check that a different locale creates a new row with the same id.
        translation.activate('de')
        german = get_model()
        trans_eq(o.name, 'english name', 'en-US')

        german.name = u'Gemütlichkeit name'
        german.description = u'clöüserw description'
        german.save()

        trans_eq(german.name, u'Gemütlichkeit name', 'de')
        trans_eq(german.description, u'clöüserw description', 'de')

        # ids should be the same, autoids are different.
        eq_(o.name.id, german.name.id)
        assert o.name.autoid != german.name.autoid

        # Check that de finds the right translation.
        fresh_german = get_model()
        trans_eq(fresh_german.name, u'Gemütlichkeit name', 'de')
        trans_eq(fresh_german.description, u'clöüserw description', 'de')

        # Check that en-US has the right translations.
        translation.deactivate()
        english = get_model()
        trans_eq(english.name, 'english name', 'en-US')
        english.debug = True
        eq_(english.description, None)

        english.description = 'english description'
        english.save()

        fresh_english = get_model()
        trans_eq(fresh_english.description, 'english description', 'en-US')
        eq_(fresh_english.description.id, fresh_german.description.id)
开发者ID:almosteverywhere,项目名称:zamboni,代码行数:43,代码来源:test_models.py


注:本文中的test_utils.trans_eq函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。