Skip to content

Commit

Permalink
[Issue #1494] Modify agency filter to be an exact match (#1530)
Browse files Browse the repository at this point in the history
## Summary
Fixes #1494

### Time to review: __2 mins__

## Changes proposed
Adjust the logic for filtering by agency to be an exact match instead of
the prior "starts with" logic.

## Context for reviewers
This adjustments comes out of a recent discussion with our front-end
folks. Turns out they intend to pass us every agency for sub-agencies
(eg. `HHS-123`, `HHS-456`, etc). I had implemented sub-agency logic
assuming we'd want prefixes, which is clunky. This makes the logic more
intuitive by just being a simple match.

Note that previously the agencies were also case-insensitive which is no
longer here, but that also isn't really necessary.

## Additional information
Updated a few tests that assumed prior logic - nothing too significant
here
  • Loading branch information
chouinar authored Mar 27, 2024
1 parent cace777 commit 5d898f9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
6 changes: 1 addition & 5 deletions api/src/services/opportunities_v0_1/search_opportunities.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,7 @@ def _add_filters(
# Note that we filter against the agency code in the opportunity, not in the summary
one_of_agencies = filters.agency.get("one_of")
if one_of_agencies:
# This produces something like:
# ..WHERE ((opportunity.agency ILIKE 'US-ABC%') OR (opportunity.agency ILIKE 'HHS%'))
stmt = stmt.where(
or_(*[Opportunity.agency.istartswith(agency) for agency in one_of_agencies])
)
stmt = stmt.where(Opportunity.agency.in_(one_of_agencies))

return stmt

Expand Down
18 changes: 10 additions & 8 deletions api/tests/src/api/opportunities_v0_1/test_opportunity_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,11 +968,11 @@ def setup_scenarios(self, truncate_opportunities, enable_factory_create):
Scenario.POSTED_OPPORTUNITY_TITLE_HAS_PERCENT,
],
),
### Agency field tests (note that agency works as a prefix)
### Agency field tests
### By default agency is set to "DEFAULT-ABC" with a few overriding that to "DIFFERENT-<something>"
# Should only return the agencies that start "DIFFERENT-" (case-insensitive)
# Should only return the agencies that start "DIFFERENT-"
(
get_search_request(page_size=25, agency_one_of=["DiFfErEnT"]),
get_search_request(page_size=25, agency_one_of=["DIFFERENT-ABC", "DIFFERENT-XYZ"]),
[
Scenario.POSTED_NON_DEFAULT_AGENCY_WITH_APP_TYPES,
Scenario.CLOSED_NON_DEFAULT_AGENCY_WITH_FUNDING_CATEGORIES,
Expand All @@ -982,12 +982,14 @@ def setup_scenarios(self, truncate_opportunities, enable_factory_create):
(get_search_request(page_size=25, agency_one_of=["no agency starts with this"]), []),
# Should only return a single agency as it's the only one that has this name
(
get_search_request(page_size=25, agency_one_of=["different-xyz"]),
get_search_request(page_size=25, agency_one_of=["DIFFERENT-XYZ"]),
[Scenario.CLOSED_NON_DEFAULT_AGENCY_WITH_FUNDING_CATEGORIES],
),
# Should return everything with agency set as it will be happy with both prefixes
# Should return everything with agency set as these are all the values we set
(
get_search_request(page_size=25, agency_one_of=["DEFAULT", "different"]),
get_search_request(
page_size=25, agency_one_of=["DEFAULT-ABC", "DIFFERENT-ABC", "DIFFERENT-XYZ"]
),
[
Scenario.POSTED_ALL_ENUM_VALUES,
Scenario.POSTED_NON_DEFAULT_AGENCY_WITH_APP_TYPES,
Expand Down Expand Up @@ -1096,7 +1098,7 @@ def setup_scenarios(self, truncate_opportunities, enable_factory_create):
(
get_search_request(
page_size=25,
agency_one_of=["different"],
agency_one_of=["DIFFERENT-ABC"],
applicant_type_one_of=[ApplicantType.COUNTY_GOVERNMENTS],
),
[Scenario.POSTED_NON_DEFAULT_AGENCY_WITH_APP_TYPES],
Expand Down Expand Up @@ -1160,7 +1162,7 @@ def setup_scenarios(self, truncate_opportunities, enable_factory_create):
get_search_request(
page_size=25,
opportunity_status_one_of=[OpportunityStatus.FORECASTED],
agency_one_of=["different"],
agency_one_of=["DIFFERENT-ABC", "DIFFERENT-XYZ"],
),
[],
),
Expand Down

0 comments on commit 5d898f9

Please sign in to comment.