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


Python openedx_instance.OpenEdXInstanceFactory类代码示例

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


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

示例1: test_spawn_appserver_detailed

    def test_spawn_appserver_detailed(self, mocks):
        """
        Test spawning an AppServer in more detail; this is partially an integration test

        Unlike test_spawn_appserver(), this test does not mock the .provision() method, so the
        AppServer will go through the motions of provisioning and end up with the appropriate
        status.

        Note that OpenEdXInstance does not include auto-retry support or auto-activation upon
        success; those behaviors are implemented at the task level in tasks.py and tested in
        test_tasks.py
        """
        mocks.mock_create_server.side_effect = [Mock(id='test-run-provisioning-server'), None]
        mocks.os_server_manager.add_fixture('test-run-provisioning-server', 'openstack/api_server_2_active.json')

        instance = OpenEdXInstanceFactory(
            sub_domain='test.spawn',
            use_ephemeral_databases=True,
        )
        self.assertEqual(instance.appserver_set.count(), 0)
        self.assertIsNone(instance.active_appserver)
        appserver_id = instance.spawn_appserver()
        self.assertIsNotNone(appserver_id)
        self.assertEqual(instance.appserver_set.count(), 1)
        self.assertIsNone(instance.active_appserver)

        appserver = instance.appserver_set.get(pk=appserver_id)
        self.assertEqual(appserver.status, AppServerStatus.Running)
        self.assertEqual(appserver.server.status, Server.Status.Ready)
开发者ID:open-craft,项目名称:opencraft,代码行数:29,代码来源:test_openedx_instance.py

示例2: test_get_details

    def test_get_details(self):
        """
        GET - Detailed attributes
        """
        self.api_client.login(username='user3', password='pass')
        instance = OpenEdXInstanceFactory(sub_domain='domain.api')
        app_server = make_test_appserver(instance)
        instance.active_appserver = app_server  # Outside of tests, use set_appserver_active() instead
        instance.save()

        response = self.api_client.get('/api/v1/instance/{pk}/'.format(pk=instance.ref.pk))
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        instance_data = response.data.items()
        self.assertIn(('domain', 'domain.api.example.com'), instance_data)
        self.assertIn(('is_shut_down', False), instance_data)
        self.assertIn(('name', instance.name), instance_data)
        self.assertIn(('url', 'http://domain.api.example.com/'), instance_data)
        self.assertIn(('studio_url', 'http://studio-domain.api.example.com/'), instance_data)
        self.assertIn(
            ('edx_platform_repository_url', 'https://github.com/{}.git'.format(settings.DEFAULT_FORK)),
            instance_data
        )
        self.assertIn(('edx_platform_commit', 'master'), instance_data)
        # AppServer info:
        self.assertIn(('appserver_count', 1), instance_data)
        self.assertIn('active_appserver', response.data)
        self.assertIn('newest_appserver', response.data)
        for key in ('active_appserver', 'newest_appserver'):
            app_server_data = response.data[key]
            self.assertEqual(app_server_data['id'], app_server.pk)
            self.assertEqual(
                app_server_data['api_url'], 'http://testserver/api/v1/openedx_appserver/{pk}/'.format(pk=app_server.pk)
            )
            self.assertEqual(app_server_data['status'], 'new')
开发者ID:open-craft,项目名称:opencraft,代码行数:35,代码来源:test_openedx_instance.py

示例3: test_preliminary_page_not_configured

 def test_preliminary_page_not_configured(self):
     """
     Test that get_preliminary_page_config() returns an empty configuration if
     PRELIMINARY_PAGE_SERVER_IP is not set.
     """
     instance = OpenEdXInstanceFactory()
     self.assertEqual(instance.get_preliminary_page_config(instance.ref.pk), ([], []))
开发者ID:open-craft,项目名称:opencraft,代码行数:7,代码来源:test_load_balanced_mixin.py

