<s> from __future__ import print_function <EOL> from django . conf import settings <EOL> from django . contrib . auth import get_user_model <EOL> from django . core . management import call_command <EOL> from django . contrib . sites . models import Site <EOL> from django . test import TestCase <EOL> from django . test . utils import override_settings <EOL> import os <EOL> from parler import appsettings <EOL> try : <EOL> from importlib import import_module <EOL> except ImportError : <EOL> from django . utils . importlib import import_module <EOL> try : <EOL> User = get_user_model ( ) <EOL> except ImportError : <EOL> from django . contrib . auth . models import User <EOL> def clear_cache ( ) : <EOL> """<STR_LIT>""" <EOL> import django <EOL> if django . VERSION >= ( <NUM_LIT> ) : <EOL> try : <EOL> from django . db . models import loading <EOL> loading . cache . loaded = False <EOL> except ImportError : <EOL> pass <EOL> else : <EOL> from django . apps import apps <EOL> apps . clear_cache ( ) <EOL> class override_parler_settings ( override_settings ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( override_parler_settings , self ) . __init__ ( ** kwargs ) <EOL> self . old_values = { } <EOL> def enable ( self ) : <EOL> super ( override_parler_settings , self ) . enable ( ) <EOL> for key , value in self . options . items ( ) : <EOL> self . old_values [ key ] = getattr ( appsettings , key ) <EOL> setattr ( appsettings , key , value ) <EOL> def disable ( self ) : <EOL> super ( override_parler_settings , self ) . disable ( ) <EOL> for key in self . options . keys ( ) : <EOL> setattr ( appsettings , key , self . old_values [ key ] ) <EOL> class AppTestCase ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> user = None <EOL> install_apps = ( <EOL> '<STR_LIT>' , <EOL> ) <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> super ( AppTestCase , cls ) . setUpClass ( ) <EOL> from django . template . loaders import app_directories <EOL> if cls . install_apps : <EOL> run_syncdb = False <EOL> for appname in cls . install_apps : <EOL> if appname not in settings . INSTALLED_APPS : <EOL> print ( '<STR_LIT>' . format ( appname ) ) <EOL> settings . INSTALLED_APPS = ( appname , ) + tuple ( settings . INSTALLED_APPS ) <EOL> run_syncdb = True <EOL> testapp = import_module ( appname ) <EOL> clear_cache ( ) <EOL> app_directories . app_template_dirs += ( <EOL> os . path . join ( os . path . dirname ( testapp . __file__ ) , '<STR_LIT>' ) , <EOL> ) <EOL> if run_syncdb : <EOL> call_command ( '<STR_LIT>' , verbosity = <NUM_LIT:0> ) <EOL> Site . objects . get_or_create ( id = settings . SITE_ID , defaults = dict ( domain = '<STR_LIT>' , name = '<STR_LIT>' ) ) <EOL> cls . user , _ = User . objects . get_or_create ( is_superuser = True , is_staff = True , username = "<STR_LIT>" ) <EOL> cls . conf_fallbacks = list ( appsettings . PARLER_LANGUAGES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] or [ '<STR_LIT>' ] ) <EOL> cls . conf_fallback = cls . conf_fallbacks [ <NUM_LIT:0> ] <EOL> cls . other_lang1 = next ( x for x , _ in settings . LANGUAGES if x not in cls . conf_fallbacks ) <EOL> cls . other_lang2 = next ( x for x , _ in settings . LANGUAGES if x not in cls . conf_fallbacks + [ cls . other_lang1 ] ) </s>
