Skip to content

Commit 4f2370b

Browse files
committed
fixed test logic
1 parent f0277ca commit 4f2370b

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

.github/workflows/integration-tests-sqlserver.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ jobs:
4040
- name: Install dependencies
4141
run: pip install -r dev_requirements.txt
4242

43-
- name: Setup secondary db
44-
run: /bin/bash ./devops/scripts/init_db.sh
45-
4643
- name: Run functional tests
4744
run: pytest -ra -v tests/functional --profile "ci_sql_server"
4845
env:

devops/scripts/init_db.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ fi
77
for i in {1..50};
88
do
99
/opt/mssql-tools/bin/sqlcmd -C -S localhost -U sa -P "${SA_PASSWORD}" -d master -I -Q "CREATE DATABASE TestDB COLLATE ${COLLATION}"
10-
/opt/mssql-tools/bin/sqlcmd -C -S localhost -U sa -P "${SA_PASSWORD}" -d master -I -Q "CREATE DATABASE TestDB_Secondary COLLATE ${COLLATION}"
1110
if [ $? -eq 0 ]
1211
then
1312
echo "database creation completed"

tests/functional/adapter/mssql/test_cross_db.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
{{
88
config(
9-
target_database='TestDB_Secondary',
9+
target_database='secondary_db',
1010
target_schema='dbo',
1111
unique_key='id',
1212
@@ -37,6 +37,31 @@
3737

3838

3939
class TestCrossDB:
40+
def create_secondary_db(self, project):
41+
create_sql = """
42+
DECLARE @col NVARCHAR(256)
43+
SET @col = (SELECT CONVERT (varchar(256), SERVERPROPERTY('collation')));
44+
45+
IF NOT EXISTS (SELECT * FROM sys.databases WHERE name='secondary_db')
46+
BEGIN
47+
EXEC ('CREATE DATABASE secondary_db COLLATE ' + @col)
48+
END
49+
"""
50+
51+
with get_connection(project.adapter):
52+
project.adapter.execute(
53+
create_sql.format(database=project.database),
54+
fetch=True,
55+
)
56+
57+
def cleanup_secondary_database(self, project):
58+
drop_sql = "DROP DATABASE IF EXISTS secondary_db"
59+
with get_connection(project.adapter):
60+
project.adapter.execute(
61+
drop_sql.format(database=project.database),
62+
fetch=True,
63+
)
64+
4065
def cleanup_primary_table(self, project):
4166
drop_sql = "DROP TABLE IF EXISTS {database}.mysource.claims"
4267
with get_connection(project.adapter):
@@ -98,7 +123,7 @@ def create_primary_table(self, project):
98123

99124
def create_secondary_schema(self, project):
100125
src_query = """
101-
USE [TestDB_Secondary]
126+
USE [secondary_db]
102127
EXEC ('CREATE SCHEMA {schema}')
103128
"""
104129
with get_connection(project.adapter):
@@ -130,12 +155,16 @@ def snapshots(self):
130155
return {"claims_snapshot.sql": snapshot_sql}
131156

132157
def test_cross_db_snapshot(self, project):
158+
self.create_secondary_db(project)
159+
133160
self.cleanup_primary_table(project)
134161
self.cleanup_snapshot_table(project)
135162

136163
self.create_source_schema(project)
137164
self.create_primary_table(project)
138-
# self.create_secondary_schema(project)
139165
run_dbt(["snapshot"])
140166
self.update_primary_table(project)
141167
run_dbt(["snapshot"])
168+
169+
self.cleanup_snapshot_table(project)
170+
self.cleanup_secondary_database(project)

0 commit comments

Comments
 (0)