示例#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.')
示例#2
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'))
示例#3
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.')
示例#4
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)
示例#5
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')
     assert sorted([c, a, b]) == [a, b, c]
示例#6
0
def test_page_title_unicode():
    t = Translation(localized_string=u'\u30de\u30eb\u30c1\u30d712\u30eb')
    request = Mock()
    request.APP = amo.FIREFOX
    jinja_helpers.reviewer_page_title({'request': request}, title=t)
示例#7
0
 def test_whitespace(self):
     t = Translation(localized_string='     khaaaaaan!    ', id=999)
     t.save()
     eq_('khaaaaaan!', t.localized_string)
示例#8
0
def test_comparison_with_lazy():
    lazy_u = lazy(lambda s: s, str)
    Translation(localized_string='xxx') == lazy_u('xxx')
    lazy_u('xxx') == Translation(localized_string='xxx')
示例#9
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])
示例#10
0
 def test_whitespace(self):
     t = Translation(localized_string='     khaaaaaan!    ', id=999)
     t.save()
     assert 'khaaaaaan!' == t.localized_string
示例#11
0
 def translation(s):
     return Translation(localized_string=s)
示例#12
0
 def test_whitespace(self):
     t = Translation(localized_string='     khaaaaaan!    ', id=999)
     t.save()
     assert 'khaaaaaan!' == t.localized_string
示例#13
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.'
示例#14
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
示例#15
0
def smorgasbord(request):
    """
    Gather many different kinds of tasty add-ons together.

    Great for testing install buttons.
    """
    def _compat(min, max):
        # Helper for faking compatible_apps.
        return {'min': {'version': min}, 'max': {'version': max}}

    addons = []
    normal_version = _compat('1.0', '10.0')
    older_version = _compat('1.0', '2.0')
    newer_version = _compat('9.0', '10.0')

    def all_versions(addon, base_tag):
        x = (('', normal_version),
             (' + older version', older_version),
             (' + newer version', newer_version))
        for extra, version in x:
            a = addon()
            a.tag = base_tag + extra
            a.compatible_apps[request.APP] = version
            addons.append(a)

    # Featured.
    featured = Addon.objects.featured(request.APP)
    addons.append(featured[0])
    addons[-1].tag = 'featured'

    normal = Addon.objects.listed(request.APP).exclude(id__in=featured)

    # Normal, Older Version, Newer Version.
    all_versions(lambda: normal[0], 'normal')

    # Unreviewed.
    exp = Addon.objects.unreviewed()
    all_versions(lambda: exp[0], 'unreviewed')

    # Multiple Platforms.
    addons.append(Addon.objects.get(id=2313))
    addons[-1].tag = 'platformer'

    # Multiple Platforms + EULA.
    addons.append(Addon.objects.get(id=2313))
    addons[-1].eula = Translation(localized_string='xxx')
    addons[-1].tag = 'platformer + eula'

    # Incompatible Platform + EULa.
    addons.append(Addon.objects.get(id=5308))
    addons[-1].eula = Translation(localized_string='xxx')
    addons[-1].tag = 'windows/linux-only + eula'

    # Incompatible Platform.
    all_versions(lambda: Addon.objects.get(id=5308), 'windows/linux-only')

    # EULA.
    eula = (Q(eula__isnull=False, eula__localized_string__isnull=False)
            & ~Q(eula__localized_string=''))
    addons.append(normal.filter(eula)[0])
    addons[-1].tag = 'eula'
    addons.append(exp.filter(eula)[0])
    addons[-1].tag = 'eula + unreviewed'

    # Contributions.
    addons.append(normal.filter(annoying=1)[0])
    addons[-1].tag = 'contrib: passive'
    addons.append(normal.filter(annoying=2)[0])
    addons[-1].tag = 'contrib: after'
    addons.append(normal.filter(annoying=3)[0])
    addons[-1].tag = 'contrib: roadblock'
    addons.append(Addon.objects.get(id=2608))
    addons[-1].tag = 'after + eula'
    addons.append(Addon.objects.get(id=8442))
    addons[-1].tag = 'roadblock + eula'

    # Other App.
    addons.append(Addon.objects.get(id=5326))
    addons[-1].tag = 'tbird'

    # Mobile.
    addons.append(Addon.objects.get(id=53476))
    addons[-1].tag = 'mobile'

    # Search Engine.
    addons.append(Addon.objects.filter(type=amo.ADDON_SEARCH)[0])
    addons[-1].tag = 'search engine'

    # Beta Version
    beta = normal.filter(versions__files__status=amo.STATUS_BETA)[0]
    beta.tag = 'beta version'

    # Theme.

    # Persona.
    addons.append(Addon.objects.filter(type=amo.ADDON_PERSONA)[0])
    addons[-1].tag = 'persona'

    # Future Version.
    # No versions.

    return render(request, 'addons/smorgasbord.html',
                  {'addons': addons, 'beta': beta})
示例#16
0
 def test_whitespace(self):
     t = Translation(localized_string='     khaaaaaan!    ', id=999)
     t.save()
     eq_('khaaaaaan!', t.localized_string)