@@ -365,6 +365,16 @@ def test_catalog(self):
365365 'definitions' : tap_postgres .BASE_RECURSIVE_SCHEMAS },
366366 stream_dict .get ('schema' ))
367367
368+ def test_escaping_values (self ):
369+ key = 'nickname'
370+ value = "Dave's Courtyard"
371+ elem = '"{}"=>"{}"' .format (key , value )
372+
373+ with get_test_connection () as conn :
374+ with conn .cursor () as cur :
375+ query = tap_postgres .sync_strategies .logical_replication .create_hstore_elem_query (elem )
376+ self .assertEqual (query .as_string (cur ), "SELECT hstore_to_array('\" nickname\" =>\" Dave''s Courtyard\" ')" )
377+
368378
369379class TestEnumTable (unittest .TestCase ):
370380 maxDiff = None
@@ -566,6 +576,63 @@ def test_catalog(self):
566576 'definitions' : tap_postgres .BASE_RECURSIVE_SCHEMAS },
567577 stream_dict .get ('schema' ))
568578
579+ class TestColumnGrants (unittest .TestCase ):
580+ maxDiff = None
581+ table_name = 'CHICKEN TIMES'
582+ user = 'tmp_user_for_grant_tests'
583+ password = 'password'
584+
585+ def setUp (self ):
586+ table_spec = {"columns" : [{"name" : "id" , "type" : "integer" , "serial" : True },
587+ {"name" : 'size integer' , "type" : "integer" , "quoted" : True },
588+ {"name" : 'size smallint' , "type" : "smallint" , "quoted" : True },
589+ {"name" : 'size bigint' , "type" : "bigint" , "quoted" : True }],
590+ "name" : TestColumnGrants .table_name }
591+ ensure_test_table (table_spec )
592+
593+ with get_test_connection () as conn :
594+ cur = conn .cursor ()
595+
596+ sql = """ DROP USER IF EXISTS {} """ .format (self .user , self .password )
597+ LOGGER .info (sql )
598+ cur .execute (sql )
599+
600+ sql = """ CREATE USER {} WITH PASSWORD '{}' """ .format (self .user , self .password )
601+ LOGGER .info (sql )
602+ cur .execute (sql )
603+
604+ sql = """ GRANT SELECT ("id") ON "{}" TO {}""" .format (TestColumnGrants .table_name , self .user )
605+ LOGGER .info ("running sql: {}" .format (sql ))
606+ cur .execute (sql )
607+
608+
609+
610+
611+ def test_catalog (self ):
612+ conn_config = get_test_connection_config ()
613+ conn_config ['user' ] = self .user
614+ conn_config ['password' ] = self .password
615+ streams = tap_postgres .do_discovery (conn_config )
616+ chicken_streams = [s for s in streams if s ['tap_stream_id' ] == 'postgres-public-CHICKEN TIMES' ]
617+
618+ self .assertEqual (len (chicken_streams ), 1 )
619+ stream_dict = chicken_streams [0 ]
620+
621+ self .assertEqual (TestStringTableWithPK .table_name , stream_dict .get ('table_name' ))
622+ self .assertEqual (TestStringTableWithPK .table_name , stream_dict .get ('stream' ))
623+
624+
625+ stream_dict .get ('metadata' ).sort (key = lambda md : md ['breadcrumb' ])
626+
627+ self .assertEqual (metadata .to_map (stream_dict .get ('metadata' )),
628+ {() : {'table-key-properties' : [], 'database-name' : 'postgres' , 'schema-name' : 'public' , 'is-view' : False , 'row-count' : 0 },
629+ ('properties' , 'id' ) : {'inclusion' : 'available' , 'sql-datatype' : 'integer' , 'selected-by-default' : True }})
630+
631+ self .assertEqual ({'definitions' : tap_postgres .BASE_RECURSIVE_SCHEMAS ,
632+ 'type' : 'object' ,
633+ 'properties' : {'id' : {'type' : ['null' , 'integer' ], 'minimum' : - 2147483648 , 'maximum' : 2147483647 }}},
634+ stream_dict .get ('schema' ))
635+
569636
570637if __name__ == "__main__" :
571638 test1 = TestArraysTable ()
0 commit comments