本文整理汇总了Python中instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory._get_mysql_user_name方法的典型用法代码示例。如果您正苦于以下问题:Python OpenEdXInstanceFactory._get_mysql_user_name方法的具体用法?Python OpenEdXInstanceFactory._get_mysql_user_name怎么用?Python OpenEdXInstanceFactory._get_mysql_user_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory
的用法示例。
在下文中一共展示了OpenEdXInstanceFactory._get_mysql_user_name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MySQLInstanceTestCase
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import _get_mysql_user_name [as 别名]
class MySQLInstanceTestCase(TestCase):
"""
Test cases for MySQLInstanceMixin and OpenEdXDatabaseMixin
"""
def setUp(self):
super().setUp()
self.instance = None
def tearDown(self):
if self.instance:
self.instance.deprovision_mysql()
super().tearDown()
def _assert_privileges(self, database):
"""
Assert that relevant users can access database
"""
database_name = database["name"]
user = database["user"]
additional_users = [user["name"] for user in database.get("additional_users", [])]
global_users = [self.instance.migrate_user, self.instance.read_only_user]
users = [user] + additional_users + global_users
for user in users:
password = self.instance._get_mysql_pass(user)
# Pass password using MYSQL_PWD environment variable rather than the --password
# parameter so that mysql command doesn't print a security warning.
env = {'MYSQL_PWD': password}
mysql_cmd = "mysql -u {user} -e 'SHOW TABLES' {db_name}".format(user=user, db_name=database_name)
tables = subprocess.call(mysql_cmd, shell=True, env=env)
self.assertEqual(tables, 0)
def check_mysql(self):
"""
Check that the mysql databases and users have been created
"""
self.assertIs(self.instance.mysql_provisioned, True)
self.assertTrue(self.instance.mysql_user)
self.assertTrue(self.instance.mysql_pass)
databases = subprocess.check_output("mysql -u root -e 'SHOW DATABASES'", shell=True).decode()
for database in self.instance.mysql_databases:
# Check if database exists
database_name = database["name"]
self.assertIn(database_name, databases)
# Check if relevant users can access it
self._assert_privileges(database)
def check_mysql_vars_not_set(self, instance):
"""
Check that the given instance does not point to a mysql database
"""
db_vars_str = instance.get_database_settings()
for var in ('EDXAPP_MYSQL_USER',
'EDXAPP_MYSQL_PASSWORD',
'EDXAPP_MYSQL_HOST',
'EDXAPP_MYSQL_PORT',
'EDXAPP_MYSQL_DB_NAME',
'COMMON_MYSQL_MIGRATE_USER',
'COMMON_MYSQL_MIGRATE_PASS'):
self.assertNotIn(var, db_vars_str)
def check_common_users(self, instance, db_vars):
"""
Check that instance settings contain correct information about common users.
"""
self.assertEqual(db_vars['COMMON_MYSQL_MIGRATE_USER'], instance.migrate_user)
self.assertEqual(db_vars['COMMON_MYSQL_MIGRATE_PASS'], instance._get_mysql_pass(instance.migrate_user))
self.assertEqual(db_vars['COMMON_MYSQL_READ_ONLY_USER'], instance.read_only_user)
self.assertEqual(db_vars['COMMON_MYSQL_READ_ONLY_PASS'], instance._get_mysql_pass(instance.read_only_user))
self.assertEqual(db_vars['COMMON_MYSQL_ADMIN_USER'], instance.admin_user)
self.assertEqual(db_vars['COMMON_MYSQL_ADMIN_PASS'], instance._get_mysql_pass(instance.admin_user))
def check_vars(self, instance, db_vars, prefix, var_names=None, values=None):
"""
Check that instance settings contain correct values for vars that start with prefix.
"""
if var_names is None:
var_names = ["DB_NAME", "USER", "PASSWORD", "HOST", "PORT"]
instance_settings = zip(var_names, values)
for var_name, value in instance_settings:
var_name = prefix + var_name
self.assertEqual(db_vars[var_name], value)
def test__get_mysql_database_name(self):
"""
Test that _get_mysql_database_name correctly builds database names.
"""
self.instance = OpenEdXInstanceFactory()
# Database name should be a combination of database_name and custom suffix
suffix = "test"
database_name = self.instance._get_mysql_database_name(suffix)
expected_database_name = "{0}_{1}".format(self.instance.database_name, suffix)
self.assertEqual(database_name, expected_database_name)
# Using suffix that exceeds maximum length should raise an error
suffix = "long-long-long-long-long-long-long-long-long-long-long-long-suffix"
with self.assertRaises(AssertionError):
self.instance._get_mysql_database_name(suffix)
def test__get_mysql_user_name(self):
#.........这里部分代码省略.........