Skip to content

Commit

Permalink
fix keyword comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
mamico committed Jul 19, 2024
1 parent 5dcbaff commit fdb0167
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/collective/taxonomy/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def __call__(self):
result = []
for key, value in utility.inverted_data[lang].items():
for found_identifier, found_language, found_path in found:
if found_path.startswith(value) and key not in result:
value_split = value.split("\u241f")
found_split = found_path.split("\u241f")[: len(value_split)]
if found_split == value_split and key not in result:
result.append(key)

return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,11 @@
<langstring language="en">Cars</langstring>
</caption>
</term>
<term>
<termIdentifier>56</termIdentifier>
<caption>
<langstring language="en">Carson</langstring>
</caption>
</term>
</term>
</vdex>
</vdex>
2 changes: 1 addition & 1 deletion src/collective/taxonomy/tests/test_controlpanel_restapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ def test_default_values_loaded(self):
self.assertEqual(len(res), 1)
self.assertEqual(res[0]["name"], "collective.taxonomy.test")
self.assertEqual(res[0]["title"], "Test vocabulary")
self.assertEqual(res[0]["count"], {"da": 4, "de": 1, "en": 5, "ru": 1})
self.assertEqual(res[0]["count"], {"da": 4, "de": 1, "en": 6, "ru": 1})
6 changes: 4 additions & 2 deletions src/collective/taxonomy/tests/test_indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def test_querystring_widget(self):
("3", {"title": "Information Science \xbb Chronology"}),
("5", {"title": "Information Science \xbb Sport"}),
("55", {"title": "Information Science \xbb Cars"}),
("56", {"title": "Information Science \xbb Carson"}),
],
)

Expand All @@ -145,11 +146,12 @@ def test_index_single_select(self):
document_schema = fti.lookupSchema()
notify(ObjectAddedEvent(taxonomy_test, document_schema))
notify(FieldAddedEvent(fti, taxonomy_test))
taxo_val = taxonomy["en"]["\u241fInformation Science\u241fCars"]
taxo_val = taxonomy["en"]["\u241fInformation Science\u241fCarson"]
self.document.taxonomy_test = taxo_val
self.document.reindexObject()
self.assertEqual(len(portal_catalog({"taxonomy_test": "5"})), 0)
self.assertEqual(len(portal_catalog({"taxonomy_test": "55"})), 1)
self.assertEqual(len(portal_catalog({"taxonomy_test": "55"})), 0) # not Cars ...
self.assertEqual(len(portal_catalog({"taxonomy_test": "56"})), 1) # ... but Carson

def test_indexer_with_property(self):
portal_catalog = api.portal.get_tool("portal_catalog")
Expand Down
2 changes: 1 addition & 1 deletion src/collective/taxonomy/tests/test_taxonomy_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_get_without_parameters_return_all_taxonomies(self):
self.assertEqual(len(res), 1)
self.assertEqual(res[0]["name"], "collective.taxonomy.test")
self.assertEqual(res[0]["title"], "Test vocabulary")
self.assertEqual(res[0]["count"], {"da": 4, "de": 1, "en": 5, "ru": 1})
self.assertEqual(res[0]["count"], {"da": 4, "de": 1, "en": 6, "ru": 1})

def test_get_with_parameters_return_taxonomy_details(self):
response = self.api_session.get("/@taxonomy/collective.taxonomy.test")
Expand Down
2 changes: 1 addition & 1 deletion src/collective/taxonomy/tests/test_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ def test_make_tree(self):

tree = taxonomy.makeVocabulary("en").makeTree()
self.assertIn("Information Science", tree)
self.assertEqual(len(tree["Information Science"]), 4)
self.assertEqual(len(tree["Information Science"]), 5)

0 comments on commit fdb0167

Please sign in to comment.