Skip to content

Commit

Permalink
[EDS-619] Re-support wildcard searches that were accidentally removed… (
Browse files Browse the repository at this point in the history
#125)

* [EDS-619] Re-support wildcard searches that were accidentally removed in a previous update. Woops!

* [Bot] Update version to 2.1.3

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
Thomas Thorogood and github-actions[bot] authored Dec 8, 2021
1 parent 163ac2f commit b6e66fb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
17 changes: 17 additions & 0 deletions husky_directory/services/query_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,23 @@ def generate_box_number_queries(box_number: str) -> Tuple[str, ListPersonsInput]
request_input=ListPersonsInput(mail_stop=alt_number),
)

@staticmethod
def generate_name_queries(name):
"""
We only execute this if a user has given us a name
with a wildcard in it. Otherwise, the wildcard/reducer strategy is used.
"""
if "*" in name:
yield GeneratedQuery(
description=f'Name matches "{name}"',
request_input=ListPersonsInput(display_name=name),
)
if not name.startswith("*"):
yield GeneratedQuery(
description=f'Name includes "{name}"',
request_input=ListPersonsInput(display_name=f"*{name}"),
)

@staticmethod
def generate_email_queries(partial: str) -> Tuple[str, ListPersonsInput]:
# If a user has supplied a full, valid email address, we will search only for the complete
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "uw-husky-directory"
version = "2.1.2"
version = "2.1.3"
description = "An updated version of the UW Directory"
authors = ["Thomas Thorogood <[email protected]>"]
license = "MIT"
Expand Down
10 changes: 9 additions & 1 deletion tests/services/test_query_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,21 @@ def initialize(self, injector: Injector, mock_injected):
self.query_generator = injector.get(SearchQueryGenerator)
yield

def test_wildcard_input(self):
def test_email_wildcard_input(self):
generated = list(
self.query_generator.generate(SearchDirectoryInput(email="foo*"))
)
assert len(generated) == 1
assert generated[0].description == 'Email matches "foo*"'

def test_name_wildcard_input(self):
generated = list(
self.query_generator.generate(SearchDirectoryInput(name="foo*"))
)
assert len(generated) == 2
assert generated[0].description == 'Name matches "foo*"'
assert generated[1].description == 'Name includes "foo*"'

def test_phone_input_short_number(self):
request_input = SearchDirectoryInput(phone="2065554321")
queries = list(self.query_generator.generate(request_input))
Expand Down

0 comments on commit b6e66fb

Please sign in to comment.