File size: 869 Bytes
065fee7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import typing
from test.conftest import _get_default_connection_args, conf

import pytest  # type: ignore

import redshift_connector


@pytest.fixture(scope="session", autouse=True)
def startup_db_stmts() -> None:
    """
    Executes a defined set of statements to configure a fresh Amazon Redshift cluster for IdP integration tests.
    """
    groups: typing.List[str] = conf.get("cluster-setup", "groups").split(sep=",")

    with redshift_connector.connect(**_get_default_connection_args()) as conn:  # type: ignore
        conn.autocommit = True
        with conn.cursor() as cursor:
            for grp in groups:
                try:
                    cursor.execute("DROP GROUP {}".format(grp))
                except:
                    pass  # we can't use IF EXISTS here, so ignore any error
                cursor.execute("CREATE GROUP {}".format(grp))