Skip to content

Commit

Permalink
LITE-28441: Adding filters to ppr endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
akodelia committed Aug 30, 2023
1 parent 51d084c commit 208b0dd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
2 changes: 2 additions & 0 deletions connect_ext_ppr/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class PPRVersionFilter(Filter):
id: Optional[str]
version: Optional[int]

order_by: Optional[List[str]]

class Constants(Filter.Constants):
model = PPRVersion

Expand Down
5 changes: 4 additions & 1 deletion connect_ext_ppr/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
)
from connect_ext_ppr.errors import ExtensionHttpError, ExtensionValidationError
from connect_ext_ppr.filters import (
DeploymentFilter, DeploymentRequestFilter, MarketplaceConfigurationFilter,
DeploymentFilter, DeploymentRequestFilter, MarketplaceConfigurationFilter, PPRVersionFilter,
)
from connect_ext_ppr.models.configuration import Configuration
from connect_ext_ppr.models.deployment import (
Expand Down Expand Up @@ -591,6 +591,7 @@ def remove_configuration(
def get_pprs(
self,
deployment_id: str,
ppr_filter: PPRVersionFilter = FilterDepends(PPRVersionFilter),
pagination_params: PaginationParams = Depends(),
response: Response = None,
db: VerboseBaseSession = Depends(get_db),
Expand All @@ -605,6 +606,8 @@ def get_pprs(
.outerjoin(Configuration, PPRVersion.configuration == Configuration.id)
.order_by(desc(PPRVersion.version))
)
ppr_file_conf_qs = ppr_filter.filter(ppr_file_conf_qs)
ppr_file_conf_qs = ppr_filter.sort(ppr_file_conf_qs)
ppr_file_conf_list = apply_pagination(ppr_file_conf_qs, db, pagination_params, response)
response_list = []
for ppr, file, conf in ppr_file_conf_list:
Expand Down
53 changes: 53 additions & 0 deletions tests/api/test_pprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,59 @@ def test_get_pprs_pagination(
assert response.headers['Content-Range'] == expected_header


@pytest.mark.parametrize(
('filters', 'expected_amount', 'expected_header'),
(
('id=PPRFL-123', 1, 'items 0-0/1'),
('version=2', 1, 'items 0-0/1'),
),
)
def test_get_pprs_filters(
filters,
expected_amount,
expected_header,
deployment_factory,
file_factory,
ppr_version_factory,
installation,
api_client,
):
deployment = deployment_factory()
ppr_file = file_factory(
id='MFL-001',
mime_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
)
ppr_version_factory(
id='PPRFL-123',
deployment=deployment,
file=ppr_file.id,
product_version=None,
summary=None,
description=None,
)

for i in range(12):
ppr_file = file_factory(
id=f'MFL-XX{i}',
mime_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
)
ppr_version_factory(
deployment=deployment,
file=ppr_file.id,
product_version=None,
summary=None,
description=None,
)

response = api_client.get(
f'/api/deployments/{deployment.id}/pprs?{filters}',
installation=installation,
)
assert response.status_code == 200
assert len(response.json()) == expected_amount
assert response.headers['Content-Range'] == expected_header


def test_get_pprs_empty(
deployment_factory,
installation,
Expand Down

0 comments on commit 208b0dd

Please sign in to comment.