<s> from ... import OratorTestCase <EOL> from . import IntegrationTestCase , User , Post <EOL> from orator import Model <EOL> from orator . connections import SQLiteConnection <EOL> from orator . connectors . sqlite_connector import SQLiteConnector <EOL> class SchemaBuilderSQLiteIntegrationTestCase ( IntegrationTestCase , OratorTestCase ) : <EOL> @ classmethod <EOL> def get_connection_resolver ( cls ) : <EOL> return DatabaseIntegrationConnectionResolver ( ) <EOL> class SchemaBuilderSQLiteIntegrationCascadingTestCase ( OratorTestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> Model . set_connection_resolver ( DatabaseIntegrationConnectionWithoutForeignKeysResolver ( ) ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> Model . unset_connection_resolver ( ) <EOL> def setUp ( self ) : <EOL> with self . schema ( ) . create ( '<STR_LIT>' ) as table : <EOL> table . increments ( '<STR_LIT:id>' ) <EOL> table . string ( '<STR_LIT:email>' ) . unique ( ) <EOL> table . timestamps ( ) <EOL> with self . schema ( ) . create ( '<STR_LIT>' ) as table : <EOL> table . integer ( '<STR_LIT>' ) <EOL> table . integer ( '<STR_LIT>' ) <EOL> table . foreign ( '<STR_LIT>' ) . references ( '<STR_LIT:id>' ) . on ( '<STR_LIT>' ) . on_delete ( '<STR_LIT>' ) <EOL> table . foreign ( '<STR_LIT>' ) . references ( '<STR_LIT:id>' ) . on ( '<STR_LIT>' ) . on_delete ( '<STR_LIT>' ) <EOL> with self . schema ( ) . create ( '<STR_LIT>' ) as table : <EOL> table . increments ( '<STR_LIT:id>' ) <EOL> table . integer ( '<STR_LIT>' ) <EOL> table . string ( '<STR_LIT:name>' ) . unique ( ) <EOL> table . timestamps ( ) <EOL> table . foreign ( '<STR_LIT>' ) . references ( '<STR_LIT:id>' ) . on ( '<STR_LIT>' ) <EOL> with self . schema ( ) . create ( '<STR_LIT>' ) as table : <EOL> table . increments ( '<STR_LIT:id>' ) <EOL> table . morphs ( '<STR_LIT>' ) <EOL> table . string ( '<STR_LIT:name>' ) <EOL> table . timestamps ( ) <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> user = User . create ( email = '<STR_LIT>' % ( i + <NUM_LIT:1> ) ) <EOL> for j in range ( <NUM_LIT:10> ) : <EOL> post = Post ( name = '<STR_LIT>' % ( user . id , j + <NUM_LIT:1> ) ) <EOL> user . posts ( ) . save ( post ) <EOL> def tearDown ( self ) : <EOL> self . schema ( ) . drop ( '<STR_LIT>' ) <EOL> self . schema ( ) . drop ( '<STR_LIT>' ) <EOL> self . schema ( ) . drop ( '<STR_LIT>' ) <EOL> self . schema ( ) . drop ( '<STR_LIT>' ) <EOL> def test_cascading ( self ) : <EOL> user = User . create ( email = '<STR_LIT>' ) <EOL> friend = User . create ( email = '<STR_LIT>' ) <EOL> another_friend = User . create ( email = '<STR_LIT>' ) <EOL> user . friends ( ) . attach ( friend ) <EOL> user . friends ( ) . attach ( another_friend ) <EOL> user . delete ( ) <EOL> self . assertEqual ( <NUM_LIT:2> , user . get_connection_resolver ( ) . connection ( ) . table ( '<STR_LIT>' ) . count ( ) ) <EOL> def connection ( self ) : <EOL> return Model . get_connection_resolver ( ) . connection ( ) <EOL> def schema ( self ) : <EOL> return self . connection ( ) . get_schema_builder ( ) <EOL> class DatabaseIntegrationConnectionResolver ( object ) : <EOL> _connection = None <EOL> def connection ( self , name = None ) : <EOL> if self . _connection : <EOL> return self . _connection <EOL> self . _connection = SQLiteConnection ( SQLiteConnector ( ) . connect ( { '<STR_LIT>' : '<STR_LIT>' } ) ) <EOL> return self . _connection <EOL> def get_default_connection ( self ) : <EOL> return '<STR_LIT:default>' <EOL> def set_default_connection ( self , name ) : <EOL> pass <EOL> class DatabaseIntegrationConnectionWithoutForeignKeysResolver ( DatabaseIntegrationConnectionResolver ) : <EOL> _connection = None <EOL> def connection ( self , name = None ) : <EOL> if self . _connection : <EOL> return self . _connection <EOL> self . _connection = SQLiteConnection ( <EOL> SQLiteConnector ( ) . connect ( <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False } <EOL> ) <EOL> ) <EOL> return self . _connection </s>
