#NEWLINE# def test_load_static_table_fk( self ) : #NEWLINE# #INDENT# 'Truncate and load a table which has a foreign key dependency' #NEWLINE# stmts = [ 'CREATE TABLE t1 (pc1 integer PRIMARY KEY, pc2 text)' , 'CREATE TABLE t2 (c1 integer, c2 integer REFERENCES t1, c3 text)' ] #NEWLINE# inmap = self . std_map ( ) #NEWLINE# inmap [ 'schema public' ] . update ( { #NEWLINE# #INDENT# 'table t1' : { #NEWLINE# #INDENT# 'columns' : [ { #NEWLINE# #INDENT# 'pc1' : { #NEWLINE# #INDENT# 'type' : 'integer' , #NEWLINE# 'not_null' : True , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'pc2' : { #NEWLINE# #INDENT# 'type' : 'text' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ] , #NEWLINE# 'primary_key' : { #NEWLINE# #INDENT# 't1_pkey' : { #NEWLINE# #INDENT# 'columns' : [ 'pc1' ] , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# 'table t2' : { #NEWLINE# #INDENT# 'columns' : [ { #NEWLINE# #INDENT# 'c1' : { #NEWLINE# #INDENT# 'type' : 'integer' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'c2' : { #NEWLINE# #INDENT# 'type' : 'integer' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'c3' : { #NEWLINE# #INDENT# 'type' : 'text' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ] , #NEWLINE# 'foreign_keys' : { #NEWLINE# #INDENT# 't2_c2_fkey' : { #NEWLINE# #INDENT# 'columns' : [ 'c2' ] , #NEWLINE# 'references' : { #NEWLINE# #INDENT# 'schema' : 'public' , #NEWLINE# 'table' : 't1' , #NEWLINE# 'columns' : [ 'pc1' ] , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# cfg = { #NEWLINE# #INDENT# 'datacopy' : { #NEWLINE# #INDENT# 'schema public' : [ 't1' ] , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# sql = self . to_sql ( inmap , stmts , config = cfg ) #NEWLINE# copy_stmt = ( '\\copy ' , 't1' , " from '" , os . path . join ( self . cfg [ 'files' ] [ 'data_path' ] , 'schema.public' , FILE_PATH ) , "' csv" ) #NEWLINE# assert ( sql [ 0 ] == 'ALTER TABLE t2 DROP CONSTRAINT t2_c2_fkey' ) #NEWLINE# assert ( sql [ 1 ] == 'TRUNCATE ONLY t1' ) #NEWLINE# assert ( sql [ 2 ] == copy_stmt ) #NEWLINE# assert ( copy_stmt [ 3 ] == 'ALTER TABLE t2 ADD CONSTRAINT t2_c2_fkey FOREIGN KEY (c2) REFERENCES t1 (pc1)' )