<s> from imp import load_module , PY_SOURCE <EOL> import os . path <EOL> from django . conf import settings <EOL> from django . template import loader , TemplateDoesNotExist <EOL> from django . test . utils import override_settings <EOL> from django . utils . encoding import force_text <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from cms import constants <EOL> from cms . test_utils . testcases import CMSTestCase <EOL> from cms . utils import get_cms_setting <EOL> PATH_PREFIX = os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> GOOD_PATH = os . path . join ( settings . PROJECT_PATH , '<STR_LIT>' , '<STR_LIT>' , PATH_PREFIX ) <EOL> BAD_PATH = os . path . join ( settings . PROJECT_PATH , '<STR_LIT>' , '<STR_LIT>' ) <EOL> SITE_PATH = { <EOL> <NUM_LIT:1> : os . path . join ( settings . PROJECT_PATH , '<STR_LIT>' , '<STR_LIT>' , PATH_PREFIX ) , <EOL> <NUM_LIT:2> : os . path . join ( settings . PROJECT_PATH , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' % PATH_PREFIX ) , <EOL> } <EOL> class TemplatesConfig ( CMSTestCase ) : <EOL> def test_templates ( self ) : <EOL> """<STR_LIT>""" <EOL> original_files = [ template [ <NUM_LIT:0> ] for template in settings . CMS_TEMPLATES ] <EOL> files = [ template [ <NUM_LIT:0> ] for template in get_cms_setting ( '<STR_LIT>' ) ] <EOL> if get_cms_setting ( '<STR_LIT>' ) : <EOL> original_files . append ( constants . TEMPLATE_INHERITANCE_MAGIC ) <EOL> self . assertEqual ( len ( files ) , <NUM_LIT:6> ) <EOL> self . assertEqual ( set ( files ) , set ( original_files ) ) <EOL> @ override_settings ( CMS_TEMPLATES_DIR = GOOD_PATH ) <EOL> def test_custom_templates ( self ) : <EOL> """<STR_LIT>""" <EOL> config_path = os . path . join ( settings . CMS_TEMPLATES_DIR , '<STR_LIT>' ) <EOL> with open ( config_path , '<STR_LIT:r>' ) as openfile : <EOL> mod = load_module ( "<STR_LIT>" , openfile , config_path , ( '<STR_LIT:m>' , '<STR_LIT:r>' , PY_SOURCE ) ) <EOL> original_labels = [ force_text ( _ ( template [ <NUM_LIT:1> ] ) ) for template in mod . TEMPLATES . items ( ) ] <EOL> original_files = [ os . path . join ( PATH_PREFIX , template [ <NUM_LIT:0> ] . strip ( ) ) for template in mod . TEMPLATES . items ( ) ] <EOL> templates = get_cms_setting ( '<STR_LIT>' ) <EOL> self . assertEqual ( len ( templates ) , <NUM_LIT:3> ) <EOL> labels = [ force_text ( template [ <NUM_LIT:1> ] ) for template in templates ] <EOL> files = [ template [ <NUM_LIT:0> ] for template in templates ] <EOL> if get_cms_setting ( '<STR_LIT>' ) : <EOL> original_labels . append ( force_text ( _ ( '<STR_LIT>' ) ) ) <EOL> original_files . append ( constants . TEMPLATE_INHERITANCE_MAGIC ) <EOL> self . assertEqual ( set ( labels ) , set ( original_labels ) ) <EOL> self . assertEqual ( set ( files ) , set ( original_files ) ) <EOL> @ override_settings ( CMS_TEMPLATES_DIR = GOOD_PATH ) <EOL> def test_custom_templates_loading ( self ) : <EOL> """<STR_LIT>""" <EOL> templates = get_cms_setting ( '<STR_LIT>' ) <EOL> for template in templates : <EOL> if template [ <NUM_LIT:0> ] != constants . TEMPLATE_INHERITANCE_MAGIC : <EOL> tpl = loader . get_template ( template [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( tpl . template . name , template [ <NUM_LIT:0> ] ) <EOL> @ override_settings ( CMS_TEMPLATES_DIR = SITE_PATH ) <EOL> def test_multisite ( self ) : <EOL> """<STR_LIT>""" <EOL> templates = get_cms_setting ( '<STR_LIT>' ) <EOL> for template in templates : <EOL> if template [ <NUM_LIT:0> ] != constants . TEMPLATE_INHERITANCE_MAGIC : <EOL> self . assertTrue ( template [ <NUM_LIT:0> ] . find ( '<STR_LIT>' % SITE_PATH [ <NUM_LIT:1> ] ) >= - <NUM_LIT:1> ) <EOL> with self . settings ( SITE_ID = <NUM_LIT:2> ) : <EOL> templates = get_cms_setting ( '<STR_LIT>' ) <EOL> for template in templates : <EOL> if template [ <NUM_LIT:0> ] != constants . TEMPLATE_INHERITANCE_MAGIC : <EOL> self . assertTrue ( template [ <NUM_LIT:0> ] . find ( '<STR_LIT>' % SITE_PATH [ <NUM_LIT:2> ] ) >= - <NUM_LIT:1> ) <EOL> @ override_settings ( CMS_TEMPLATES_DIR = BAD_PATH ) <EOL> def test_custom_templates_bad_dir ( self ) : <EOL> """<STR_LIT>""" <EOL> templates = get_cms_setting ( '<STR_LIT>' ) <EOL> for template in templates : <EOL> if template [ <NUM_LIT:0> ] != constants . TEMPLATE_INHERITANCE_MAGIC : <EOL> with self . assertRaises ( TemplateDoesNotExist ) : <EOL> loader . get_template ( template [ <NUM_LIT:0> ] ) </s>
