Skip to content

Commit a05e78b

Browse files
authored
Adding Primary / Unique key tests
1 parent 5530709 commit a05e78b

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

tests/test_tap_mssql.py

+57
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,63 @@ def test_do_not_discover_key_properties_for_view(self):
650650

651651
self.assertEqual(primary_keys, {"a_table": ["id"], "a_view": []})
652652

653+
class TestPrimaryKeyUniqueKey(unittest.TestCase):
654+
def setUp(self):
655+
self.conn = test_utils.get_test_connection()
656+
657+
with connect_with_backoff(self.conn) as open_conn:
658+
with open_conn.cursor() as cursor:
659+
try:
660+
cursor.execute("drop table uc_only_table")
661+
except:
662+
pass
663+
try:
664+
cursor.execute("drop table pk_only_table")
665+
except:
666+
pass
667+
try:
668+
cursor.execute("drop table pk_uc_table")
669+
except:
670+
pass
671+
cursor.execute(
672+
"""
673+
CREATE TABLE uc_only_table (
674+
pk int,
675+
uc_1 int,
676+
uc_2 int,
677+
CONSTRAINT constraint_uc_only_table UNIQUE(uc_1,uc_2) )
678+
"""
679+
)
680+
cursor.execute(
681+
"""
682+
CREATE TABLE pk_only_table (
683+
pk int PRIMARY KEY,
684+
uc_1 int,
685+
uc_2 int,
686+
)
687+
"""
688+
)
689+
cursor.execute(
690+
"""
691+
CREATE TABLE pk_uc_table (
692+
pk int PRIMARY KEY,
693+
uc_1 int,
694+
uc_2 int,
695+
CONSTRAINT constraint_pk_uc_table UNIQUE(uc_1,uc_2) )
696+
"""
697+
)
698+
699+
def test_only_primary_key(self):
700+
catalog = test_utils.discover_catalog(self.conn, {})
701+
primary_keys = {}
702+
for c in catalog.streams:
703+
primary_keys[c.table] = (
704+
singer.metadata.to_map(c.metadata).get((), {}).get("table-key-properties")
705+
)
706+
707+
self.assertEqual(primary_keys["uc_only_table"], ["uc_1","uc_2"])
708+
self.assertEqual(primary_keys["pk_only_table"], ["pk"])
709+
self.assertEqual(primary_keys["pk_uc_table"], ["pk"])
653710

654711
if __name__ == "__main__":
655712
# test1 = TestBinlogReplication()

0 commit comments

Comments
 (0)