Exemplo n.º 1
0
    def testMigration(self):
        from models import Setting

        # put in some old values
        self.policy.SetProbability(1)
        db.put([
            Setting(key_name='test', parent=None, value='old and busted'),
            Setting(key_name='another', parent=None,
                    value='another old value'),
        ])
        Setting._get_settings_dict(bust_cache=True)
        self.policy.SetProbability(0)

        self.assertEqual(Setting._get_or_set_with_key('test'),
                         'old and busted')
        self.assertEqual(Setting._get_or_set_with_key('another'),
                         'another old value')

        # simulate a write
        Setting._get_or_set_with_key('test', 'new hotness')

        # now assert that old and new style settings were updated
        old = Setting.get_by_key_name('test', parent=None)
        self.assertEqual(old.value, 'new hotness')
        new = Setting.get_by_key_name('test',
                                      parent=Setting.entity_group_key())
        self.assertEqual(new.value, 'new hotness')

        # finally, check the caching layers work too
        self.assertEqual(Setting._cache_get_by_key_name("test"), 'new hotness')
        self.assertEqual(Setting._get_or_set_with_key("another"),
                         'another old value')
Exemplo n.º 2
0
    def testMigration(self):
        from models import Setting

        # put in some old values
        self.policy.SetProbability(1)
        db.put(
            [
                Setting(key_name="test", parent=None, value="old and busted"),
                Setting(key_name="another", parent=None, value="another old value"),
            ]
        )
        Setting._get_settings_dict(bust_cache=True)
        self.policy.SetProbability(0)

        self.assertEqual(Setting._get_or_set_with_key("test"), "old and busted")
        self.assertEqual(Setting._get_or_set_with_key("another"), "another old value")

        # simulate a write
        Setting._get_or_set_with_key("test", "new hotness")

        # now assert that old and new style settings were updated
        old = Setting.get_by_key_name("test", parent=None)
        self.assertEqual(old.value, "new hotness")
        new = Setting.get_by_key_name("test", parent=Setting.entity_group_key())
        self.assertEqual(new.value, "new hotness")

        # finally, check the caching layers work too
        self.assertEqual(Setting._cache_get_by_key_name("test"), "new hotness")
        self.assertEqual(Setting._get_or_set_with_key("another"), "another old value")