예제 #1
0
 def test_validate__prefs_empty_id__exception_raised(self, ext_dir, valid_manifest):
     valid_manifest['preferences'] = [
         {}
     ]
     manifest = ExtensionManifest('test_extension', valid_manifest, ext_dir)
     with pytest.raises(ManifestValidationError):
         manifest.validate()
예제 #2
0
 def test_validate__name_empty__exception_raised(self, ext_dir):
     manifest = ExtensionManifest('test_extension', {
         'manifest_version': '1',
         'api_version': '1'
     }, ext_dir)
     with pytest.raises(ManifestValidationError):
         manifest.validate()
예제 #3
0
 def test_validate__type_kw_empty_name__exception_raised(self, ext_dir, valid_manifest):
     valid_manifest['preferences'] = [
         {'id': 'id', 'type': 'incorrect', 'keyword': 'kw'}
     ]
     manifest = ExtensionManifest('test_extension', valid_manifest, ext_dir)
     with pytest.raises(ManifestValidationError):
         manifest.validate()
예제 #4
0
 def test_validate__raises_error_if_empty_default_value_for_keyword(self, ext_dir, valid_manifest):
     valid_manifest['preferences'] = [
         {'id': 'id', 'type': 'keyword', 'name': 'My Keyword'}
     ]
     manifest = ExtensionManifest('test_extension', valid_manifest, ext_dir)
     with pytest.raises(ManifestValidationError):
         manifest.validate()
예제 #5
0
 def test_validate__doesnt_raise_if_empty_default_value_for_non_keyword(self, ext_dir, valid_manifest):
     valid_manifest['preferences'] = [
         {'id': 'id', 'type': 'keyword', 'name': 'My Keyword', 'default_value': 'kw'},
         {'id': 'city', 'type': 'input', 'name': 'City'},
     ]
     manifest = ExtensionManifest('test_extension', valid_manifest, ext_dir)
     manifest.validate()
 def test_validate__doesnt_raise_if_empty_default_value_for_non_keyword(self, ext_dir, valid_manifest):
     valid_manifest['preferences'] = [
         {'id': 'id', 'type': 'keyword', 'name': 'My Keyword', 'default_value': 'kw'},
         {'id': 'city', 'type': 'input', 'name': 'City'},
     ]
     manifest = ExtensionManifest('test_extension', valid_manifest, ext_dir)
     manifest.validate()
예제 #7
0
 def test_load_icon__load_image__is_called(self, ext_dir, mocker):
     load_image = mocker.patch(
         'ulauncher.api.server.ExtensionManifest.load_image')
     manifest = ExtensionManifest('test_extension',
                                  {'icon': 'images/icon.png'}, ext_dir)
     assert manifest.load_icon(100) is load_image.return_value
     load_image.assert_called_with(
         os.path.join(ext_dir, 'test_extension', 'images/icon.png'), 100)
 def test_validate__type_kw_empty_name__exception_raised(self, ext_dir, valid_manifest):
     valid_manifest['preferences'] = [
         {'id': 'id', 'type': 'incorrect', 'keyword': 'kw'}
     ]
     manifest = ExtensionManifest('test_extension', valid_manifest, ext_dir)
     with pytest.raises(ExtensionManifestError) as e:
         manifest.validate()
     assert e.value.error_name == ErrorName.InvalidManifestJson.value
예제 #9
0
 def test_check_compatibility__manifest_version_12__exception_raised(
         self, ext_dir):
     manifest = ExtensionManifest('test_extension', {
         'api_version': '0',
         'manifest_version': '12'
     }, ext_dir)
     with pytest.raises(VersionIncompatibilityError):
         manifest.check_compatibility()
예제 #10
0
 def test_validate__raises_error_if_empty_default_value_for_keyword(self, ext_dir, valid_manifest):
     valid_manifest['preferences'] = [
         {'id': 'id', 'type': 'keyword', 'name': 'My Keyword'}
     ]
     manifest = ExtensionManifest('test_extension', valid_manifest, ext_dir)
     with pytest.raises(ExtensionManifestError) as e:
         manifest.validate()
     assert e.value.error_name == ErrorName.InvalidManifestJson.value
예제 #11
0
 def test_validate__prefs_empty_id__exception_raised(self, ext_dir, valid_manifest):
     valid_manifest['preferences'] = [
         {}
     ]
     manifest = ExtensionManifest('test_extension', valid_manifest, ext_dir)
     with pytest.raises(ExtensionManifestError) as e:
         manifest.validate()
     assert e.value.error_name == ErrorName.InvalidManifestJson.value
