def _initialize_skill_settings(self, device_id):
        """Use default settings or copy from another device in same account."""
        _log.info('Initializing settings for skill ' + self.skill.skill_gid)
        account_repo = AccountRepository(self.db)
        account = account_repo.get_account_by_device_id(device_id)
        skill_settings_repo = SkillSettingRepository(self.db)
        skill_family = extract_family_from_global_id(self.skill.skill_gid)
        family_settings = skill_settings_repo.get_family_settings(
            account.id, skill_family)
        new_settings_values = self.default_settings
        if family_settings is not None:
            for settings in family_settings:
                if settings.settings_values is None:
                    continue
                if settings.settings_values != self.default_settings:
                    field_names = settings.settings_values.keys()
                    if field_names == self.default_settings.keys():
                        _log.info(
                            'Copying settings from another device for skill' +
                            self.skill.skill_gid)
                        new_settings_values = settings.settings_values
                        break
        else:
            _log.info('Using default skill settings for skill ' +
                      self.skill.skill_gid)

        return new_settings_values
def _get_device_skill_settings(context):
    """Minimize DB hits and code duplication by getting these values once."""
    if not hasattr(context, 'device_skill_settings'):
        settings_repo = SkillSettingRepository(context.db)
        context.device_skill_settings = (
            settings_repo.get_skill_settings_for_device(context.device_id))
        context.device_settings_values = [
            dss.settings_values for dss in context.device_skill_settings
        ]
Beispiel #3
0
def validate_updated_skill_setting_value(context):
    settings_repo = SkillSettingRepository(context.db)
    device_skill_settings = settings_repo.get_skill_settings_for_device(
        context.device_id
    )
    device_settings_values = [
        dss.settings_values for dss in device_skill_settings
    ]
    assert_that(len(device_skill_settings), equal_to(3))
    expected_settings_values = dict(textfield='New skill text value')
    assert_that(
        expected_settings_values,
        is_in(device_settings_values)
    )
Beispiel #4
0
def validate_skill_setting_field_removed(context):
    settings_repo = SkillSettingRepository(context.db)
    device_skill_settings = settings_repo.get_skill_settings_for_device(
        context.device_id
    )
    device_settings_values = [
        dss.settings_values for dss in device_skill_settings
    ]
    assert_that(len(device_skill_settings), equal_to(2))
    assert_that([None, None], equal_to(device_settings_values))

    new_section = dict(fields=None)
    for device_skill_setting in device_skill_settings:
        skill_gid = device_skill_setting.settings_display['skill_gid']
        if skill_gid.startswith('bar'):
            new_settings_display = device_skill_setting.settings_display
            new_skill_definition = new_settings_display['skillMetadata']
            new_section = new_skill_definition['sections'][0]
    assert_that(context.removed_field, not is_in(new_section['fields']))
Beispiel #5
0
    def setting_repository(self):
        """Only instantiate the SkillSettingsRepository if needed."""
        if self._setting_repository is None:
            self._setting_repository = SkillSettingRepository(self.db)

        return self._setting_repository
Beispiel #6
0
    def skill_setting_repo(self):
        if self._skill_setting_repo is None:
            self._skill_setting_repo = SkillSettingRepository(self.db)

        return self._skill_setting_repo