Родитель
2fe1eec01a
Коммит
6667c90c73
|
@ -1,9 +1,10 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from settings import * # noqa
|
||||
|
||||
# Make sure the app needed to test translations is present.
|
||||
# Make sure the apps needed to test translations and core are present.
|
||||
INSTALLED_APPS += (
|
||||
'olympia.translations.tests.testapp',
|
||||
'olympia.core.tests.db_tests_testapp',
|
||||
)
|
||||
# Make sure the debug toolbar isn't used during the tests.
|
||||
INSTALLED_APPS = [app for app in INSTALLED_APPS if app != 'debug_toolbar']
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
from django.db import models
|
||||
|
||||
|
||||
class TestRegularCharField(models.Model):
|
||||
name = models.CharField(max_length=255)
|
|
@ -0,0 +1,16 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import pytest
|
||||
|
||||
from olympia.core.tests.db_tests_testapp.models import TestRegularCharField
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.parametrize('value', [
|
||||
u'a',
|
||||
u'🔍', # Magnifying Glass Tilted Left (U+1F50D)
|
||||
u'❤', # Heavy Black Heart (U+2764, U+FE0F)
|
||||
])
|
||||
def test_max_length_utf8mb4(value):
|
||||
TestRegularCharField.objects.create(name=value * 255)
|
||||
|
||||
assert TestRegularCharField.objects.get().name == value * 255
|
|
@ -768,3 +768,40 @@ def test_translated_field_fk_lookups():
|
|||
fresh_parent = TranslatedModel.objects.get(pk=parent.pk)
|
||||
assert fresh_parent.translated_through_fk.name_id == obj.name_id
|
||||
assert fresh_parent.translated_through_fk.name is not None
|
||||
|
||||
|
||||
def test_translated_field_emoji_support():
|
||||
# Make sure utf8mb4 settings are correct and emojis are correctly handled
|
||||
assert Translation.objects.count() == 0
|
||||
obj = TranslatedModel.objects.create(name=u'😀❤')
|
||||
|
||||
def get_model():
|
||||
return TranslatedModel.objects.get(pk=obj.pk)
|
||||
|
||||
assert Translation.objects.count() == 1
|
||||
|
||||
# Make sure the translation id is stored on the model, not the autoid.
|
||||
assert obj.name.id == obj.name_id
|
||||
|
||||
# Reload the object from database with a different locale activated.
|
||||
# Its name should still be there, using the fallback...
|
||||
translation.activate('de')
|
||||
german = get_model()
|
||||
assert german.name == u'😀❤'
|
||||
assert german.name.locale == 'en-us'
|
||||
|
||||
# Check that a different locale creates a new row with the same id.
|
||||
german.name = u'😀'
|
||||
german.save()
|
||||
|
||||
assert Translation.objects.count() == 2 # New name *and* description.
|
||||
assert german.name == u'😀'
|
||||
assert german.name.locale == 'de'
|
||||
|
||||
# ids should be the same, autoids are different.
|
||||
assert obj.name.id == german.name.id
|
||||
assert obj.name.autoid != german.name.autoid
|
||||
|
||||
# Check that de finds the right translation.
|
||||
fresh_german = get_model()
|
||||
assert fresh_german.name == u'😀'
|
||||
|
|
Загрузка…
Ссылка в новой задаче