def setUp(self):
        connection_string = 'sqlite:///:memory:'
        db_data = parse_db_url(connection_string)
        self.settings = {
            'out_of_order': False,
            'dry_run': False,
            'connection_string': connection_string,
            'run_for_new_db': True
        }
        if db_data['engine'] == 'mysql':
            import MySQLdb
            # create the test database
            db = connection_settings.pop('db')
            c = MySQLdb.connect(**connection_settings)
            c.cursor().execute('DROP DATABASE IF EXISTS %s' % db)
            c.cursor().execute('CREATE DATABASE %s' % db)
        if db_data['engine'] == 'postgres':
            import psycopg2
            # create the test database
            database = connection_settings['database']
            schema = connection_settings.pop('schema', None)

            if schema is None:
                c = psycopg2.connect(database='template1')
                c.set_isolation_level(0)
                cur = c.cursor()
                cur.execute('DROP DATABASE IF EXISTS %s' % database)
                cur.execute('CREATE DATABASE %s' % database)

            else:
                c = psycopg2.connect(**connection_settings)
                c.cursor().execute('DROP SCHEMA IF EXISTS %s CASCADE' % schema)
                c.cursor().execute('CREATE SCHEMA %s' % schema)
                c.commit()
 def test_sqlite_memory(self):
     url = 'sqlite:///:memory:'
     parts = parse_db_url(url)
     self.assertEqual(parts,
                      dict(engine='sqlite',
                           host=None,
                           port=None,
                           user=None,
                           password=None,
                           database=':memory:'))
 def test_postgres_url_parts(self):
     url = 'postgresql://*****:*****@hosthost:12345/dbname'
     parts = parse_db_url(url)
     self.assertEqual(parts,
                      dict(engine='postgresql',
                           host='hosthost',
                           port=12345,
                           user='******',
                           password='******',
                           database='dbname'))