added new test and put back is_stored property

pull/933/head
Michael Nguyen 2017-08-01 13:52:51 -05:00
parent 05852f30ef
commit 48b26d1fbd
2 changed files with 14 additions and 3 deletions

View File

@ -70,6 +70,10 @@ class SkillSettings(dict):
self.load_skill_settings()
@property
def _is_stored(self):
return hash(str(self)) == self.loaded_hash
def __getitem__(self, key):
return super(SkillSettings, self).__getitem__(key)
@ -111,7 +115,7 @@ class SkillSettings(dict):
request settings and store it if it changes
TODO: implement as websocket
"""
if self._skill_exist_in_backend:
if self._skill_exist_in_backend():
try:
# update settings
self.settings = self._get_settings()
@ -124,8 +128,7 @@ class SkillSettings(dict):
self.__setitem__(field["name"], field["value"])
# store value if settings has changed from backend
new_hash = hash(str(self))
if new_hash != self.loaded_hash:
if not self._is_stored:
self.store()
self.loaded_hash = hash(str(self))

View File

@ -2,6 +2,7 @@ from mycroft.skills.settings import SkillSettings
from os.path import join, dirname, abspath
from os import remove
import json
import unittest
@ -68,6 +69,13 @@ class SkillSettingsTest(unittest.TestCase):
s2 = SkillSettings(join(dirname(__file__), 'settings'))
self.assertTrue(len(s) == len(s2))
def test_load_existing(self):
directory = join(dirname(__file__), 'settings', 'settings.json')
with open(directory, 'w') as f:
json.dump({"test": "1"}, f)
s = SkillSettings(join(dirname(__file__), 'settings'))
self.assertEqual(len(s), 1)
if __name__ == '__main__':
unittest.main()