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


Python Configuration.save方法代码示例

本文整理汇总了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)
开发者ID:globocom,项目名称:database-as-a-service,代码行数:28,代码来源:tests.py

示例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)
开发者ID:globocom,项目名称:database-as-a-service,代码行数:38,代码来源:test_errors.py

示例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)
开发者ID:globocom,项目名称:database-as-a-service,代码行数:67,代码来源:test_notification.py

示例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)
#.........这里部分代码省略.........
开发者ID:globocom,项目名称:database-as-a-service,代码行数:103,代码来源:test_disk_offering.py


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