Skip to content

Commit

Permalink
Fix search in plugin name when there is a space
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed May 19, 2022
1 parent 019cc89 commit 91559fb
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

* Fix the search when there is a space in the plugin name
* Fix some Python errors and typo

## 1.1.0 - 2022-05-10
Expand Down
12 changes: 6 additions & 6 deletions qgis_plugin_manager/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,15 @@ def _parse_xml(self, xml_file: Path, plugins: Dict) -> Dict:
else:
tags = []

data['search'] = [
search_text = [
xml_plugin_name.lower(),
xml_plugin_name.lower().replace(" ", ""),
]
data['search'].extend(tags)
data['search'] = list(dict.fromkeys(data['search']))
search_text.extend(tags)
search_text.extend(plugin.attrib['name'].lower().split(" "))

# Remove duplicates
data['search'] = list(dict.fromkeys(search_text))

plugin_obj = Plugin(**data)
self.list_plugins[xml_plugin_name] = plugin_obj
Expand All @@ -229,9 +232,6 @@ def search(self, search_string: str) -> List:
if self.list_plugins is None:
self.available_plugins()

if len(self.list) == 0:
return []

for plugin_name, plugin in self.list_plugins.items():
for item in plugin.search:
ratio = SequenceMatcher(None, search_string.lower(), item.lower()).ratio()
Expand Down
26 changes: 26 additions & 0 deletions test/fixtures/xml_files/lizmap/lizmap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,30 @@
<external_dependencies></external_dependencies>
<server>True</server>
</pyqgis_plugin>
<pyqgis_plugin name="Lizmap server" version="1.0.0" plugin_id="2683">
<description><![CDATA[Only used on a QGIS server. Publish and share your QGIS maps on the Web via Lizmap Web Client, by 3liz.com]]></description>
<about><![CDATA[With a few clicks, it&#39;s possible to publish and share your QGIS projects on the Web via Lizmap Web Client, by 3liz.com. QGIS Server is used in the background so all the symbology is kept. The edition forms in QGIS are also available. Demo : https://demo.lizmap.com and documentation : https://docs.lizmap.com and hosting solutions https://lizmap.com]]></about>
<version>1.0.0</version>
<trusted>True</trusted>
<qgis_minimum_version>3.10.0</qgis_minimum_version>
<qgis_maximum_version>3.99.0</qgis_maximum_version>
<homepage><![CDATA[https://docs.lizmap.com]]></homepage>
<file_name>lizmap_server.1.0.0.zip</file_name>
<icon>/media/packages/2022/icon_NdFz8Bm.png</icon>
<author_name><![CDATA[3Liz]]></author_name>
<download_url>https://plugins.qgis.org/plugins/lizmap_server/version/1.0.0/download/</download_url>
<uploaded_by><![CDATA[Gustry]]></uploaded_by>
<create_date>2022-05-11T04:20:29.836930</create_date>
<update_date>2022-05-11T04:20:30.259694</update_date>
<experimental>False</experimental>
<deprecated>False</deprecated>
<tracker><![CDATA[https://github.com/3liz/qgis-lizmap-server-plugin/issues]]></tracker>
<repository><![CDATA[https://github.com/3liz/qgis-lizmap-server-plugin]]></repository>
<tags><![CDATA[web,cloud]]></tags>
<downloads>189</downloads>
<average_vote>0.0</average_vote>
<rating_votes>0</rating_votes>
<external_dependencies></external_dependencies>
<server>True</server>
</pyqgis_plugin>
</plugins>
34 changes: 32 additions & 2 deletions test/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,52 @@ def test_plugin_name_with_space_and_tags(self):
""" Test plugin with different name, using tags. """
self.remote = Remote(Path('fixtures/xml_files/dataplotly'))
plugins = self.remote._parse_xml(Path('fixtures/xml_files/dataplotly/dataplotly.xml'), {})
self.assertDictEqual({'Data Plotly': '0.4'}, plugins)

self.assertEqual(1, len(self.remote.list_plugins))

plugin = self.remote.list_plugins.get('Data Plotly')
self.assertIsNotNone(plugin)
self.assertEqual(plugin.name, 'Data Plotly')
self.assertDictEqual({'Data Plotly': '0.4'}, plugins)
self.assertEqual(plugin.tags, 'vector,python,d3,plots,graphs,datavis,dataplotly,dataviz')
self.assertListEqual(
plugin.search,
['data plotly', 'dataplotly', 'vector', 'python', 'd3', 'plots', 'graphs', 'datavis', 'dataviz']
[
'data plotly', 'dataplotly', 'vector', 'python', 'd3', 'plots', 'graphs', 'datavis',
'dataviz', 'data', 'plotly'
]
)

# Test the search
self.assertListEqual([], self.remote.search("foo"))
self.assertListEqual(['Data Plotly'], self.remote.search("dataviz"))
self.assertListEqual(['Data Plotly'], self.remote.search("dataplotly"))

def test_search_with_space_in_name(self):
""" Test Lizmap should give 2 values : Lizmap and 'Lizmap server'. """
self.remote = Remote(Path('fixtures/xml_files/lizmap'))
plugins = self.remote._parse_xml(Path('fixtures/xml_files/lizmap/lizmap.xml'), {})
self.assertEqual(2, len(self.remote.list_plugins))
self.assertDictEqual(
{
'Lizmap': '3.7.4',
'Lizmap server': '1.0.0',
},
plugins
)

plugin = self.remote.list_plugins.get('Lizmap server')
self.assertIsNotNone(plugin)
self.assertEqual(plugin.name, 'Lizmap server')

self.assertListEqual(
plugin.search,
['lizmap server', 'lizmapserver', 'web', 'cloud', 'lizmap', 'server']
)

# Test the search
self.assertListEqual(['Lizmap', 'Lizmap server'], self.remote.search("lizmap"))

@unittest.expectedFailure
def test_latest_pgmetadata(self):
""" Test read multiple remotes. """
Expand Down

0 comments on commit 91559fb

Please sign in to comment.