示例4: test_terminate_obsolete_appservers_no_active

    def test_terminate_obsolete_appservers_no_active(self):
        """
        Test that `terminate_obsolete_appservers` does not terminate any app servers
        if an instance does not have an active app server.
        """
        instance = OpenEdXInstanceFactory()
        reference_date = timezone.now()

        # Create app servers
        obsolete_appserver = self._create_running_appserver(instance, reference_date - timedelta(days=5))
        obsolete_appserver_failed = self._create_failed_appserver(instance, reference_date - timedelta(days=5))

        recent_appserver = self._create_running_appserver(instance, reference_date - timedelta(days=1))
        recent_appserver_failed = self._create_failed_appserver(instance, reference_date - timedelta(days=1))

        appserver = self._create_running_appserver(instance, reference_date)
        appserver_failed = self._create_failed_appserver(instance, reference_date)

        newer_appserver = self._create_running_appserver(instance, reference_date + timedelta(days=3))
        newer_appserver_failed = self._create_failed_appserver(instance, reference_date + timedelta(days=3))

        # Terminate app servers
        instance.terminate_obsolete_appservers()

        # Check status of app servers (should be unchanged)
        self._assert_status([
            (obsolete_appserver, AppServerStatus.Running, ServerStatus.Pending),
            (obsolete_appserver_failed, AppServerStatus.ConfigurationFailed, ServerStatus.Pending),
            (recent_appserver, AppServerStatus.Running, ServerStatus.Pending),
            (recent_appserver_failed, AppServerStatus.ConfigurationFailed, ServerStatus.Pending),
            (appserver, AppServerStatus.Running, ServerStatus.Pending),
            (appserver_failed, AppServerStatus.ConfigurationFailed, ServerStatus.Pending),
            (newer_appserver, AppServerStatus.Running, ServerStatus.Pending),
            (newer_appserver_failed, AppServerStatus.ConfigurationFailed, ServerStatus.Pending),
        ])
开发者ID:open-craft,项目名称:opencraft,代码行数:35,代码来源:test_openedx_instance.py

示例5: test_enable_monitoring

    def test_enable_monitoring(self, mock_newrelic):
        """
        Check that the `enable_monitoring` method creates New Relic Synthetics
        monitors for each of the instance's public urls, and enables email
        alerts.
        """
        monitor_ids = [str(uuid4()) for i in range(3)]
        mock_newrelic.get_synthetics_monitors.return_value = []
        mock_newrelic.create_synthetics_monitor.side_effect = monitor_ids
        instance = OpenEdXInstanceFactory()
        instance.enable_monitoring()

        # Check that the monitors have been created
        mock_newrelic.delete_synthetics_monitor.assert_not_called()
        mock_newrelic.create_synthetics_monitor.assert_has_calls([
            call(instance.url),
            call(instance.studio_url),
            call(instance.lms_preview_url),
        ], any_order=True)
        self.assertCountEqual(
            instance.new_relic_availability_monitors.values_list('pk', flat=True),
            monitor_ids
        )

        # Check that alert emails have been set up
        mock_newrelic.add_synthetics_email_alerts.assert_has_calls([
            call(monitor_id, ['[email protected]'])
            for monitor_id in monitor_ids
        ], any_order=True)
开发者ID:open-craft,项目名称:opencraft,代码行数:29,代码来源:test_openedx_monitoring_mixins.py

示例6: test_delete_instance

    def test_delete_instance(self, mocks, delete_by_ref, *mock_methods):
        """
        Test that an instance can be deleted directly or by its InstanceReference.
        """
        instance = OpenEdXInstanceFactory(sub_domain='test.deletion', use_ephemeral_databases=True)
        instance_ref = instance.ref
        appserver = OpenEdXAppServer.objects.get(pk=instance.spawn_appserver())

        for method in mock_methods:
            self.assertEqual(
                method.call_count, 0,
                '{} should not have been called'.format(method._mock_name)
            )

        # Now delete the instance, either using InstanceReference or the OpenEdXInstance class:
        if delete_by_ref:
            instance_ref.delete()
        else:
            instance.delete()

        for method in mock_methods:
            self.assertEqual(
                method.call_count, 1,
                '{} should have been called exactly once'.format(method._mock_name)
            )

        with self.assertRaises(OpenEdXInstance.DoesNotExist):
            OpenEdXInstance.objects.get(pk=instance.pk)
        with self.assertRaises(InstanceReference.DoesNotExist):
            instance_ref.refresh_from_db()
        with self.assertRaises(OpenEdXAppServer.DoesNotExist):
            appserver.refresh_from_db()
开发者ID:open-craft,项目名称:opencraft,代码行数:32,代码来源:test_openedx_instance.py

