def test_get_setting(self): """get_setting should get the setting from the database.""" widget = DummyWidget() setting = widget.get_setting('IS_ENABLED') self.assertEqual(setting, None, msg=( 'Should return None if the setting does not exist in the db')) widget.save_setting('IS_ENABLED', '1') setting = widget.get_setting('IS_ENABLED') self.assertEqual(setting.setting_name, 'IS_ENABLED', msg=( 'Should return the correct setting from the database when called'))
def test_save_setting(self): """save_setting should save the value to the database.""" widget = DummyWidget() setting = widget.save_setting('IS_ENABLED', '1') self.assertTrue(setting.pk, msg=( 'Should create a new DB entry when saving the setting for the' ' first time')) self.assertEqual(setting.value, '1', msg=( 'Should set the correct value on the new setting object')) setting2 = widget.save_setting('IS_ENABLED', '0') self.assertEqual(setting, setting2, msg=( 'Should not create a new object if that setting already exists' ' in the database')) self.assertEqual(setting2.value, '0', msg=( 'Should update the setting value on save'))