Example #1
0
    def test_setting_lazy(self):
        """lazy settings work"""
        test_group = {
            'key':
            'test_group',
            'name':
            "Test settings",
            'description':
            "Those are test settings.",
            'settings': [
                {
                    'setting': 'fish_name',
                    'name': "Fish's name",
                    'value': "Greedy Eric",
                    'field_extra': {
                        'min_length': 2,
                        'max_length': 255,
                    },
                    'is_lazy': False,
                },
                {
                    'setting': 'lazy_fish_name',
                    'name': "Fish's name",
                    'value': "Lazy Eric",
                    'field_extra': {
                        'min_length': 2,
                        'max_length': 255,
                    },
                    'is_lazy': True,
                },
                {
                    'setting': 'lazy_empty_setting',
                    'name': "Fish's name",
                    'field_extra': {
                        'min_length': 2,
                        'max_length': 255,
                    },
                    'is_lazy': True,
                },
            ],
        }

        migrate_settings_group(apps, test_group)

        self.assertTrue(gateway.lazy_fish_name)
        self.assertTrue(db_settings.lazy_fish_name)

        self.assertTrue(gateway.lazy_fish_name)
        self.assertEqual(gateway.get_lazy_setting('lazy_fish_name'),
                         'Lazy Eric')
        self.assertTrue(db_settings.lazy_fish_name)
        self.assertEqual(db_settings.get_lazy_setting('lazy_fish_name'),
                         'Lazy Eric')

        self.assertTrue(gateway.lazy_empty_setting is None)
        self.assertTrue(db_settings.lazy_empty_setting is None)
        with self.assertRaises(ValueError):
            db_settings.get_lazy_setting('fish_name')
Example #2
0
    def test_setting_lazy(self):
        """lazy settings work"""
        test_group = {
            'key': 'test_group',
            'name': "Test settings",
            'description': "Those are test settings.",
            'settings': (
                {
                    'setting': 'fish_name',
                    'name': "Fish's name",
                    'value': "Greedy Eric",
                    'field_extra': {
                            'min_length': 2,
                            'max_length': 255
                        },
                    'is_lazy': False
                },
                {
                    'setting': 'lazy_fish_name',
                    'name': "Fish's name",
                    'value': "Lazy Eric",
                    'field_extra': {
                            'min_length': 2,
                            'max_length': 255
                        },
                    'is_lazy': True
                },
                {
                    'setting': 'lazy_empty_setting',
                    'name': "Fish's name",
                    'field_extra': {
                            'min_length': 2,
                            'max_length': 255
                        },
                    'is_lazy': True
                },
            )
        }

        migrate_settings_group(apps, test_group)

        self.assertTrue(gateway.lazy_fish_name)
        self.assertTrue(db_settings.lazy_fish_name)

        self.assertTrue(gateway.lazy_fish_name)
        self.assertEqual(
            gateway.get_lazy_setting('lazy_fish_name'), 'Lazy Eric')
        self.assertTrue(db_settings.lazy_fish_name)
        self.assertEqual(
            db_settings.get_lazy_setting('lazy_fish_name'), 'Lazy Eric')

        self.assertTrue(gateway.lazy_empty_setting is None)
        self.assertTrue(db_settings.lazy_empty_setting is None)
        with self.assertRaises(ValueError):
            db_settings.get_lazy_setting('fish_name')