<s> from __future__ import absolute_import , unicode_literals <EOL> import mock <EOL> import logging <EOL> from django . test import TestCase <EOL> from drivers import DriverFactory <EOL> from physical . tests import factory as factory_physical <EOL> from logical . tests import factory as factory_logical <EOL> from logical . models import Database <EOL> from . . mysqldb import MySQL <EOL> from django . conf import settings <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class AbstractTestDriverMysql ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . databaseinfra = factory_physical . DatabaseInfraFactory ( <EOL> user = "<STR_LIT:root>" , password = settings . DB_PASSWORD , endpoint = "<STR_LIT>" ) <EOL> self . instance = factory_physical . InstanceFactory ( <EOL> databaseinfra = self . databaseinfra , port = <NUM_LIT> ) <EOL> self . driver = MySQL ( databaseinfra = self . databaseinfra ) <EOL> self . _mysql_client = None <EOL> def tearDown ( self ) : <EOL> if not Database . objects . filter ( databaseinfra_id = self . databaseinfra . id ) : <EOL> self . databaseinfra . delete ( ) <EOL> if self . _mysql_client : <EOL> self . _mysql_client . close ( ) <EOL> self . driver = self . databaseinfra = self . _mysql_client = None <EOL> @ property <EOL> def mysql_client ( self ) : <EOL> if self . _mysql_client is None : <EOL> self . _mysql_client = self . driver . __mysql_client__ ( self . instance ) <EOL> return self . _mysql_client <EOL> class MySQLEngineTestCase ( AbstractTestDriverMysql ) : <EOL> """<STR_LIT>""" <EOL> def test_mysqldb_app_installed ( self ) : <EOL> self . assertTrue ( DriverFactory . is_driver_available ( "<STR_LIT>" ) ) <EOL> def test_instantiate_mysqldb_using_engine_factory ( self ) : <EOL> self . assertEqual ( MySQL , type ( self . driver ) ) <EOL> self . assertEqual ( self . databaseinfra , self . driver . databaseinfra ) <EOL> def test_connection_string ( self ) : <EOL> self . assertEqual ( <EOL> "<STR_LIT>" , self . driver . get_connection ( ) ) <EOL> def test_get_user ( self ) : <EOL> self . assertEqual ( self . databaseinfra . user , self . driver . get_user ( ) ) <EOL> def test_get_password ( self ) : <EOL> self . assertEqual ( <EOL> self . databaseinfra . password , self . driver . get_password ( ) ) <EOL> def test_get_default_port ( self ) : <EOL> self . assertEqual ( <NUM_LIT> , self . driver . default_port ) <EOL> def test_connection_with_database ( self ) : <EOL> self . database = factory_logical . DatabaseFactory ( <EOL> name = "<STR_LIT>" , databaseinfra = self . databaseinfra ) <EOL> self . assertEqual ( "<STR_LIT>" , <EOL> self . driver . get_connection ( database = self . database ) ) <EOL> class ManageDatabaseMySQLTestCase ( AbstractTestDriverMysql ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( ManageDatabaseMySQLTestCase , self ) . setUp ( ) <EOL> self . database = factory_logical . DatabaseFactory ( <EOL> databaseinfra = self . databaseinfra ) <EOL> driver = self . databaseinfra . get_driver ( ) <EOL> driver . remove_database ( self . database ) <EOL> def tearDown ( self ) : <EOL> if not Database . objects . filter ( databaseinfra_id = self . databaseinfra . id ) : <EOL> self . database . delete ( ) <EOL> super ( ManageDatabaseMySQLTestCase , self ) . tearDown ( ) <EOL> def test_mysqldb_create_and_drop_database ( self ) : <EOL> LOG . debug ( "<STR_LIT>" % type ( self . mysql_client ) ) <EOL> try : <EOL> self . driver . remove_database ( self . database ) <EOL> except : <EOL> pass <EOL> self . assertFalse ( self . database . name in self . driver . list_databases ( ) ) <EOL> self . driver . create_database ( self . database ) <EOL> self . assertTrue ( self . database . name in self . driver . list_databases ( ) ) <EOL> self . driver . remove_database ( self . database ) <EOL> self . assertFalse ( self . database . name in self . driver . list_databases ( ) ) <EOL> class ManageCredentialsMySQLTestCase ( AbstractTestDriverMysql ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( ManageCredentialsMySQLTestCase , self ) . setUp ( ) <EOL> self . database = factory_logical . DatabaseFactory ( <EOL> databaseinfra = self . databaseinfra , name = "<STR_LIT>" ) <EOL> try : <EOL> self . driver . remove_database ( self . database ) <EOL> except : <EOL> pass <EOL> self . credential = factory_logical . CredentialFactory ( <EOL> database = self . database ) <EOL> self . driver . create_database ( self . database ) <EOL> def tearDown ( self ) : <EOL> self . driver . remove_database ( self . database ) <EOL> self . credential . delete ( ) <EOL> self . database . delete ( ) <EOL> super ( ManageCredentialsMySQLTestCase , self ) . tearDown ( ) <EOL> def test_mysqldb_create__and_remove_credential ( self ) : <EOL> self . assertFalse ( self . credential . user in self . driver . list_users ( ) ) <EOL> self . driver . create_user ( self . credential ) <EOL> self . assertTrue ( self . credential . user in self . driver . list_users ( ) ) <EOL> self . driver . remove_user ( self . credential ) <EOL> self . assertFalse ( self . credential . user in self . driver . list_users ( ) ) </s>
