Example #1
0
 def test_translation_sequence_increases(self):
     """Make sure translation sequence increases monotonically."""
     newtrans1 = Translation.new('abc', 'en-us')
     newtrans1.save()
     newtrans2 = Translation.new('def', 'de')
     newtrans2.save()
     assert newtrans2.pk > newtrans1.pk, (
         'Translation sequence needs to keep increasing.')
Example #2
0
 def test_translation_sequence_increases(self):
     """Make sure translation sequence increases monotonically."""
     newtrans1 = Translation.new('abc', 'en-us')
     newtrans1.save()
     newtrans2 = Translation.new('def', 'de')
     newtrans2.save()
     assert newtrans2.pk > newtrans1.pk, (
         'Translation sequence needs to keep increasing.')
Example #3
0
def test_cache_key():
    # Test that we are not taking the db into account when building our
    # cache keys for django-cache-machine. See bug 928881.
    eq_(Translation._cache_key(1, 'default'),
        Translation._cache_key(1, 'slave'))

    # Test that we are using the same cache no matter what Translation class
    # we use.
    eq_(PurifiedTranslation._cache_key(1, 'default'),
        Translation._cache_key(1, 'default'))
    eq_(LinkifiedTranslation._cache_key(1, 'default'),
        Translation._cache_key(1, 'default'))
Example #4
0
def test_cache_key():
    # Test that we are not taking the db into account when building our
    # cache keys for django-cache-machine. See bug 928881.
    eq_(Translation._cache_key(1, 'default'),
        Translation._cache_key(1, 'slave'))

    # Test that we are using the same cache no matter what Translation class
    # we use.
    eq_(PurifiedTranslation._cache_key(1, 'default'),
        Translation._cache_key(1, 'default'))
    eq_(LinkifiedTranslation._cache_key(1, 'default'),
        Translation._cache_key(1, 'default'))
Example #5
0
 def test_empty_translations_seq(self):
     """Make sure we can handle an empty translation sequence table."""
     TranslationSequence.objects.all().delete()
     newtrans = Translation.new('abc', 'en-us')
     newtrans.save()
     assert newtrans.id > 0, (
         'Empty translation table should still generate an ID.')
Example #6
0
def test_translation_bool():
    t = lambda s: Translation(localized_string=s)

    assert bool(t('text')) is True
    assert bool(t(' ')) is False
    assert bool(t('')) is False
    assert bool(t(None)) is False
Example #7
0
 def test_empty_translations_seq(self):
     """Make sure we can handle an empty translation sequence table."""
     TranslationSequence.objects.all().delete()
     newtrans = Translation.new('abc', 'en-us')
     newtrans.save()
     assert newtrans.id > 0, (
         'Empty translation table should still generate an ID.')
Example #8
0
 def test_single_translation_sequence(self):
     """Make sure we only ever have one translation sequence."""
     TranslationSequence.objects.all().delete()
     eq_(TranslationSequence.objects.count(), 0)
     for i in range(5):
         newtrans = Translation.new(str(i), 'en-us')
         newtrans.save()
         eq_(TranslationSequence.objects.count(), 1)
Example #9
0
 def test_single_translation_sequence(self):
     """Make sure we only ever have one translation sequence."""
     TranslationSequence.objects.all().delete()
     eq_(TranslationSequence.objects.count(), 0)
     for i in range(5):
         newtrans = Translation.new(str(i), 'en-us')
         newtrans.save()
         eq_(TranslationSequence.objects.count(), 1)
Example #10
0
def get_trans(items):
    if not items:
        return

    model = items[0].__class__
    # FIXME: if we knew which db the queryset we are transforming used, we
    # could make sure we are re-using the same one.
    dbname = router.db_for_read(model)
    connection = connections[dbname]
    sql, params = build_query(model, connection)
    item_dict = dict((item.pk, item) for item in items)
    ids = ','.join(map(str, item_dict.keys()))

    cursor = connection.cursor()
    cursor.execute(sql.format(ids='(%s)' % ids), tuple(params))
    step = len(trans_fields)
    for row in cursor.fetchall():
        # We put the item's pk as the first selected field.
        item = item_dict[row[0]]
        for index, field in enumerate(model._meta.translated_fields):
            start = 1 + step * index
            t = Translation(*row[start:start + step])
            if t.id is not None and t.localized_string is not None:
                setattr(item, field.name, t)
Example #11
0
def test_comparison_with_lazy():
    x = Translation(localized_string='xxx')
    lazy_u = lazy(lambda x: x, unicode)
    x == lazy_u('xxx')
    lazy_u('xxx') == x
Example #12
0
 def test_sorting(self):
     """Test translation comparisons in Python code."""
     b = Translation.new('bbbb', 'de')
     a = Translation.new('aaaa', 'de')
     c = Translation.new('cccc', 'de')
     eq_(sorted([c, a, b]), [a, b, c])
Example #13
0
 def test_whitespace(self):
     t = Translation(localized_string='     khaaaaaan!    ', id=999)
     t.save()
     eq_('khaaaaaan!', t.localized_string)
Example #14
0
 def test_sorting(self):
     """Test translation comparisons in Python code."""
     b = Translation.new('bbbb', 'de')
     a = Translation.new('aaaa', 'de')
     c = Translation.new('cccc', 'de')
     eq_(sorted([c, a, b]), [a, b, c])
Example #15
0
 def test_whitespace(self):
     t = Translation(localized_string='     khaaaaaan!    ', id=999)
     t.save()
     eq_('khaaaaaan!', t.localized_string)
Example #16
0
def test_translation_unicode():
    t = lambda s: Translation(localized_string=s)

    eq_(unicode(t('hello')), 'hello')
    eq_(unicode(t(None)), '')
Example #17
0
 def t(s):
     return Translation(localized_string=s)