当前位置: 首页>>代码示例>>Python>>正文


Python OpenEdXInstanceFactory._get_template_vars方法代码示例

本文整理汇总了Python中instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory._get_template_vars方法的典型用法代码示例。如果您正苦于以下问题:Python OpenEdXInstanceFactory._get_template_vars方法的具体用法?Python OpenEdXInstanceFactory._get_template_vars怎么用?Python OpenEdXInstanceFactory._get_template_vars使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory的用法示例。


在下文中一共展示了OpenEdXInstanceFactory._get_template_vars方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MySQLInstanceTestCase

# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import _get_template_vars [as 别名]

#.........这里部分代码省略.........
            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.
        """
        with self.assertRaises(MySQLServer.DoesNotExist):
            self.instance = OpenEdXInstanceFactory(use_ephemeral_databases=False)

    def test_provision_mysql(self):
        """
        Provision mysql database
        """
        self.instance = OpenEdXInstanceFactory(use_ephemeral_databases=False)
        self.instance.provision_mysql()
开发者ID:open-craft,项目名称:opencraft,代码行数:70,代码来源:test_openedx_database_mixins.py


注:本文中的instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory._get_template_vars方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。