本文整理汇总了Python中instance.tests.models.factories.instance.OpenEdXInstanceFactory类的典型用法代码示例。如果您正苦于以下问题:Python OpenEdXInstanceFactory类的具体用法?Python OpenEdXInstanceFactory怎么用?Python OpenEdXInstanceFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OpenEdXInstanceFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ansible_settings_mysql_ephemeral
def test_ansible_settings_mysql_ephemeral(self):
"""
Don't add mysql ansible vars for ephemeral databases
"""
instance = OpenEdXInstanceFactory(use_ephemeral_databases=True)
instance.reset_ansible_settings()
self.check_mysql_vars_not_set(instance)
示例2: test_provision_failed_email
def test_provision_failed_email(self):
"""
Tests that provision_failed sends email when called from normal program flow
"""
instance = OpenEdXInstanceFactory(name='test', sub_domain='test')
reason = "something went wrong"
log_lines = ["log line1", "log_line2"]
instance.provision_failed_email(reason, log_lines)
expected_subject = OpenEdXInstance.EmailSubject.PROVISION_FAILED.format(
instance_name=instance.name, instance_url=instance.url
)
expected_recipients = [admin_tuple[1] for admin_tuple in settings.ADMINS]
self.assertEqual(len(django_mail.outbox), 1)
mail = django_mail.outbox[0]
self.assertIn(expected_subject, mail.subject)
self.assertIn(instance.name, mail.body)
self.assertIn(reason, mail.body)
self.assertEqual(mail.from_email, settings.SERVER_EMAIL)
self.assertEqual(mail.to, expected_recipients)
self.assertEqual(len(mail.attachments), 1)
self.assertEqual(mail.attachments[0], ("provision.log", "\n".join(log_lines), "text/plain"))
示例3: test_provision_failed_exception_email
def test_provision_failed_exception_email(self):
"""
Tests that provision_failed sends email when called from exception handler
"""
instance = OpenEdXInstanceFactory(name='exception_test', sub_domain='exception_test')
reason = "something went wrong"
log_lines = ["log line1", "log_line2"]
exception_message = "Something Bad happened Unexpectedly"
exception = Exception(exception_message)
try:
raise exception
except Exception: # pylint: disable=broad-except
instance.provision_failed_email(reason, log_lines)
expected_subject = OpenEdXInstance.EmailSubject.PROVISION_FAILED.format(
instance_name=instance.name, instance_url=instance.url
)
expected_recipients = [admin_tuple[1] for admin_tuple in settings.ADMINS]
self.assertEqual(len(django_mail.outbox), 1)
mail = django_mail.outbox[0]
self.assertIn(expected_subject, mail.subject)
self.assertIn(instance.name, mail.body)
self.assertIn(reason, mail.body)
self.assertEqual(mail.from_email, settings.SERVER_EMAIL)
self.assertEqual(mail.to, expected_recipients)
self.assertEqual(len(mail.attachments), 2)
self.assertEqual(mail.attachments[0], ("provision.log", "\n".join(log_lines), "text/plain"))
name, content, mime_type = mail.attachments[1]
self.assertEqual(name, "debug.html")
self.assertIn(exception_message, content)
self.assertEqual(mime_type, "text/html")
示例4: test_reset_ansible_settings
def test_reset_ansible_settings(self):
"""
Ansible vars as a string
"""
instance = OpenEdXInstanceFactory(
name='Vars Instance',
sub_domain='vars.test',
email='[email protected]',
github_organization_name='vars-org',
github_repository_name='vars-repo',
commit_id='9' * 40,
ansible_source_repo_url='http://example.org/config/repo',
configuration_version='test-config-ver',
forum_version='test-forum-ver',
notifier_version='test-notif-ver',
xqueue_version='test-xq-ver',
certs_version='test-cert-ver',
)
instance.reset_ansible_settings()
self.assertIn('EDXAPP_PLATFORM_NAME: "Vars Instance"', instance.ansible_settings)
self.assertIn("EDXAPP_SITE_NAME: 'vars.test.example.com", instance.ansible_settings)
self.assertIn("EDXAPP_CMS_SITE_NAME: 'studio.vars.test.example.com'", instance.ansible_settings)
self.assertIn("EDXAPP_CONTACT_EMAIL: '[email protected]'", instance.ansible_settings)
self.assertIn("edx_platform_repo: 'https://github.com/vars-org/vars-repo.git'", instance.ansible_settings)
self.assertIn("edx_platform_version: '{}'".format('9' * 40), instance.ansible_settings)
self.assertIn("edx_ansible_source_repo: 'http://example.org/config/repo'", instance.ansible_settings)
self.assertIn("configuration_version: 'test-config-ver'", instance.ansible_settings)
self.assertIn("forum_version: 'test-forum-ver'", instance.ansible_settings)
self.assertIn("notifier_version: 'test-notif-ver'", instance.ansible_settings)
self.assertIn("xqueue_version: 'test-xq-ver'", instance.ansible_settings)
self.assertIn("certs_version: 'test-cert-ver'", instance.ansible_settings)
示例5: test_provision_with_external_databases
def test_provision_with_external_databases(self, mocks):
"""
Run provisioning sequence, with external databases
"""
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='run.provisioning', use_ephemeral_databases=False)
def deploy():
"""
Make sure that ansible settings are present at deploy time
"""
ansible_settings = yaml.load(instance.ansible_settings)
for setting in ('EDXAPP_MYSQL_USER', 'EDXAPP_MONGO_PASSWORD',
'EDXAPP_MONGO_USER', 'EDXAPP_MONGO_PASSWORD',
'EDXAPP_SWIFT_USERNAME', 'EDXAPP_SWIFT_KEY'):
self.assertTrue(ansible_settings[setting])
return (['log'], 0)
mocks.mock_deploy.side_effect = deploy
instance.provision()
self.assertEqual(mocks.mock_provision_mysql.call_count, 1)
self.assertEqual(mocks.mock_provision_mongo.call_count, 1)
self.assertEqual(mocks.mock_provision_swift.call_count, 1)
示例6: test_ansible_settings_mongo_ephemeral
def test_ansible_settings_mongo_ephemeral(self):
"""
Don't add mongo ansible vars if INSTANCE_MONGO_URL is not set
"""
instance = OpenEdXInstanceFactory(use_ephemeral_databases=True)
instance.reset_ansible_settings()
self.check_mongo_vars_not_set(instance)
示例7: test_provision_no_active
def test_provision_no_active(self, os_server_manager, mock_deploy, mock_set_dns_record,
mock_server_reboot, mock_sleep, mock_update_status):
"""
Run provisioning sequence, with status jumping from 'started' to 'booted' (no 'active')
"""
mock_deploy.return_value = (['log'], 0)
instance = OpenEdXInstanceFactory(sub_domain='run.provisioning.noactive')
status_queue = [
OpenStackServer.STARTED,
OpenStackServer.BOOTED,
OpenStackServer.BOOTED,
OpenStackServer.PROVISIONING,
OpenStackServer.REBOOTING,
OpenStackServer.READY,
]
status_queue.reverse() # To be able to use pop()
def update_status(self, provisioning=False, rebooting=False, failed=None):
""" Simulate status progression successive runs """
self.status = status_queue.pop()
self.progress = self.PROGRESS_SUCCESS
mock_update_status.side_effect = update_status
with patch('instance.models.server.OpenStackServer.start'):
instance.provision()
self.assertEqual(mock_deploy.call_count, 1)
示例8: test_provision_mongo
def test_provision_mongo(self):
"""
Provision mongo databases
"""
instance = OpenEdXInstanceFactory(use_ephemeral_databases=False)
instance.provision_mongo()
self.check_mongo(instance)
示例9: test_provision_mysql
def test_provision_mysql(self):
"""
Provision mysql database
"""
instance = OpenEdXInstanceFactory(use_ephemeral_databases=False)
instance.provision_mysql()
self.check_mysql(instance)
示例10: test_ansible_settings_mysql_not_set
def test_ansible_settings_mysql_not_set(self):
"""
Don't add mysql ansible vars if INSTANCE_MYSQL_URL is not set
"""
instance = OpenEdXInstanceFactory(use_ephemeral_databases=False)
instance.reset_ansible_settings()
self.check_mysql_vars_not_set(instance)
示例11: test_set_to_branch_tip_replace_commit_hash
def test_set_to_branch_tip_replace_commit_hash(self, mock_get_commit_id_from_ref):
"""
The hash should be updated in the instance name when updating
"""
mock_get_commit_id_from_ref.return_value = '1234567' + 'd' * 33
instance = OpenEdXInstanceFactory(commit_id='a' * 40, name='Test Instance (aaaaaaa)')
instance.set_to_branch_tip(branch_name='new-branch', ref_type='tag')
self.assertEqual(instance.name, 'Test Instance (1234567)')
示例12: test_swift_disabled
def test_swift_disabled(self, mock_swift_connection):
"""
Verify disabling Swift provisioning works.
"""
instance = OpenEdXInstanceFactory(use_ephemeral_databases=False)
instance.provision_swift()
self.assertIs(instance.swift_provisioned, False)
self.assertFalse(mock_swift_connection.called)
示例13: test_commit_short_id
def test_commit_short_id(self):
"""
Short representation of a commit_id
"""
instance = OpenEdXInstanceFactory(commit_id='6e580ca9fed6fb65ec45949494dabec40e8cb533')
self.assertEqual(instance.commit_short_id, '6e580ca')
instance.commit_id = None
self.assertEqual(instance.commit_short_id, None)
示例14: test_github_admin_username_list_default
def test_github_admin_username_list_default(self):
"""
By default, no admin should be configured
"""
instance = OpenEdXInstanceFactory()
instance.reset_ansible_settings()
self.assertEqual(instance.github_admin_organization_name, '')
self.assertEqual(instance.github_admin_username_list, [])
self.assertNotIn('COMMON_USER_INFO', instance.ansible_settings)
示例15: test_provision_mysql_no_url
def test_provision_mysql_no_url(self):
"""
Don't provision a mysql database if INSTANCE_MYSQL_URL is not set
"""
instance = OpenEdXInstanceFactory(use_ephemeral_databases=False)
instance.provision_mysql()
databases = subprocess.check_output("mysql -u root -e 'SHOW DATABASES'", shell=True).decode()
for database in instance.mysql_database_names:
self.assertNotIn(database, databases)