Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge pull request #93 from cloudblue/feature/LITE-28440-Add-filters-… #95

Closed
Closed
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
15 changes: 11 additions & 4 deletions connect_ext_ppr/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,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 @@ -49,3 +45,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,
DeploymentFilter, DeploymentRequestExtendedFilter, DeploymentRequestFilter,
MarketplaceConfigurationFilter,
)
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 @@ -407,6 +407,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
You are viewing a condensed version of this merge commit. You can view the full changes here.