예제 #12
0
 def test_get_preference(self, ext_dir):
     manifest_dict = {
         'preferences': [
             {'id': 'myid', 'type': 'keyword', 'default_value': 'mi', 'name': "Mimimi"},
             {'id': 'newid', 'type': 'input', 'default_value': 'ni'}
         ]
     }
     manifest = ExtensionManifest('test_extension', manifest_dict, ext_dir)
     assert manifest.get_preference('newid') == {'id': 'newid', 'type': 'input', 'default_value': 'ni'}
예제 #13
0
 def test_get_preference(self, ext_dir):
     manifest_dict = {
         'preferences': [
             {'id': 'myid', 'type': 'keyword', 'default_value': 'mi', 'name': "Mimimi"},
             {'id': 'newid', 'type': 'input', 'default_value': 'ni'}
         ]
     }
     manifest = ExtensionManifest('test_extension', manifest_dict, ext_dir)
     assert manifest.get_preference('newid') == {'id': 'newid', 'type': 'input', 'default_value': 'ni'}
예제 #14
0
 def test_validate__raises_error_if_empty_default_value_for_keyword(
         self, ext_dir, valid_manifest):
     valid_manifest['preferences'] = [{
         'id': 'id',
         'type': 'keyword',
         'name': 'My Keyword'
     }]
     manifest = ExtensionManifest('test_extension', valid_manifest, ext_dir)
     with pytest.raises(ManifestValidationError):
         manifest.validate()
예제 #15
0
 def test_validate__type_kw_empty_name__exception_raised(
         self, ext_dir, valid_manifest):
     valid_manifest['preferences'] = [{
         'id': 'id',
         'type': 'incorrect',
         'keyword': 'kw'
     }]
     manifest = ExtensionManifest('test_extension', valid_manifest, ext_dir)
     with pytest.raises(ManifestValidationError):
         manifest.validate()
예제 #16
0
    def handleConnected(self):
        """
        Implements abstract method of :class:`WebSocket`

        * Appends `self` to `self.controllers`
        * Validates manifest file.
        * Sends :class:`PreferencesEvent` to extension
        """
        self.extension_id = self.request.path[1:]
        if not self.extension_id:
            raise Exception('Incorrect path %s' % self.request.path)

        logger.info('Extension "%s" connected', self.extension_id)

        self.manifest = ExtensionManifest.open(self.extension_id)
        try:
            self.manifest.validate()
        except ExtensionManifestError as e:
            logger.warning("Couldn't connect '%s'. %s: %s", self.extension_id, type(e).__name__, e)
            self.close()
            return

        self.preferences = ExtensionPreferences.create_instance(self.extension_id)
        self.controllers[self.extension_id] = self
        self._debounced_send_event = debounce(self.manifest.get_option('query_debounce', 0.05))(self._send_event)

        self._send_event(PreferencesEvent(self.preferences.get_dict()))
예제 #17
0
    def run(self, extension_id):
        """
        * Validates manifest
        * Runs extension in a new process

        :rtype: :class:`threading.Thread`
        """
        if self.is_running(extension_id):
            raise ExtensionIsRunningError('Extension ID: %s' % extension_id)

        manifest = ExtensionManifest.open(extension_id)
        manifest.validate()
        manifest.check_compatibility()

        run_process = run_async(daemon=True)(self._run_process)
        run_process(extension_id)
예제 #18
0
 def test_load_icon__load_image__is_called(self, ext_dir, mocker):
     load_image = mocker.patch('ulauncher.api.server.ExtensionManifest.load_image')
     manifest = ExtensionManifest('test_extension', {'icon': 'images/icon.png'}, ext_dir)
     assert manifest.load_icon(100) is load_image.return_value
     load_image.assert_called_with(os.path.join(ext_dir, 'test_extension', 'images/icon.png'), 100)
예제 #19
0
 def test_refresh__name__is_reloaded(self, ext_dir):
     manifest = ExtensionManifest('test_extension', {'name': 'Old'}, ext_dir)
     assert manifest.get_name() == 'Old'
     manifest.refresh()
     assert manifest.get_name() == "Test Extension"
예제 #20
0
 def test_open__manifest_file__is_read(self, ext_dir):
     manifest = ExtensionManifest.open('test_extension', ext_dir)
     assert manifest.get_name() == "Test Extension"
예제 #21
0
 def test_get_option__option_doesnt_exist__default_returned(self, ext_dir):
     manifest_dict = {
         'options': {}
     }
     manifest = ExtensionManifest('test_extension', manifest_dict, ext_dir)
     manifest.get_option('query_debounce', 0.4) == 0.4
