本文整理汇总了Python中instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory._get_database_suffix方法的典型用法代码示例。如果您正苦于以下问题:Python OpenEdXInstanceFactory._get_database_suffix方法的具体用法?Python OpenEdXInstanceFactory._get_database_suffix怎么用?Python OpenEdXInstanceFactory._get_database_suffix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory
的用法示例。
在下文中一共展示了OpenEdXInstanceFactory._get_database_suffix方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MySQLInstanceTestCase
# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import _get_database_suffix [as 别名]
#.........这里部分代码省略.........
# User name should be a combination of mysql_user and custom suffix
suffix = "test"
user_name = self.instance._get_mysql_user_name(suffix)
expected_user_name = "{0}_{1}".format(self.instance.mysql_user, suffix)
self.assertEqual(user_name, expected_user_name)
# Using suffix that exceeds maximum length should raise an error
suffix = "long-long-long-suffix"
with self.assertRaises(AssertionError):
self.instance._get_mysql_user_name(suffix)
def test__get_mysql_pass(self):
"""
Test behavior of _get_mysql_pass.
It should:
- generate passwords of appropriate length
- generate different passwords for different users
- behave deterministically, i.e., return the same password for a given user
every time it is called with that user
"""
self.instance = OpenEdXInstanceFactory()
user1 = "user1"
pass1 = self.instance._get_mysql_pass(user1)
user2 = "user2"
pass2 = self.instance._get_mysql_pass(user2)
self.assertEqual(len(pass1), 64)
self.assertEqual(len(pass2), 64)
self.assertFalse(pass1 == pass2)
self.assertEqual(pass1, self.instance._get_mysql_pass(user1))
self.assertEqual(pass2, self.instance._get_mysql_pass(user2))
def test__get_database_suffix(self):
"""
Test that _get_database_suffix returns correct suffix for a given database.
"""
self.instance = OpenEdXInstanceFactory()
suffix = "test"
database_name = self.instance._get_mysql_database_name(suffix)
self.assertEqual(self.instance._get_database_suffix(database_name), suffix)
def test__get_template_vars(self):
"""
Test that _get_template_vars returns correct settings for a given database.
"""
self.instance = OpenEdXInstanceFactory()
suffix = "test-db"
database = {
"name": self.instance._get_mysql_database_name(suffix),
"user": self.instance._get_mysql_user_name(suffix),
}
template_vars = self.instance._get_template_vars(database)
expected_template_vars = {
"{}_database".format(suffix): database["name"],
"{}_user".format(suffix): database["user"],
"{}_pass".format(suffix): self.instance._get_mysql_pass(database["user"])
}
self.assertEqual(template_vars, expected_template_vars)
@override_settings(DEFAULT_INSTANCE_MYSQL_URL=None)
def test_create_instance_no_default_mysql_url(self):
"""
Test that creating an instance with persistent databases raises an exception
if DEFAULT_INSTANCE_MYSQL_URL not set.
"""