@@ -452,6 +452,51 @@ def test_catalog(self):
452452 'definitions' : BASE_RECURSIVE_SCHEMAS },
453453 stream_dict .get ('schema' ))
454454
455+ class TestDomainTable (unittest .TestCase ):
456+ maxDiff = None
457+ table_name = 'CHICKEN TIMES'
458+
459+ def setUp (self ):
460+ table_spec = {"columns" : [{"name" : 'our_test_domain_pk' , "type" : "test_domain" , "primary_key" : True },
461+ {"name" : 'our_test_domain' , "type" : "test_domain" },
462+ {"name" : 'our_test_integer_domain' , "type" : "test_integer_domain" }],
463+ "name" : TestHStoreTable .table_name }
464+ with get_test_connection () as conn :
465+ cur = conn .cursor ()
466+ cur .execute (""" DROP DOMAIN IF EXISTS test_domain CASCADE """ )
467+ cur .execute (""" CREATE DOMAIN test_domain AS text; """ )
468+ cur .execute (""" DROP DOMAIN IF EXISTS test_integerdomain CASCADE """ )
469+ cur .execute (""" CREATE DOMAIN test_integerdomain AS text; """ )
470+
471+ ensure_test_table (table_spec )
472+
473+ def test_catalog (self ):
474+ conn_config = get_test_connection_config ()
475+ streams = tap_postgres .do_discovery (conn_config )
476+ chicken_streams = [s for s in streams if s ['tap_stream_id' ] == 'public-CHICKEN TIMES' ]
477+ self .assertEqual (len (chicken_streams ), 1 )
478+ stream_dict = chicken_streams [0 ]
479+ stream_dict .get ('metadata' ).sort (key = lambda md : md ['breadcrumb' ])
480+
481+ with get_test_connection () as conn :
482+ with conn .cursor (cursor_factory = psycopg2 .extras .DictCursor ) as cur :
483+ cur .execute ("""INSERT INTO "CHICKEN TIMES" (our_test_domain_pk, our_test_domain, our_test_integer_domain) VALUES ('sad', 'happy', 3)""" )
484+ cur .execute ("""SELECT * FROM "CHICKEN TIMES" """ )
485+
486+ self .assertEqual (metadata .to_map (stream_dict .get ('metadata' )),
487+ {() : {'table-key-properties' : ['our_test_domain_pk' ], 'database-name' : 'postgres' , 'schema-name' : 'public' , 'is-view' : False , 'row-count' : 0 },
488+ ('properties' , 'our_test_domain_pk' ) : {'inclusion' : 'automatic' , 'sql-datatype' : 'text' , 'selected-by-default' : True },
489+ ('properties' , 'our_test_domain' ) : {'inclusion' : 'available' , 'sql-datatype' : 'text' , 'selected-by-default' : True },
490+ ('properties' , 'our_test_integer_domain' ) : {'inclusion' : 'available' , 'sql-datatype' : 'integer' , 'selected-by-default' : True }})
491+
492+
493+ self .assertEqual ({'properties' : {'our_test__integer_domain' : {'type' : ['null' , 'integer' ]},
494+ 'our_test_domain' : {'type' : ['null' , 'string' ]},
495+ 'our_test_domain_pk' : {'type' : ['string' ]}},
496+ 'type' : 'object' ,
497+ 'definitions' : BASE_RECURSIVE_SCHEMAS },
498+ stream_dict .get ('schema' ))
499+
455500class TestArraysTable (unittest .TestCase ):
456501 maxDiff = None
457502 table_name = 'CHICKEN TIMES'
@@ -536,7 +581,7 @@ class TestColumnGrants(unittest.TestCase):
536581 table_name = 'CHICKEN TIMES'
537582 user = 'tmp_user_for_grant_tests'
538583 password = 'password'
539-
584+
540585 def setUp (self ):
541586 table_spec = {"columns" : [{"name" : "id" , "type" : "integer" , "serial" : True },
542587 {"name" : 'size integer' , "type" : "integer" , "quoted" : True },
@@ -560,8 +605,8 @@ def setUp(self):
560605 LOGGER .info ("running sql: {}" .format (sql ))
561606 cur .execute (sql )
562607
563-
564-
608+
609+
565610
566611 def test_catalog (self ):
567612 conn_config = get_test_connection_config ()
@@ -587,7 +632,7 @@ def test_catalog(self):
587632 ('properties' , 'id' ): {'inclusion' : 'available' ,
588633 'selected-by-default' : True ,
589634 'sql-datatype' : 'integer' }})
590-
635+
591636 self .assertEqual ({'definitions' : BASE_RECURSIVE_SCHEMAS ,
592637 'type' : 'object' ,
593638 'properties' : {'id' : {'type' : ['null' , 'integer' ],
0 commit comments