示例7: test_swift_disabled

 def test_swift_disabled(self, create_swift_container):
     """
     Verify disabling Swift provisioning works.
     """
     instance = OpenEdXInstanceFactory(use_ephemeral_databases=False)
     instance.provision_swift()
     self.assertIs(instance.swift_provisioned, False)
     self.assertFalse(create_swift_container.called)
开发者ID:open-craft,项目名称:opencraft,代码行数:8,代码来源:test_openedx_storage_mixins.py

示例8: test_set_appserver_active

 def test_set_appserver_active(self, mocks, mock_enable_monitoring):
     """
     Check that monitoring is enabled when an appserver is activated.
     """
     instance = OpenEdXInstanceFactory()
     appserver_id = instance.spawn_appserver()
     instance.set_appserver_active(appserver_id)
     self.assertEqual(mock_enable_monitoring.call_count, 1)
开发者ID:open-craft,项目名称:opencraft,代码行数:8,代码来源:test_openedx_monitoring_mixins.py

示例9: test_instance_subdomain

 def test_instance_subdomain(self):
     """
     Subdomain used by an existing instance.
     """
     OpenEdXInstanceFactory.create(
         sub_domain=self.form_data['subdomain'],
     )
     self._assert_registration_fails(self.form_data, expected_errors={
         'subdomain': ['This domain is already taken.'],
     })
开发者ID:open-craft,项目名称:opencraft,代码行数:10,代码来源:test_views.py

示例10: make_test_appserver

def make_test_appserver(instance=None):
    """
    Factory method to create an OpenEdXAppServer (and OpenStackServer).
    """
    if not instance:
        instance = OpenEdXInstanceFactory()
    if not instance.load_balancing_server:
        instance.load_balancing_server = LoadBalancingServer.objects.select_random()
        instance.save()
    return instance._create_owned_appserver()
开发者ID:open-craft,项目名称:opencraft,代码行数:10,代码来源:openedx_appserver.py

示例11: test_ansible_s3_settings_ephemeral

 def test_ansible_s3_settings_ephemeral(self):
     """
     Test that get_storage_settings() does not include S3 vars when in ephemeral mode
     """
     instance = OpenEdXInstanceFactory(
         s3_access_key='test-s3-access-key',
         s3_secret_access_key='test-s3-secret-access-key',
         s3_bucket_name='test-s3-bucket-name',
         use_ephemeral_databases=True,
     )
     self.assertEqual(instance.get_storage_settings(), '')
开发者ID:open-craft,项目名称:opencraft,代码行数:11,代码来源:test_openedx_storage_mixins.py

