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


Python OpenEdXInstanceFactory.provision_mongo方法代码示例

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


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

示例1: MongoDBInstanceTestCase

# 需要导入模块: from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.openedx_instance.OpenEdXInstanceFactory import provision_mongo [as 别名]
class MongoDBInstanceTestCase(TestCase):
    """
    Test cases for MongoDBInstanceMixin and OpenEdXDatabaseMixin
    """
    def setUp(self):
        super().setUp()
        self.instance = None

    def tearDown(self):
        if self.instance:
            self.instance.deprovision_mongo()
        super().tearDown()

    def check_mongo(self):
        """
        Check that the instance mongo user has access to the external mongo database
        """
        mongo = pymongo.MongoClient(settings.DEFAULT_INSTANCE_MONGO_URL)
        for database in self.instance.mongo_database_names:
            self.assertTrue(mongo[database].authenticate(self.instance.mongo_user, self.instance.mongo_pass))

    def check_mongo_vars_not_set(self, appserver):
        """
        Check that the given OpenEdXAppServer does not point to a mongo database
        """
        for var in ('EDXAPP_MONGO_USER',
                    'EDXAPP_MONGO_PASSWORD'
                    'EDXAPP_MONGO_HOSTS',
                    'EDXAPP_MONGO_PORT',
                    'EDXAPP_MONGO_DB_NAME',
                    'FORUM_MONGO_USER',
                    'FORUM_MONGO_PASSWORD',
                    'FORUM_MONGO_HOSTS',
                    'FORUM_MONGO_PORT',
                    'FORUM_MONGO_DATABASE'):
            self.assertNotIn(var, appserver.configuration_settings)

    @override_settings(DEFAULT_INSTANCE_MONGO_URL=None)
    def test_create_instance_no_default_mongo_url(self):
        """
        Test that creating an instance with persistent databases raises an exception
        if DEFAULT_INSTANCE_MONGO_URL not set.
        """
        with self.assertRaises(MongoDBServer.DoesNotExist):
            self.instance = OpenEdXInstanceFactory(use_ephemeral_databases=False)

    def test_provision_mongo(self):
        """
        Provision mongo databases
        """
        self.instance = OpenEdXInstanceFactory(use_ephemeral_databases=False)
        self.instance.provision_mongo()
        self.check_mongo()

    def test_provision_mongo_again(self):
        """
        Only create the databases once
        """
        self.instance = OpenEdXInstanceFactory(use_ephemeral_databases=False)
        self.instance.provision_mongo()
        self.assertIs(self.instance.mongo_provisioned, True)

        mongo_user = self.instance.mongo_user
        mongo_pass = self.instance.mongo_pass
        self.instance.provision_mongo()
        self.assertEqual(self.instance.mongo_user, mongo_user)
        self.assertEqual(self.instance.mongo_pass, mongo_pass)
        self.check_mongo()

    def test_provision_mongo_no_mongodb_server(self):
        """
        Don't provision a mongo database if instance has no MongoDB server
        """
        mongo = pymongo.MongoClient(settings.DEFAULT_INSTANCE_MONGO_URL)
        self.instance = OpenEdXInstanceFactory(use_ephemeral_databases=False)
        self.instance.mongodb_server = None
        self.instance.save()
        self.instance.provision_mongo()
        databases = mongo.database_names()
        for database in self.instance.mongo_database_names:
            self.assertNotIn(database, databases)

    @override_settings(DEFAULT_INSTANCE_MONGO_URL='mongodb://user:[email protected]')
    def test_ansible_settings_mongo(self):
        """
        Add mongo ansible vars if instance has a MongoDB server
        """
        self.instance = OpenEdXInstanceFactory(use_ephemeral_databases=False)
        appserver = make_test_appserver(self.instance)
        ansible_vars = appserver.configuration_settings
        self.assertIn('EDXAPP_MONGO_USER: {0}'.format(self.instance.mongo_user), ansible_vars)
        self.assertIn('EDXAPP_MONGO_PASSWORD: {0}'.format(self.instance.mongo_pass), ansible_vars)
        self.assertIn('EDXAPP_MONGO_HOSTS: [mongo.opencraft.com]', ansible_vars)
        self.assertIn('EDXAPP_MONGO_PORT: {0}'.format(MONGODB_SERVER_DEFAULT_PORT), ansible_vars)
        self.assertIn('EDXAPP_MONGO_DB_NAME: {0}'.format(self.instance.mongo_database_name), ansible_vars)
        self.assertIn('FORUM_MONGO_USER: {0}'.format(self.instance.mongo_user), ansible_vars)
        self.assertIn('FORUM_MONGO_PASSWORD: {0}'.format(self.instance.mongo_pass), ansible_vars)
        self.assertIn('FORUM_MONGO_HOSTS: [mongo.opencraft.com]', ansible_vars)
        self.assertIn('FORUM_MONGO_PORT: {0}'.format(MONGODB_SERVER_DEFAULT_PORT), ansible_vars)
        self.assertIn('FORUM_MONGO_DATABASE: {0}'.format(self.instance.forum_database_name), ansible_vars)
#.........这里部分代码省略.........
开发者ID:open-craft,项目名称:opencraft,代码行数:103,代码来源:test_openedx_database_mixins.py


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