11import unittest
2+ from unittest import mock
23import tap_postgres
34import tap_postgres .sync_strategies .full_table as full_table
45import tap_postgres .sync_strategies .common as pg_common
@@ -62,7 +63,8 @@ def setUp(self):
6263 global CAUGHT_MESSAGES
6364 CAUGHT_MESSAGES .clear ()
6465
65- def test_catalog (self ):
66+ @mock .patch ('tap_postgres.sync_logical_streams' )
67+ def test_catalog (self , mock_sync_logical_streams ):
6668 singer .write_message = singer_write_message_no_cow
6769 pg_common .write_schema_message = singer_write_message_ok
6870
@@ -90,7 +92,7 @@ def test_catalog(self):
9092 insert_record (cur , 'COW' , cow_rec )
9193
9294 conn .close ()
93-
95+
9496 blew_up_on_cow = False
9597 state = {}
9698 #the initial phase of cows logical replication will be a full table.
@@ -100,6 +102,8 @@ def test_catalog(self):
100102 except Exception :
101103 blew_up_on_cow = True
102104
105+ mock_sync_logical_streams .assert_not_called ()
106+
103107 self .assertTrue (blew_up_on_cow )
104108
105109 self .assertEqual (7 , len (CAUGHT_MESSAGES ))
@@ -151,6 +155,8 @@ def test_catalog(self):
151155 CAUGHT_MESSAGES .clear ()
152156 tap_postgres .do_sync (get_test_connection_config (), {'streams' : streams }, None , old_state )
153157
158+ mock_sync_logical_streams .assert_called_once ()
159+
154160 self .assertEqual (8 , len (CAUGHT_MESSAGES ))
155161
156162 self .assertEqual (CAUGHT_MESSAGES [0 ]['type' ], 'SCHEMA' )
@@ -238,7 +244,7 @@ def test_catalog(self):
238244
239245 conn = get_test_connection ()
240246 conn .autocommit = True
241-
247+
242248 with conn .cursor () as cur :
243249 cow_rec = {'name' : 'betty' , 'colour' : 'blue' }
244250 insert_record (cur , 'COW' , {'name' : 'betty' , 'colour' : 'blue' })
@@ -256,7 +262,7 @@ def test_catalog(self):
256262
257263 state = {}
258264 blew_up_on_cow = False
259-
265+
260266 #this will sync the CHICKEN but then blow up on the COW
261267 try :
262268 tap_postgres .do_sync (get_test_connection_config (), {'streams' : streams }, None , state )
0 commit comments