Example #1
0
    def test(self):
        user = User(pk=1)
        value = dict(
            spam='ham',
            xzsf='sdf',
        )

        self.assertRaises(
            UserSetting.DoesNotExist,
            UserSetting.objects.get,
            user=user,
            name='simple',
        )

        self.assertEqual(getsetting(user, self.settingname), None)
        self.assertEqual(getsettings(user)[self.settingname], None)
        self.assertEqual(getsettings(user, [self.settingname]), {self.settingname: None})
        self.assertEqual(getsettings(user, ['nonexisting_setting']), {})

        setsetting(user, self.settingname, value)
        self.assertEqual(getsettings(user)[self.settingname], value)
        self.assertEqual(getsettings(user, [self.settingname]), {self.settingname: value})
        self.assertEqual(getsettings(user, ['nonexisting_setting']), {})

        setsetting(user, self.settingname, None)
        self.assertEqual(getsetting(user, self.settingname), None)
        self.assertEqual(getsettings(user)[self.settingname], None)
        self.assertEqual(getsettings(user, [self.settingname]), {self.settingname: None})
        self.assertEqual(getsettings(user, ['nonexisting_setting']), {})

        self.assertRaises(
            UserSetting.DoesNotExist,
            UserSetting.objects.get,
            user=user,
            name='simple',
        )
Example #2
0
    def test(self):
        user = User(pk=1)

        self.assertRaises(
            UserSetting.DoesNotExist,
            UserSetting.objects.get,
            user=user,
            name='simple',
        )

        self.assertEqual(getsetting(user, self.settingname), None)
        self.assertEqual(getsettings(user)[self.settingname], None)
        self.assertEqual(getsettings(user, [self.settingname]), {self.settingname: None})
        self.assertEqual(getsettings(user, ['nonexisting_setting']), {})

        setsetting(user, self.settingname, 'testvalue')
        self.assertEqual(getsettings(user)[self.settingname], 'testvalue')
        self.assertEqual(getsettings(user, [self.settingname]), {self.settingname: 'testvalue'})
        self.assertEqual(getsettings(user, ['nonexisting_setting']), {})

        self.assertEqual(UserSetting.objects.get(
            user=user,
            name=self.settingname,
        ).value, 'testvalue')

        setsetting(user, self.settingname, None)
        self.assertEqual(getsetting(user, self.settingname), None)
        self.assertEqual(getsettings(user)[self.settingname], None)
        self.assertEqual(getsettings(user, [self.settingname]), {self.settingname: None})
        self.assertEqual(getsettings(user, ['nonexisting_setting']), {})

        setsettings(user, {self.settingname: 'testvalue2'})
        self.assertEqual(getsettings(user)[self.settingname], 'testvalue2')
        self.assertEqual(getsettings(user, [self.settingname]), {self.settingname: 'testvalue2'})
        self.assertEqual(getsettings(user, ['nonexisting_setting']), {})

        self.assertEqual(UserSetting.objects.get(
            user=user,
            name=self.settingname,
        ).value, 'testvalue2')

        setsetting(user, self.settingname, None)
        self.assertEqual(getsetting(user, self.settingname), None)
        self.assertEqual(getsettings(user)[self.settingname], None)
        self.assertEqual(getsettings(user, [self.settingname]), {self.settingname: None})
        self.assertEqual(getsettings(user, ['nonexisting_setting']), {})

        self.assertRaises(
            UserSetting.DoesNotExist,
            UserSetting.objects.get,
            user=user,
            name='simple',
        )