<s> from __future__ import unicode_literals <EOL> from django . apps import apps <EOL> from django . conf import settings <EOL> from django . db import connection <EOL> from django . test import TestCase , skipIfDBFeature , skipUnlessDBFeature <EOL> from . models . tablespaces import ( <EOL> Article , ArticleRef , Authors , Reviewers , Scientist , ScientistRef , <EOL> ) <EOL> def sql_for_table ( model ) : <EOL> with connection . schema_editor ( collect_sql = True ) as editor : <EOL> editor . create_model ( model ) <EOL> return editor . collected_sql [ <NUM_LIT:0> ] <EOL> def sql_for_index ( model ) : <EOL> return '<STR_LIT:\n>' . join ( connection . schema_editor ( ) . _model_indexes_sql ( model ) ) <EOL> class TablespacesTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . _old_models = apps . app_configs [ '<STR_LIT>' ] . models . copy ( ) <EOL> for model in Article , Authors , Reviewers , Scientist : <EOL> model . _meta . managed = True <EOL> def tearDown ( self ) : <EOL> for model in Article , Authors , Reviewers , Scientist : <EOL> model . _meta . managed = False <EOL> apps . app_configs [ '<STR_LIT>' ] . models = self . _old_models <EOL> apps . all_models [ '<STR_LIT>' ] = self . _old_models <EOL> apps . clear_cache ( ) <EOL> def assertNumContains ( self , haystack , needle , count ) : <EOL> real_count = haystack . count ( needle ) <EOL> self . assertEqual ( real_count , count , "<STR_LIT>" % ( real_count , needle , count ) ) <EOL> @ skipUnlessDBFeature ( '<STR_LIT>' ) <EOL> def test_tablespace_for_model ( self ) : <EOL> sql = sql_for_table ( Scientist ) . lower ( ) <EOL> if settings . DEFAULT_INDEX_TABLESPACE : <EOL> self . assertNumContains ( sql , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> self . assertNumContains ( sql , settings . DEFAULT_INDEX_TABLESPACE , <NUM_LIT:1> ) <EOL> else : <EOL> self . assertNumContains ( sql , '<STR_LIT>' , <NUM_LIT:2> ) <EOL> @ skipIfDBFeature ( '<STR_LIT>' ) <EOL> def test_tablespace_ignored_for_model ( self ) : <EOL> self . assertEqual ( sql_for_table ( Scientist ) , <EOL> sql_for_table ( ScientistRef ) ) <EOL> @ skipUnlessDBFeature ( '<STR_LIT>' ) <EOL> def test_tablespace_for_indexed_field ( self ) : <EOL> sql = sql_for_table ( Article ) . lower ( ) <EOL> if settings . DEFAULT_INDEX_TABLESPACE : <EOL> self . assertNumContains ( sql , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> self . assertNumContains ( sql , settings . DEFAULT_INDEX_TABLESPACE , <NUM_LIT:2> ) <EOL> else : <EOL> self . assertNumContains ( sql , '<STR_LIT>' , <NUM_LIT:3> ) <EOL> self . assertNumContains ( sql , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> @ skipIfDBFeature ( '<STR_LIT>' ) <EOL> def test_tablespace_ignored_for_indexed_field ( self ) : <EOL> self . assertEqual ( sql_for_table ( Article ) , <EOL> sql_for_table ( ArticleRef ) ) <EOL> @ skipUnlessDBFeature ( '<STR_LIT>' ) <EOL> def test_tablespace_for_many_to_many_field ( self ) : <EOL> sql = sql_for_table ( Authors ) . lower ( ) <EOL> if settings . DEFAULT_INDEX_TABLESPACE : <EOL> self . assertNumContains ( sql , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> self . assertNumContains ( sql , settings . DEFAULT_INDEX_TABLESPACE , <NUM_LIT:1> ) <EOL> else : <EOL> self . assertNumContains ( sql , '<STR_LIT>' , <NUM_LIT:2> ) <EOL> self . assertNumContains ( sql , '<STR_LIT>' , <NUM_LIT:0> ) <EOL> sql = sql_for_index ( Authors ) . lower ( ) <EOL> if settings . DEFAULT_INDEX_TABLESPACE : <EOL> self . assertNumContains ( sql , settings . DEFAULT_INDEX_TABLESPACE , <NUM_LIT:2> ) <EOL> else : <EOL> self . assertNumContains ( sql , '<STR_LIT>' , <NUM_LIT:2> ) <EOL> self . assertNumContains ( sql , '<STR_LIT>' , <NUM_LIT:0> ) <EOL> sql = sql_for_table ( Reviewers ) . lower ( ) <EOL> if settings . DEFAULT_INDEX_TABLESPACE : <EOL> self . assertNumContains ( sql , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> self . assertNumContains ( sql , settings . DEFAULT_INDEX_TABLESPACE , <NUM_LIT:1> ) <EOL> else : <EOL> self . assertNumContains ( sql , '<STR_LIT>' , <NUM_LIT:2> ) <EOL> self . assertNumContains ( sql , '<STR_LIT>' , <NUM_LIT:0> ) <EOL> sql = sql_for_index ( Reviewers ) . lower ( ) <EOL> self . assertNumContains ( sql , '<STR_LIT>' , <NUM_LIT:0> ) <EOL> self . assertNumContains ( sql , '<STR_LIT>' , <NUM_LIT:2> ) </s>
