Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Updating offset pagination strategy to parse numeric strings as integers #1364

Merged
merged 2 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The types of changes are:
### Fixed
* Distinguish whether webhook has been visited and no fields were found, versus never visited [#1339](https://github.com/ethyca/fidesops/pull/1339)
* Fix Redis Cache Early Expiration in Tests [#1358](https://github.com/ethyca/fidesops/pull/1358)
* Limit values for the offset pagination strategy are now cast to integers before use [#1364](https://github.com/ethyca/fidesops/pull/1364)

### Added

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ def get_next_request(
raise FidesopsException(
f"Unable to find value for 'limit' with the connector_param reference '{self.limit.connector_param}'"
)
try:
limit = int(limit)
except ValueError:
raise FidesopsException(
f"The value '{limit}' of the '{self.limit.connector_param}' connector_param could not be cast to an int"
)
param_value += self.increment_by
if param_value > limit:
return None
Expand Down
48 changes: 48 additions & 0 deletions tests/ops/service/pagination/test_pagination_strategy_offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,54 @@ def test_offset_with_connector_param_reference(response_with_body):
)


def test_offset_with_parsable_string_connector_param_reference(response_with_body):
config = OffsetPaginationConfiguration(
incremental_param="page",
increment_by=1,
limit={"connector_param": "limit"},
)
connector_params = {"limit": "10"}
request_params: SaaSRequestParams = SaaSRequestParams(
method=HTTPMethod.GET,
path="/conversations",
query_params={"page": 1},
)

paginator = OffsetPaginationStrategy(config)
next_request: Optional[SaaSRequestParams] = paginator.get_next_request(
request_params, connector_params, response_with_body, "conversations"
)
assert next_request == SaaSRequestParams(
method=HTTPMethod.GET,
path="/conversations",
query_params={"page": 2},
)


def test_offset_with_unparsable_string_connector_param_reference(response_with_body):
config = OffsetPaginationConfiguration(
incremental_param="page",
increment_by=1,
limit={"connector_param": "limit"},
)
connector_params = {"limit": "ten"}
request_params: SaaSRequestParams = SaaSRequestParams(
method=HTTPMethod.GET,
path="/conversations",
query_params={"page": 1},
)

paginator = OffsetPaginationStrategy(config)
with pytest.raises(FidesopsException) as exc:
next_request: Optional[SaaSRequestParams] = paginator.get_next_request(
request_params, connector_params, response_with_body, "conversations"
)
assert (
f"The value 'ten' of the 'limit' connector_param could not be cast to an int"
== str(exc.value)
)


def test_offset_with_connector_param_reference_not_found(response_with_body):
config = OffsetPaginationConfiguration(
incremental_param="page",
Expand Down