diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-07-25 18:33:04 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-07-25 18:33:04 -0400 |
commit | 9e6624c0496e22ec1139e0fb54cfefc14f660352 (patch) | |
tree | 673048a2c63d3f59b94fa1326c6b9adfb636bfe1 /lib/sqlalchemy/testing/plugin/provision.py | |
parent | fe878f5aff1cb17fdf1f13aba1d13f008da0ef4e (diff) | |
download | sqlalchemy-9e6624c0496e22ec1139e0fb54cfefc14f660352.tar.gz |
- proof of concept for parallel testing
Diffstat (limited to 'lib/sqlalchemy/testing/plugin/provision.py')
-rw-r--r-- | lib/sqlalchemy/testing/plugin/provision.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/sqlalchemy/testing/plugin/provision.py b/lib/sqlalchemy/testing/plugin/provision.py new file mode 100644 index 000000000..d665727f1 --- /dev/null +++ b/lib/sqlalchemy/testing/plugin/provision.py @@ -0,0 +1,62 @@ +from sqlalchemy.engine import url as sa_url + +def create_follower_db(follower_ident): + from .. import config, engines + + follower_ident = "test_%s" % follower_ident + + hosts = set() + + for cfg in config.Config.all_configs(): + url = cfg.db.url + backend = url.get_backend_name() + host_conf = ( + backend, + url.username, url.host, url.database) + + if host_conf not in hosts: + if backend.startswith("postgresql"): + _pg_create_db(cfg.db, follower_ident) + elif backend.startswith("mysql"): + _mysql_create_db(cfg.db, follower_ident) + + new_url = sa_url.make_url(str(url)) + + new_url.database = follower_ident + eng = engines.testing_engine(new_url, cfg.db_opts) + + if backend.startswith("postgresql"): + _pg_init_db(eng) + elif backend.startswith("mysql"): + _mysql_init_db(eng) + + hosts.add(host_conf) + + +def _pg_create_db(eng, ident): + with eng.connect().execution_options( + isolation_level="AUTOCOMMIT") as conn: + try: + conn.execute("DROP DATABASE %s" % ident) + except: + pass + conn.execute("CREATE DATABASE %s" % ident) + + +def _pg_init_db(eng): + with eng.connect() as conn: + conn.execute("CREATE SCHEMA test_schema") + conn.execute("CREATE SCHEMA test_schema_2") + + +def _mysql_create_db(eng, ident): + with eng.connect() as conn: + try: + conn.execute("DROP DATABASE %s" % ident) + except: + pass + conn.execute("CREATE DATABASE %s" % ident) + + +def _mysql_init_db(eng): + pass |