Skip to content

Commit

Permalink
LITE-28633: Adding filtering on tasks endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
akodelia committed Sep 19, 2023
1 parent 3d70714 commit 1ccbcbf
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
8 changes: 8 additions & 0 deletions connect_ext_ppr/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Deployment, DeploymentRequest, MarketplaceConfiguration,
)
from connect_ext_ppr.models.ppr import PPRVersion
from connect_ext_ppr.models.task import Task


class DeploymentFilter(Filter):
Expand Down Expand Up @@ -66,3 +67,10 @@ class Constants(Filter.Constants):

class PricingBatchFilter(BaseModel):
marketplace_id: Optional[str]


class TaskFilter(Filter):
status: Optional[str]

class Constants(Filter.Constants):
model = Task
5 changes: 4 additions & 1 deletion connect_ext_ppr/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from connect_ext_ppr.errors import ExtensionHttpError, ExtensionValidationError
from connect_ext_ppr.filters import (
DeploymentFilter, DeploymentRequestExtendedFilter, DeploymentRequestFilter,
MarketplaceConfigurationFilter, PPRVersionFilter, PricingBatchFilter,
MarketplaceConfigurationFilter, PPRVersionFilter, PricingBatchFilter, TaskFilter,
)
from connect_ext_ppr.models.configuration import Configuration
from connect_ext_ppr.models.deployment import (
Expand Down Expand Up @@ -266,6 +266,7 @@ def get_deployment_request(
def list_deployment_request_tasks(
self,
depl_req_id: str,
task_filter: TaskFilter = FilterDepends(TaskFilter),
pagination_params: PaginationParams = Depends(),
response: Response = None,
db: VerboseBaseSession = Depends(get_db),
Expand All @@ -275,6 +276,8 @@ def list_deployment_request_tasks(
if dr:
task_list = []
qs = db.query(Task).filter_by(deployment_request_id=dr.id).order_by(Task.id)
qs = task_filter.filter(qs)

for task in apply_pagination(qs, db, pagination_params, response):
task_list.append(get_task_schema(task))
return task_list
Expand Down
32 changes: 32 additions & 0 deletions tests/api/test_deployment_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,38 @@ def test_list_deployment_request_tasks(
assert list(events['created'].keys()) == ['at', 'by']


def test_list_deployment_request_tasks_filters(
deployment_factory,
deployment_request_factory,
installation,
api_client,
task_factory,
):
hub_data = {
'id': 'HB-0000-0001',
'name': 'Another Hub for the best',
}
dep1 = deployment_factory(account_id=installation['owner']['id'], hub_id=hub_data['id'])
dep2 = deployment_factory(account_id='PA-123-456')

dr1 = deployment_request_factory(deployment=dep1)
deployment_request_factory(deployment=dep1)
deployment_request_factory(deployment=dep2)

task_factory(deployment_request=dr1, status='done')
t2 = task_factory(
deployment_request=dr1, task_index='002', status='error', error_message='error message',
)

response = api_client.get(
f'/api/deployments/requests/{dr1.id}/tasks?status=error',
installation=installation,
)
assert response.status_code == 200
assert len(response.json()) == 1
assert response.json()[0]['id'] == t2.id


def test_list_deployment_request_tasks_not_found(
deployment_factory,
deployment_request_factory,
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def _build_ppr(
status='pending',
):
ppr = PPRVersion(
file=file or file_factory(id=f'MFL-{randbelow(99999):05d}').id,
file=file or file_factory(id=f'MFL-{randbelow(999):03d}-{randbelow(999):03d}').id,
deployment=deployment.id,
configuration=configuration,
summary=summary or {},
Expand Down

0 comments on commit 1ccbcbf

Please sign in to comment.