Skip to content

Commit

Permalink
fix: case insensitive fiscalcode (#94)
Browse files Browse the repository at this point in the history
* fix: case insensitive fiscalcode

* black

* zprettu

* changelog

* fix test
  • Loading branch information
mamico authored Sep 25, 2023
1 parent c72c670 commit 05a0d59
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 44 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ Changelog
2.0.1 (unreleased)
------------------

- Rimosso searchabletext di prenotazioni doppio
[mamico]

- Aggiunto indexer per fiscalcode uppercase per
fare ricerche case insensitive
[mamico]

- Remove Contributor from the package permissions map
[folix-01]

Expand Down
15 changes: 0 additions & 15 deletions src/redturtle/prenotazioni/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,4 @@
name="redturtle.prenotazioni-hiddenprofiles"
/>

<adapter
factory=".indexes.Subject_prenotazione"
name="Subject"
/>

<adapter
factory=".indexes.SearchableText_prenotazione"
name="SearchableText"
/>

<adapter
factory=".indexes.Date"
name="Date"
/>

</configure>
17 changes: 16 additions & 1 deletion src/redturtle/prenotazioni/indexers/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,23 @@
>

<adapter
factory=".searchable_text.prenotazione"
factory=".prenotazione.Subject_prenotazione"
name="Subject"
/>

<adapter
factory=".prenotazione.SearchableText_prenotazione"
name="SearchableText"
/>

<adapter
factory=".prenotazione.Date"
name="Date"
/>

<adapter
factory=".prenotazione.fiscalcode"
name="fiscalcode"
/>

</configure>
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,10 @@ def Date(obj):
Set as booking_date
"""
return obj.Date()


@indexer(IPrenotazione)
def fiscalcode(obj):
"""upper-ize fiscalcode for case insensitive search"""
if obj.fiscalcode:
return obj.fiscalcode.upper()
28 changes: 0 additions & 28 deletions src/redturtle/prenotazioni/indexers/searchable_text.py

This file was deleted.

18 changes: 18 additions & 0 deletions src/redturtle/prenotazioni/tests/test_prenotazioni_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,24 @@ def test_search_by_fiscalcode(self):
self.assertIn(self.prenotazione_fscode.UID(), result_uids)
self.assertNotIn(self.prenotazione_no_fscode.UID(), result_uids)

def test_search_by_fiscalcode_case_insensitive(self):
# ABCDEF12G34H567I -> AbCdEf12G34H567i
camelcase_fiscalcode = "".join(
[
c.upper() if i % 2 == 0 else c.lower()
for i, c in enumerate(self.testing_fiscal_code)
]
)
result_uids = [
i["booking_id"]
for i in self.api_session.get(
f"{self.portal.absolute_url()}/@bookings/{camelcase_fiscalcode}" # noqa: E501
).json()["items"]
]

self.assertIn(self.prenotazione_fscode.UID(), result_uids)
self.assertNotIn(self.prenotazione_no_fscode.UID(), result_uids)

def test_search_by_fiscalcode_traverse(self):
res = self.api_session.get(
f"{self.portal.absolute_url()}/@bookings/{self.testing_fiscal_code}"
Expand Down

0 comments on commit 05a0d59

Please sign in to comment.