示例12: test_domain_url

 def test_domain_url(self):
     """
     Domain and URL attributes
     """
     instance = OpenEdXInstanceFactory(
         internal_lms_domain='sample.example.org', name='Sample Instance'
     )
     internal_lms_domain = 'sample.example.org'
     internal_lms_preview_domain = 'preview-sample.example.org'
     internal_studio_domain = 'studio-sample.example.org'
     self.assertEqual(instance.internal_lms_domain, internal_lms_domain)
     self.assertEqual(instance.internal_lms_preview_domain, internal_lms_preview_domain)
     self.assertEqual(instance.internal_studio_domain, internal_studio_domain)
     # External domains are empty by default.
     self.assertEqual(instance.external_lms_domain, '')
     self.assertEqual(instance.external_lms_preview_domain, '')
     self.assertEqual(instance.external_studio_domain, '')
     # When external domain is empty, main domains/URLs equal internal domains.
     self.assertEqual(instance.domain, internal_lms_domain)
     self.assertEqual(instance.lms_preview_domain, internal_lms_preview_domain)
     self.assertEqual(instance.studio_domain, internal_studio_domain)
     self.assertEqual(instance.studio_domain_nginx_regex, r'~^(studio\-sample\.example\.org)$')
     self.assertEqual(instance.url, 'http://{}/'.format(internal_lms_domain))
     self.assertEqual(instance.lms_preview_url, 'http://{}/'.format(internal_lms_preview_domain))
     self.assertEqual(instance.studio_url, 'http://{}/'.format(internal_studio_domain))
     self.assertEqual(str(instance), 'Sample Instance (sample.example.org)')
     # External domains take precedence over internal domains.
     external_lms_domain = 'external.domain.com'
     external_lms_preview_domain = 'lms-preview.external.domain.com'
     external_studio_domain = 'external-studio.domain.com'
     instance.external_lms_domain = external_lms_domain
     instance.external_lms_preview_domain = external_lms_preview_domain
     instance.external_studio_domain = external_studio_domain
     # Internal domains are still the same.
     self.assertEqual(instance.internal_lms_domain, internal_lms_domain)
     self.assertEqual(instance.internal_lms_preview_domain, internal_lms_preview_domain)
     self.assertEqual(instance.internal_studio_domain, internal_studio_domain)
     # Default domains will now equal external domains.
     self.assertEqual(instance.domain, external_lms_domain)
     self.assertEqual(instance.lms_preview_domain, external_lms_preview_domain)
     self.assertEqual(instance.studio_domain, external_studio_domain)
     self.assertEqual(
         instance.studio_domain_nginx_regex,
         r'~^(external\-studio\.domain\.com|studio\-sample\.example\.org)$'
     )
     self.assertEqual(instance.url, 'http://{}/'.format(external_lms_domain))
     self.assertEqual(instance.lms_preview_url, 'http://{}/'.format(external_lms_preview_domain))
     self.assertEqual(instance.studio_url, 'http://{}/'.format(external_studio_domain))
     self.assertEqual(str(instance), 'Sample Instance (external.domain.com)')
     # URLs respect the protocol setting.
     instance.protocol = 'https'
     self.assertEqual(instance.url, 'https://{}/'.format(external_lms_domain))
     self.assertEqual(instance.lms_preview_url, 'https://{}/'.format(external_lms_preview_domain))
     self.assertEqual(instance.studio_url, 'https://{}/'.format(external_studio_domain))
开发者ID:open-craft,项目名称:opencraft,代码行数:54,代码来源:test_openedx_instance.py

示例13: test_forum_api_key

 def test_forum_api_key(self, mocks, mock_provision):
     """
     Ensure the FORUM_API_KEY matches EDXAPP_COMMENTS_SERVICE_KEY
     """
     instance = OpenEdXInstanceFactory(sub_domain='test.forum_api_key', use_ephemeral_databases=True)
     appserver_id = instance.spawn_appserver()
     appserver = instance.appserver_set.get(pk=appserver_id)
     configuration_vars = yaml.load(appserver.configuration_settings)
     api_key = configuration_vars['EDXAPP_COMMENTS_SERVICE_KEY']
     self.assertIsNot(api_key, '')
     self.assertIsNotNone(api_key)
     self.assertEqual(configuration_vars['FORUM_API_KEY'], api_key)
开发者ID:open-craft,项目名称:opencraft,代码行数:12,代码来源:test_openedx_instance.py

示例14: test_spawn_appserver_with_lms_users

 def test_spawn_appserver_with_lms_users(self, mocks, mock_provision):
     """
     Provision an AppServer with a user added to lms_users.
     """
     instance = OpenEdXInstanceFactory(sub_domain='test.spawn', use_ephemeral_databases=True)
     user = get_user_model().objects.create_user(username='test', email='[email protected]')
     instance.lms_users.add(user)
     appserver_id = instance.spawn_appserver()
     appserver = instance.appserver_set.get(pk=appserver_id)
     self.assertEqual(appserver.lms_users.count(), 1)
     self.assertEqual(appserver.lms_users.get(), user)
     self.assertTrue(appserver.lms_user_settings)
开发者ID:open-craft,项目名称:opencraft,代码行数:12,代码来源:test_openedx_instance.py

示例15: test_provision_swift

    def test_provision_swift(self, create_swift_container):
        """
        Test provisioning Swift containers, and that they are provisioned only once.
        """
        instance = OpenEdXInstanceFactory(use_ephemeral_databases=False)
        instance.provision_swift()
        self.check_swift(instance, create_swift_container)

        # Provision again without resetting the mock.  The assertCountEqual assertion will verify
        # that the container isn't provisioned again.
        instance.provision_swift()
        self.check_swift(instance, create_swift_container)
开发者ID:open-craft,项目名称:opencraft,代码行数:12,代码来源:test_openedx_storage_mixins.py


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