Skip to content

Commit d6f69f6

Browse files
committed
refactor(tests): modify config for use with CI
1 parent 4926a6e commit d6f69f6

File tree

8 files changed

+97
-98
lines changed

8 files changed

+97
-98
lines changed

test/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
azure_browser_idp,
44
azure_idp,
55
idp_arg,
6+
jumpcloud_browser_idp,
67
jwt_azure_v2_idp,
78
jwt_google_idp,
89
okta_browser_idp,

test/integration/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
azure_browser_idp,
44
azure_idp,
55
idp_arg,
6+
jumpcloud_browser_idp,
67
jwt_azure_v2_idp,
78
jwt_google_idp,
89
okta_browser_idp,

test/integration/conftest.py

Lines changed: 48 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -24,167 +24,139 @@ def pytest_runtest_makereport(item, call):
2424
f.write(rep.longreprtext + "\n")
2525

2626

27-
@pytest.fixture(scope="class")
28-
def db_kwargs():
29-
db_connect = {
30-
"database": conf.get("database", "database"),
31-
"host": conf.get("database", "host"),
32-
"port": conf.getint("database", "port"),
33-
"user": conf.get("database", "user"),
34-
"password": conf.get("database", "password"),
35-
"ssl": conf.getboolean("database", "ssl"),
36-
"sslmode": conf.get("database", "sslmode"),
27+
def _get_default_connection_args():
28+
"""
29+
Helper function defining default database connection parameter values.
30+
Returns
31+
-------
32+
33+
"""
34+
return {
35+
"database": conf.get("ci-cluster", "database"),
36+
"host": conf.get("ci-cluster", "host"),
37+
"port": conf.getint("default-test", "port"),
38+
"user": conf.get("ci-cluster", "test_user"),
39+
"password": conf.get("ci-cluster", "test_password"),
40+
"ssl": conf.getboolean("default-test", "ssl"),
41+
"sslmode": conf.get("default-test", "sslmode"),
42+
"region": conf.get("ci-cluster", "region"),
43+
"cluster_identifier": conf.get("ci-cluster", "cluster_identifier"),
3744
}
3845

39-
return db_connect
46+
47+
@pytest.fixture(scope="class")
48+
def db_kwargs():
49+
return _get_default_connection_args()
4050

4151

4252
@pytest.fixture(scope="class")
4353
def okta_idp():
4454
db_connect = {
45-
"database": conf.get("database", "database"),
46-
"host": conf.get("database", "host"),
47-
"port": conf.getint("database", "port"),
48-
"db_user": conf.get("database", "user"),
49-
"ssl": conf.getboolean("database", "ssl"),
50-
"sslmode": conf.get("database", "sslmode"),
55+
"db_user": conf.get("ci-cluster", "test_user"),
5156
"password": conf.get("okta-idp", "password"),
5257
"iam": conf.getboolean("okta-idp", "iam"),
5358
"idp_host": conf.get("okta-idp", "idp_host"),
5459
"user": conf.get("okta-idp", "user"),
5560
"app_id": conf.get("okta-idp", "app_id"),
5661
"app_name": conf.get("okta-idp", "app_name"),
5762
"credentials_provider": conf.get("okta-idp", "credentials_provider"),
58-
"region": conf.get("okta-idp", "region"),
59-
"cluster_identifier": conf.get("okta-idp", "cluster_identifier"),
6063
}
61-
return db_connect
64+
return {**_get_default_connection_args(), **db_connect}
6265

6366

6467
@pytest.fixture(scope="class")
6568
def okta_browser_idp():
6669
db_connect = {
67-
"database": conf.get("database", "database"),
68-
"host": conf.get("database", "host"),
69-
"port": conf.getint("database", "port"),
70-
"db_user": conf.get("database", "user"),
71-
"ssl": conf.getboolean("database", "ssl"),
72-
"sslmode": conf.get("database", "sslmode"),
70+
"db_user": conf.get("ci-cluster", "test_user"),
7371
"password": conf.get("okta-browser-idp", "password"),
7472
"iam": conf.getboolean("okta-browser-idp", "iam"),
7573
"user": conf.get("okta-browser-idp", "user"),
7674
"credentials_provider": conf.get("okta-browser-idp", "credentials_provider"),
77-
"region": conf.get("okta-browser-idp", "region"),
78-
"cluster_identifier": conf.get("okta-browser-idp", "cluster_identifier"),
7975
"login_url": conf.get("okta-browser-idp", "login_url"),
8076
}
81-
return db_connect
77+
return {**_get_default_connection_args(), **db_connect}
8278

8379

8480
@pytest.fixture(scope="class")
8581
def azure_browser_idp():
8682
db_connect = {
87-
"database": conf.get("database", "database"),
88-
"host": conf.get("database", "host"),
89-
"port": conf.getint("database", "port"),
90-
"db_user": conf.get("database", "user"),
91-
"ssl": conf.getboolean("database", "ssl"),
92-
"sslmode": conf.get("database", "sslmode"),
83+
"db_user": conf.get("ci-cluster", "test_user"),
9384
"password": conf.get("azure-browser-idp", "password"),
9485
"iam": conf.getboolean("azure-browser-idp", "iam"),
9586
"user": conf.get("azure-browser-idp", "user"),
9687
"credentials_provider": conf.get("azure-browser-idp", "credentials_provider"),
97-
"region": conf.get("azure-browser-idp", "region"),
98-
"cluster_identifier": conf.get("azure-browser-idp", "cluster_identifier"),
9988
"idp_tenant": conf.get("azure-browser-idp", "idp_tenant"),
10089
"client_id": conf.get("azure-browser-idp", "client_id"),
10190
"client_secret": conf.get("azure-browser-idp", "client_secret"),
10291
}
103-
return db_connect
92+
return {**_get_default_connection_args(), **db_connect}
93+
94+
95+
@pytest.fixture(scope="class")
96+
def jumpcloud_browser_idp():
97+
db_connect = {
98+
"db_user": conf.get("ci-cluster", "test_user"),
99+
"password": conf.get("jumpcloud-browser-idp", "password"),
100+
"iam": conf.getboolean("jumpcloud-browser-idp", "iam"),
101+
"user": conf.get("jumpcloud-browser-idp", "user"),
102+
"credentials_provider": conf.get("jumpcloud-browser-idp", "credentials_provider"),
103+
"login_url": conf.get("jumpcloud-browser-idp", "login_url"),
104+
}
105+
return {**_get_default_connection_args(), **db_connect}
104106

105107

106108
@pytest.fixture(scope="class")
107109
def azure_idp():
108110
db_connect = {
109-
"database": conf.get("database", "database"),
110-
"host": conf.get("database", "host"),
111-
"port": conf.getint("database", "port"),
112-
"db_user": conf.get("database", "user"),
113-
"ssl": conf.getboolean("database", "ssl"),
114-
"sslmode": conf.get("database", "sslmode"),
111+
"db_user": conf.get("ci-cluster", "test_user"),
115112
"password": conf.get("azure-idp", "password"),
116113
"iam": conf.getboolean("azure-idp", "iam"),
117114
"user": conf.get("azure-idp", "user"),
118115
"credentials_provider": conf.get("azure-idp", "credentials_provider"),
119-
"region": conf.get("azure-idp", "region"),
120-
"cluster_identifier": conf.get("azure-idp", "cluster_identifier"),
121116
"idp_tenant": conf.get("azure-idp", "idp_tenant"),
122117
"client_id": conf.get("azure-idp", "client_id"),
123118
"client_secret": conf.get("azure-idp", "client_secret"),
124119
}
125-
return db_connect
120+
return {**_get_default_connection_args(), **db_connect}
126121

127122

128123
@pytest.fixture(scope="class")
129124
def adfs_idp():
130125
db_connect = {
131-
"database": conf.get("database", "database"),
132-
"host": conf.get("database", "host"),
133-
"port": conf.getint("database", "port"),
134-
"db_user": conf.get("database", "user"),
135-
"ssl": conf.getboolean("database", "ssl"),
136-
"sslmode": conf.get("database", "sslmode"),
126+
"db_user": conf.get("ci-cluster", "test_user"),
137127
"password": conf.get("adfs-idp", "password"),
138128
"iam": conf.getboolean("adfs-idp", "iam"),
139129
"user": conf.get("adfs-idp", "user"),
140130
"credentials_provider": conf.get("adfs-idp", "credentials_provider"),
141-
"region": conf.get("adfs-idp", "region"),
142-
"cluster_identifier": conf.get("adfs-idp", "cluster_identifier"),
143131
"idp_host": conf.get("adfs-idp", "idp_host"),
144132
}
145-
return db_connect
133+
return {**_get_default_connection_args(), **db_connect}
146134

147135

148136
@pytest.fixture(scope="class")
149137
def jwt_google_idp():
150138
db_connect = {
151-
"database": conf.get("database", "database"),
152-
"host": conf.get("database", "host"),
153-
"port": conf.getint("database", "port"),
154-
"db_user": conf.get("database", "user"),
155-
"ssl": conf.getboolean("database", "ssl"),
156-
"sslmode": conf.get("database", "sslmode"),
139+
"db_user": conf.get("ci-cluster", "test_user"),
157140
"iam": conf.getboolean("jwt-google-idp", "iam"),
158-
"user": conf.get("database", "user"),
159141
"password": conf.get("jwt-google-idp", "password"),
160142
"credentials_provider": conf.get("jwt-google-idp", "credentials_provider"),
161-
"region": conf.get("jwt-google-idp", "region"),
162-
"cluster_identifier": conf.get("jwt-google-idp", "cluster_identifier"),
163143
"web_identity_token": conf.get("jwt-google-idp", "web_identity_token"),
164144
"preferred_role": conf.get("jwt-google-idp", "preferred_role"),
165145
}
166-
return db_connect
146+
return {**_get_default_connection_args(), **db_connect}
167147

168148

169149
@pytest.fixture(scope="class")
170150
def jwt_azure_v2_idp():
171151
db_connect = {
172-
"database": conf.get("database", "database"),
173-
"host": conf.get("database", "host"),
174-
"port": conf.getint("database", "port"),
175-
"db_user": conf.get("database", "user"),
176-
"ssl": conf.getboolean("database", "ssl"),
177-
"sslmode": conf.get("database", "sslmode"),
152+
"db_user": conf.get("ci-cluster", "test_user"),
178153
"iam": conf.getboolean("jwt-azure-v2-idp", "iam"),
179-
"user": conf.get("database", "user"),
180154
"password": conf.get("jwt-azure-v2-idp", "password"),
181155
"credentials_provider": conf.get("jwt-azure-v2-idp", "credentials_provider"),
182-
"region": conf.get("jwt-azure-v2-idp", "region"),
183-
"cluster_identifier": conf.get("jwt-azure-v2-idp", "cluster_identifier"),
184156
"web_identity_token": conf.get("jwt-azure-v2-idp", "web_identity_token"),
185157
"preferred_role": conf.get("jwt-azure-v2-idp", "preferred_role"),
186158
}
187-
return db_connect
159+
return {**_get_default_connection_args(), **db_connect}
188160

189161

190162
@pytest.fixture

test/integration/datatype/_generate_test_datatype_tables.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,10 @@ def datatype_test_setup(conf) -> None:
377377
# execute test sql file
378378
os.system(
379379
"PGPASSWORD={password} psql --host={host} --port 5439 --user={user} --dbname={db} -f {file}".format(
380-
password=conf.get("database", "password"),
381-
host=conf.get("database", "host"),
382-
user=conf.get("database", "user"),
383-
db=conf.get("database", "database"),
380+
password=conf.get("ci-cluster", "password"),
381+
host=conf.get("ci-cluster", "host"),
382+
user=conf.get("ci-cluster", "test_user"),
383+
db=conf.get("ci-cluster", "database"),
384384
file=CREATE_FILE_PATH,
385385
)
386386
)
@@ -396,10 +396,10 @@ def datatype_test_teardown(conf) -> None:
396396

397397
os.system(
398398
"PGPASSWORD={password} psql --host={host} --port 5439 --user={user} --dbname={db} -f {file}".format(
399-
password=conf.get("database", "password"),
400-
host=conf.get("database", "host"),
401-
user=conf.get("database", "user"),
402-
db=conf.get("database", "database"),
399+
password=conf.get("ci-cluster", "password"),
400+
host=conf.get("ci-cluster", "host"),
401+
user=conf.get("ci-cluster", "test_user"),
402+
db=conf.get("ci-cluster", "database"),
403403
file=TEARDOWN_FILE_PATH,
404404
)
405405
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import typing
2+
from test.integration.conftest import _get_default_connection_args, conf
3+
4+
import pytest
5+
6+
import redshift_connector
7+
8+
9+
@pytest.fixture(scope="session", autouse=True)
10+
def startup_db_stmts():
11+
"""
12+
Executes a defined set of statements to configure a fresh Amazon Redshift cluster for IdP integration tests.
13+
"""
14+
groups: typing.List[str] = conf.get("cluster-setup", "groups").split(sep=",")
15+
16+
with redshift_connector.connect(**_get_default_connection_args()) as conn:
17+
conn.autocommit = True
18+
with conn.cursor() as cursor:
19+
for grp in groups:
20+
try:
21+
cursor.execute("DROP GROUP {}".format(grp))
22+
except:
23+
pass # we can't use IF EXISTS here, so ignore any error
24+
cursor.execute("CREATE GROUP {}".format(grp))

test/integration/test_connection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ def test_client_protocol_version_is_used(db_kwargs, _input):
194194

195195
def test_client_protocol_version_invalid_warns_user(db_kwargs):
196196
db_kwargs["client_protocol_version"] = max(ClientProtocolVersion.list()) + 1
197-
197+
del db_kwargs["region"]
198+
del db_kwargs["cluster_identifier"]
198199
with pytest.warns(UserWarning):
199200
redshift_connector.Connection(**db_kwargs)

test/integration/test_query.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def test_get_schemas(con):
266266
with con.cursor() as cursor:
267267
cursor.execute(
268268
"create schema IF NOT EXISTS schema_test1 authorization {awsuser}".format(
269-
awsuser=conf.get("database", "user")
269+
awsuser=conf.get("ci-cluster", "test_user")
270270
)
271271
)
272272
res = cursor.get_schemas(schema_pattern="schema_test1")
@@ -281,12 +281,12 @@ def test_get_primary_keys(con):
281281

282282
cursor.execute(
283283
"create schema IF NOT EXISTS schema_test1 authorization {awsuser}".format(
284-
awsuser=conf.get("database", "user")
284+
awsuser=conf.get("ci-cluster", "test_user")
285285
)
286286
)
287287
cursor.execute(
288288
"CREATE TABLE IF NOT EXISTS {database}.schema_test1.test_primary (f1 int primary key, f3 varchar(50) null)".format(
289-
database=conf.get("database", "database")
289+
database=conf.get("ci-cluster", "database")
290290
)
291291
)
292292
key = cursor.get_primary_keys(schema="schema_test1", table="test_primary")
@@ -301,12 +301,12 @@ def test_get_columns(con):
301301

302302
cursor.execute(
303303
"create schema IF NOT EXISTS schema_test1 authorization {awsuser}".format(
304-
awsuser=conf.get("database", "user")
304+
awsuser=conf.get("ci-cluster", "test_user")
305305
)
306306
)
307307
cursor.execute(
308308
"create table IF NOT EXISTS {database}.schema_test1.table_columns (bookname varchar, author varchar)".format(
309-
database=conf.get("database", "database")
309+
database=conf.get("ci-cluster", "database")
310310
)
311311
)
312312
columns = cursor.get_columns(schema_pattern="schema_test1", tablename_pattern="table_columns")
@@ -322,13 +322,13 @@ def test_get_tables(con):
322322

323323
cursor.execute(
324324
"create schema IF NOT EXISTS schema_test1 authorization {awsuser}".format(
325-
awsuser=conf.get("database", "user")
325+
awsuser=conf.get("ci-cluster", "test_user")
326326
)
327327
)
328328
num = len(cursor.get_tables(schema_pattern="schema_test1", types=["TABLE"]))
329329
cursor.execute(
330330
"create table IF NOT EXISTS {database}.schema_test1.book (bookname varchar, author varchar)".format(
331-
database=conf.get("database", "database")
331+
database=conf.get("ci-cluster", "database")
332332
)
333333
)
334334
new_num = len(cursor.get_tables(schema_pattern="schema_test1", types=["TABLE"]))

test/performance/performance.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
sql.close()
1717

1818
conn: redshift_connector.Connection = redshift_connector.connect(
19-
database=conf.get("database", "database"),
20-
host=conf.get("database", "host"),
21-
port=conf.getint("database", "port"),
22-
user=conf.get("database", "user"),
23-
password=conf.get("database", "password"),
19+
database=conf.get("ci-cluster", "database"),
20+
host=conf.get("ci-cluster", "host"),
21+
port=conf.getint("default-test", "port"),
22+
user=conf.get("ci-cluster", "test_user"),
23+
password=conf.get("ci-cluster", "password"),
2424
ssl=True,
25-
sslmode=conf.get("database", "sslmode"),
25+
sslmode=conf.get("default-test", "sslmode"),
2626
iam=False,
2727
)
2828

0 commit comments

Comments
 (0)