distil/tests/__init__.py
adriant ab75581297 Changes to the config system.
This patch addresses issues with the need for a global config.
Now any module needing config access can simply import the config module.
To facilitate this there were a lot of minor changes to config use throughout artifice,
as well as changes to classes that were passed a config on creation.
Also some changes to constants so that the new config system can work with them easier.

Change-Id: I6e9b4cbf0ff30683dc13e37f13334f7ed7ee7add
2014-04-02 15:55:00 +13:00

41 lines
1.4 KiB
Python

import subprocess
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session,create_session
from sqlalchemy.pool import NullPool
from artifice.models import Resource, Tenant, UsageEntry, SalesOrder, Base
from artifice import config
from .constants import DATABASE_NAME, PG_DATABASE_URI, MY_DATABASE_URI
from .constants import config as test_config
def setUp():
subprocess.call(["/usr/bin/createdb","%s" % DATABASE_NAME])
subprocess.call(["mysql", "-u", "root","--password=password", "-e", "CREATE DATABASE %s" % DATABASE_NAME])
mysql_engine = create_engine(MY_DATABASE_URI, poolclass=NullPool)
pg_engine = create_engine(PG_DATABASE_URI, poolclass=NullPool)
Base.metadata.create_all(bind=mysql_engine)
Base.metadata.create_all(bind=pg_engine)
mysql_engine.dispose()
pg_engine.dispose()
# setup test config:
config.setup_config(test_config)
def tearDown():
mysql_engine = create_engine(MY_DATABASE_URI, poolclass=NullPool)
pg_engine = create_engine(PG_DATABASE_URI, poolclass=NullPool)
Base.metadata.drop_all(bind=mysql_engine)
Base.metadata.drop_all(bind=pg_engine)
mysql_engine.dispose()
pg_engine.dispose()
subprocess.call(["/usr/bin/dropdb","%s" % DATABASE_NAME])
subprocess.call(["mysql", "-u", "root", "--password=password", "-e", "DROP DATABASE %s" % DATABASE_NAME])