<s> from __future__ import unicode_literals <EOL> import json <EOL> from django . utils import translation <EOL> from . . import settings <EOL> from . . import utils <EOL> from . base import BaseTestCase <EOL> class UtilsTest ( BaseTestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_get_language_name ( self ) : <EOL> expected = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ] <EOL> for e in expected : <EOL> self . assertEqual ( utils . get_language_name ( e [ <NUM_LIT:0> ] ) , e [ <NUM_LIT:1> ] ) <EOL> def test_get_language ( self ) : <EOL> translation . activate ( '<STR_LIT>' ) <EOL> self . assertEqual ( utils . get_language ( ) , '<STR_LIT>' ) <EOL> translation . activate ( '<STR_LIT>' ) <EOL> self . assertEqual ( utils . get_fallback_language ( ) , '<STR_LIT>' ) <EOL> self . assertEqual ( utils . get_language ( ) , utils . get_fallback_language ( ) ) <EOL> translation . deactivate_all ( ) <EOL> self . assertEqual ( utils . get_fallback_language ( ) , '<STR_LIT>' ) <EOL> self . assertEqual ( utils . get_language ( ) , utils . get_fallback_language ( ) ) <EOL> def test_get_fallback_language ( self ) : <EOL> self . assertEqual ( utils . get_fallback_language ( ) , settings . DEFAULT_LANGUAGE ) <EOL> def test_get_supported_languages ( self ) : <EOL> languages = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> old = list ( settings . SUPPORTED_LANGUAGES ) <EOL> settings . SUPPORTED_LANGUAGES = languages <EOL> self . assertEqual ( utils . get_supported_languages ( ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> settings . SUPPORTED_LANGUAGES = old <EOL> def test_get_language_fields ( self ) : <EOL> self . assertEqual ( utils . get_language_fields ( [ '<STR_LIT:title>' ] ) , [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] ) <EOL> def test_build_localized_field_name ( self ) : <EOL> self . assertEqual ( utils . build_localized_field_name ( '<STR_LIT:title>' , '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( utils . build_localized_field_name ( '<STR_LIT:title>' , '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> translation . deactivate_all ( ) <EOL> self . assertEqual ( utils . build_localized_field_name ( '<STR_LIT:title>' ) , '<STR_LIT>' ) <EOL> translation . activate ( '<STR_LIT>' ) <EOL> self . assertEqual ( utils . build_localized_field_name ( '<STR_LIT:title>' ) , '<STR_LIT>' ) <EOL> def test_get_translation_lookup ( self ) : <EOL> expected = { <EOL> '<STR_LIT:title>' : { <EOL> '<STR_LIT>' : '<STR_LIT:title>' , <EOL> '<STR_LIT>' : '<STR_LIT:value>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT:title>' , <EOL> '<STR_LIT>' : '<STR_LIT:value>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT:title>' , <EOL> '<STR_LIT>' : '<STR_LIT:value>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT:title>' , <EOL> '<STR_LIT>' : '<STR_LIT:value>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> } <EOL> for k , v in expected . items ( ) : <EOL> lookup = utils . get_translation_lookup ( '<STR_LIT:foo>' , k , '<STR_LIT:value>' ) <EOL> lookup = json . loads ( json . dumps ( lookup , sort_keys = True ) ) <EOL> self . assertEqual ( lookup , expected [ k ] ) </s>
