Skip to content

Commit

Permalink
Merge pull request #97 from cloudblue/feature/LITE-28443-add-filterin…
Browse files Browse the repository at this point in the history
…g-on-dep-requests

LITE-28443: Adding filtering on deployment's request
  • Loading branch information
akodelia authored Aug 30, 2023
2 parents 1bc4677 + feb9552 commit 7dc27c9
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 6 deletions.
15 changes: 11 additions & 4 deletions connect_ext_ppr/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ class Constants(Filter.Constants):


class DeploymentRequestFilter(Filter):
id: Optional[str]
deployment: Optional[DeploymentFilter] = FilterDepends(
with_prefix('deployment', DeploymentFilter),
)
status: Optional[str]
delegate_l2: Optional[bool]

Expand All @@ -53,3 +49,14 @@ class MarketplaceConfigurationFilter(Filter):

class Constants(Filter.Constants):
model = MarketplaceConfiguration


class DeploymentRequestExtendedFilter(DeploymentRequestFilter):
id: Optional[str]

deployment: Optional[DeploymentFilter] = FilterDepends(
with_prefix('deployment', DeploymentFilter),
)

class Constants(Filter.Constants):
model = DeploymentRequest
6 changes: 4 additions & 2 deletions connect_ext_ppr/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
)
from connect_ext_ppr.errors import ExtensionHttpError, ExtensionValidationError
from connect_ext_ppr.filters import (
DeploymentFilter, DeploymentRequestFilter, MarketplaceConfigurationFilter, PPRVersionFilter,
DeploymentFilter, DeploymentRequestExtendedFilter, DeploymentRequestFilter,
MarketplaceConfigurationFilter, PPRVersionFilter,
)
from connect_ext_ppr.models.configuration import Configuration
from connect_ext_ppr.models.deployment import (
Expand Down Expand Up @@ -185,7 +186,7 @@ def add_dep_request(
)
def list_deployment_requests(
self,
dr_filter: DeploymentRequestFilter = FilterDepends(DeploymentRequestFilter),
dr_filter: DeploymentRequestExtendedFilter = FilterDepends(DeploymentRequestExtendedFilter),
pagination_params: PaginationParams = Depends(),
response: Response = None,
client: ConnectClient = Depends(get_installation_client),
Expand Down Expand Up @@ -383,6 +384,7 @@ def get_deployment(
def list_requests_for_deployment(
self,
deployment_id: str,
dr_filter: DeploymentRequestFilter = FilterDepends(DeploymentRequestFilter),
pagination_params: PaginationParams = Depends(),
response: Response = None,
client: ConnectClient = Depends(get_installation_client),
Expand Down
61 changes: 61 additions & 0 deletions tests/api/test_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,67 @@ def test_list_deployments_requests_for_deployment_with_pagination(
assert response.headers['Content-Range'] == expected_header


@pytest.mark.parametrize(
('filters', 'expected_amount', 'expected_header'),
(
('', 3, 'items 0-2/3'),
('status=pending', 1, 'items 0-0/1'),
('delegate_l2=false', 2, 'items 0-1/2'),
('delegate_l2=true', 1, 'items 0-0/1'),
('ppr__version=1', 1, 'items 0-0/1'),
),
)
def test_list_deployment_requests_filters(
filters,
expected_amount,
expected_header,
mocker,
deployment_factory,
deployment_request_factory,
ppr_version_factory,
installation,
api_client,
):
hubs_data = [{
'id': 'HB-0000-000',
'name': 'Another Hub for the best',
}]

mocker.patch(
'connect_ext_ppr.webapp.get_hubs',
side_effect=[hubs_data],
)
dep1 = deployment_factory(
product_id='PRD-000-001',
account_id=installation['owner']['id'],
hub_id=hubs_data[0]['id'],
)

deployment_request_factory(
deployment=dep1,
status='error',
ppr=ppr_version_factory(deployment=dep1, version=1))

deployment_request_factory(
deployment=dep1,
status='done',
delegate_l2=True,
ppr=ppr_version_factory(deployment=dep1, version=2))

deployment_request_factory(
deployment=dep1,
status='pending',
ppr=ppr_version_factory(deployment=dep1, version=3))

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


def test_list_deployment_request_deployment_not_found(
deployment_factory,
deployment_request_factory,
Expand Down

0 comments on commit 7dc27c9

Please sign in to comment.