예제 #22
0
 def test_get_option__option_exists__value_returned(self, ext_dir):
     manifest_dict = {
         'options': {'query_debounce': 0.5}
     }
     manifest = ExtensionManifest('test_extension', manifest_dict, ext_dir)
     manifest.get_option('query_debounce') == 0.5
예제 #23
0
 def test_validate__name_empty__exception_raised(self, ext_dir):
     manifest = ExtensionManifest('test_extension', {'required_api_version': '1'}, ext_dir)
     with pytest.raises(ExtensionManifestError) as e:
         manifest.validate()
     assert e.value.error_name == ErrorName.InvalidManifestJson.value
예제 #24
0
 def test_validate__valid_manifest__no_exceptions_raised(self, ext_dir, valid_manifest):
     manifest = ExtensionManifest('test_extension', valid_manifest, ext_dir)
     manifest.validate()
예제 #25
0
 def test_validate__prefs_empty_id__exception_raised(
         self, ext_dir, valid_manifest):
     valid_manifest['preferences'] = [{}]
     manifest = ExtensionManifest('test_extension', valid_manifest, ext_dir)
     with pytest.raises(ManifestValidationError):
         manifest.validate()
예제 #26
0
 def test_get_option__option_doesnt_exist__default_returned(self, ext_dir):
     manifest_dict = {
         'options': {}
     }
     manifest = ExtensionManifest('test_extension', manifest_dict, ext_dir)
     assert manifest.get_option('query_debounce', 0.4) == 0.4
예제 #27
0
 def create_instance(cls, ext_id):
     return cls(ext_id, ExtensionManifest.open(ext_id))
예제 #28
0
 def test_open__manifest_file__is_read(self, ext_dir):
     manifest = ExtensionManifest.open('test_extension', ext_dir)
     assert manifest.get_name() == "Test Extension"
예제 #29
0
 def test_validate__valid_manifest__no_exceptions_raised(self, ext_dir, valid_manifest):
     manifest = ExtensionManifest('test_extension', valid_manifest, ext_dir)
     manifest.validate()
예제 #30
0
 def test_validate__manifest_version_is_2__exception_raised(self, ext_dir):
     manifest = ExtensionManifest('test_extension', {'manifest_version': '2'}, ext_dir)
     with pytest.raises(ManifestValidationError):
         manifest.validate()
예제 #31
0
 def test_validate__name_empty__exception_raised(self, ext_dir):
     manifest = ExtensionManifest('test_extension', {'manifest_version': '1', 'api_version': '1'}, ext_dir)
     with pytest.raises(ManifestValidationError):
         manifest.validate()
예제 #32
0
 def test_check_compatibility__required_api_version_1__no_exceptions(self, ext_dir):
     manifest = ExtensionManifest('test_extension', {'required_api_version': '2'}, ext_dir)
     manifest.check_compatibility()
예제 #33
0
 def test_get_option__option_exists__value_returned(self, ext_dir):
     manifest_dict = {
         'options': {'query_debounce': 0.5}
     }
     manifest = ExtensionManifest('test_extension', manifest_dict, ext_dir)
     assert manifest.get_option('query_debounce') == 0.5
예제 #34
0
 def test_refresh__name__is_reloaded(self, ext_dir):
     manifest = ExtensionManifest('test_extension', {'name': 'Old'}, ext_dir)
     assert manifest.get_name() == 'Old'
     manifest.refresh()
     assert manifest.get_name() == "Test Extension"
예제 #35
0
 def test_validate__manifest_version_is_2__exception_raised(self, ext_dir):
     manifest = ExtensionManifest('test_extension',
                                  {'manifest_version': '2'}, ext_dir)
     with pytest.raises(ManifestValidationError):
         manifest.validate()
예제 #36
0
 def test_check_compatibility__manifest_version_12__exception_raised(self, ext_dir):
     manifest = ExtensionManifest('test_extension', {'required_api_version': '0'}, ext_dir)
     with pytest.raises(ExtensionManifestError) as e:
         manifest.check_compatibility()
     assert e.value.error_name == ErrorName.ExtensionCompatibilityError.value
예제 #37
0
 def test_check_compatibility__manifest_version_12__exception_raised(self, ext_dir):
     manifest = ExtensionManifest('test_extension', {'api_version': '0', 'manifest_version': '12'}, ext_dir)
     with pytest.raises(VersionIncompatibilityError):
         manifest.check_compatibility()
예제 #38
0
 def test_check_compatibility__api_version_1__no_exceptions(self, ext_dir):
     manifest = ExtensionManifest('test_extension', {'api_version': '1', 'manifest_version': '1'}, ext_dir)
     manifest.check_compatibility()