def test_osmcprefs_setget_all_types(self): for value in ['True', '1234', '1.01', 'None']: with FreshDatabase() as db: self.assertEqual(osmcprefs(*['osmc_setprefs', 'a', str(value)]), 'Set "a" to "%s"' % value) self.assertEqual(osmcprefs(*['osmc_getprefs', 'a']), str(value))
def test_osmcprefs_setprefs_success(self): with FreshDatabase() as db: self.assertEqual(osmcprefs(*['osmc_setprefs', 'mykey', 'myvalue']), 'Set "mykey" to "myvalue"') self.assertEqual(db.getsetting('mykey'), 'myvalue')
def test_osmcprefs_setprefs_toomany_args(self): # the function should just ignore the extra arguments with FreshDatabase() as db: self.assertEqual(osmcprefs(*['osmc_setprefs', 'mykey', 'myvalue', 'extra']), 'Set "mykey" to "myvalue"')
def test_osmcprefs_setprefs_insuf_args(self): error = 'Error, no params provided\Example: osmc_setprefs key value' with FreshDatabase() as db: self.assertEqual(osmcprefs(*['osmc_setprefs']), error) self.assertEqual(osmcprefs(*['osmc_setprefs', 'key']), error)
def test_osmcprefs_getprefs_toomany_args(self): # the function should just ignore the extra arguments with FreshDatabase(preload={'mykey': 'myvalue'}) as db: self.assertEqual(osmcprefs(*['osmc_getprefs', 'mykey', 'extra']), 'myvalue')
def test_osmcprefs_getprefs_noargs(self): with FreshDatabase(preload={'a': '1234'}): self.assertEqual(len(osmcprefs(*['osmc_getprefs'])), 168) self.assertEqual(osmcprefs(*['osmc_getprefs', 'a']), '1234')
def test__get_setting_validkey(self): with FreshDatabase(preload={'a':'1234'}) as db: self.assertEqual(_get_setting('a', db=db), '1234')
def test__get_setting_junkkey(self): with FreshDatabase() as db: self.assertEqual(_get_setting('junk_key', db=db), "KeyError: Key not found in database")