本文整理汇总了Python中system.models.Configuration.save方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.save方法的具体用法?Python Configuration.save怎么用?Python Configuration.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类system.models.Configuration
的用法示例。
在下文中一共展示了Configuration.save方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MakeDatabaseBackup
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import save [as 别名]
class MakeDatabaseBackup(TestCase):
def setUp(self):
cache.clear()
self.admin = SnapshotAdmin(Snapshot, admin.sites.AdminSite())
self.param_backup_available = Configuration(
name='backup_available', value=1
)
self.param_backup_available.save()
def tearDown(self):
if self.param_backup_available.id:
self.param_backup_available.delete()
def test_is_backup_available(self):
self.assertTrue(self.admin.is_backup_available)
def test_is_backup_disable(self):
self.param_backup_available.value = 0
self.param_backup_available.save()
self.assertFalse(self.admin.is_backup_available)
def test_is_backup_disable_not_configured(self):
self.param_backup_available.delete()
self.assertFalse(self.admin.is_backup_available)
示例2: PhysicalErrorsTestCase
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import save [as 别名]
class PhysicalErrorsTestCase(TestCase):
def setUp(self):
self.auto_resize_max_size_in_gb = Configuration(
name='auto_resize_max_size_in_gb', value=100
)
self.auto_resize_max_size_in_gb.save()
def tearDown(self):
self.auto_resize_max_size_in_gb.delete()
def test_no_disk_offering(self):
size = 123
typo = 'testing'
message = 'No disk offering {} than {}kb'.format(typo, size)
no_disk_offering = NoDiskOfferingError(typo=typo, size=size)
self.assertEqual(no_disk_offering.message, message)
def test_no_disk_offering_lesser(self):
size = 456
message = 'No disk offering lesser than {}kb'.format(size)
no_disk_offering = NoDiskOfferingLesserError(size=size)
self.assertEqual(no_disk_offering.message, message)
def test_no_disk_offering_greater(self):
size = 789
message = 'No disk offering greater than {}kb'.format(size)
no_disk_offering = NoDiskOfferingGreaterError(size=size)
self.assertEqual(no_disk_offering.message, message)
def test_disk_auto_resize_max_value(self):
message = 'Disk auto resize can not be greater than {}GB'.format(
self.auto_resize_max_size_in_gb.value
)
no_disk_offering = DiskOfferingMaxAutoResize()
self.assertEqual(no_disk_offering.message, message)
示例3: BaseTestCase
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import save [as 别名]
class BaseTestCase(object):
engine_name = ''
port = None
replication_topology_class_path = None
instance_helper = InstanceHelper
instance_quantity = 1
instance_type = 1
def setUp(self):
self.team = TeamFactory()
self.threshold_database_notification = Configuration(
name='threshold_database_notification', value=70,
description='Threshold infra notification'
)
self.threshold_database_notification.save()
self.new_user_notify_email = Configuration(
name='new_user_notify_email', value='[email protected]',
description='New user notify e-mail'
)
self.new_user_notify_email.save()
self.database_big = DatabaseFactory(
databaseinfra__engine__engine_type__name=self.engine_name,
)
self.database_big.team = self.team
self.database_big.save()
self.infra_big = self.database_big.databaseinfra
self.infra_big.plan.replication_topology.class_path = self.replication_topology_class_path
self.infra_big.plan.replication_topology.save()
self.infra_big.save()
self.database_small = DatabaseFactory(
databaseinfra__engine__engine_type__name=self.engine_name
)
self.database_small.team = self.team
self.database_small.save()
self.infra_small = self.database_small.databaseinfra
self.infra_small.plan.replication_topology.class_path = self.replication_topology_class_path
self.infra_small.plan.replication_topology.save()
self.infra_small.save()
self.instance_helper.create_instances_by_quant(
qt=self.instance_quantity, infra=self.infra_big,
total_size_in_bytes=10000, used_size_in_bytes=9900,
port=self.port, instance_type=self.instance_type
)
self.instance_helper.create_instances_by_quant(
qt=self.instance_quantity, infra=self.infra_small,
total_size_in_bytes=10000, used_size_in_bytes=1900,
port=self.port, instance_type=self.instance_type
)
def test_team_can_receive_notification(self, check_master_mock):
database_notification_for_team(team=self.team)
self.assertEqual(len(mail.outbox), 2)
def test_team_do_not_want_receive_notification(self, check_master_mock):
self.database_big.subscribe_to_email_events = False
self.database_big.save()
database_notification_for_team(team=self.team)
self.assertEqual(len(mail.outbox), 0)
示例4: DiskOfferingTestCase
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import save [as 别名]
class DiskOfferingTestCase(TestCase):
def create_basic_disks(self):
for disk_offering in DiskOffering.objects.all():
for plan in disk_offering.plans.all():
plan.databaseinfras.all().delete()
disk_offering.plans.all().delete()
disk_offering.delete()
cache.clear()
self.bigger = DiskOfferingFactory()
self.bigger.size_kb *= 30
self.bigger.save()
self.medium = DiskOfferingFactory()
self.medium.size_kb *= 20
self.medium.save()
self.smaller = DiskOfferingFactory()
self.smaller.size_kb *= 10
self.smaller.save()
def setUp(self):
self.admin = DiskOfferingAdmin(DiskOffering, admin.sites.AdminSite())
self.auto_resize_max_size_in_gb = Configuration(
name='auto_resize_max_size_in_gb', value=100
)
self.auto_resize_max_size_in_gb.save()
def tearDown(self):
if self.auto_resize_max_size_in_gb.id:
self.auto_resize_max_size_in_gb.delete()
def test_search_fields(self):
self.assertEqual(SEARCH_FIELDS, self.admin.search_fields)
def test_list_fields(self):
self.assertEqual(LIST_FIELDS, self.admin.list_display)
def test_save_position(self):
self.assertEqual(SAVE_ON_TOP, self.admin.save_on_top)
def test_adding_gb_to_kb(self):
disk_offering_form = DiskOfferingForm(
data={
'name': 'disk_offering_small',
'size_gb': 0.5,
}
)
self.assertTrue(disk_offering_form.is_valid())
self.admin.save_model(
request=None, obj=disk_offering_form.instance,
form=disk_offering_form, change=None
)
disk_offering = DiskOffering.objects.get(name='disk_offering_small')
self.assertEqual(disk_offering.size_gb(), 0.5)
self.assertEqual(disk_offering.size_kb, 524288)
def test_editing_gb_to_kb(self):
disk_factory = DiskOfferingFactory()
disk_offering = DiskOffering.objects.get(pk=disk_factory.pk)
self.assertEqual(disk_offering.size_gb(), 1)
self.assertEqual(disk_offering.size_kb, 1048576)
disk_offering_form = DiskOfferingForm(
data={
'name': disk_offering.name,
'size_gb': 1.5,
},
instance=disk_offering
)
self.assertTrue(disk_offering_form.is_valid())
self.admin.save_model(
request=None, obj=disk_offering,
form=disk_offering_form, change=None
)
self.assertEqual(disk_offering.size_gb(), 1.5)
self.assertEqual(disk_offering.size_kb, 1572864)
def test_edit_initial_values(self):
disk_offering_form = DiskOfferingForm()
self.assertNotIn('name', disk_offering_form.initial)
self.assertIn('size_gb', disk_offering_form.initial)
self.assertIsNone(disk_offering_form.initial['size_gb'])
disk_factory = DiskOfferingFactory()
disk_offering = DiskOffering.objects.get(pk=disk_factory.pk)
disk_offering_form = DiskOfferingForm(instance=disk_offering)
self.assertEqual(
disk_offering_form.initial['name'], disk_offering.name
)
self.assertEqual(
disk_offering_form.initial['size_gb'], disk_offering.size_gb()
)
def test_model_sizes(self):
disk_factory = DiskOfferingFactory()
self.assertEqual(disk_factory.size_kb, 1048576)
#.........这里部分代码省略.........