Skip to content

Commit

Permalink
Merge branch 'master' into upload-config
Browse files Browse the repository at this point in the history
  • Loading branch information
nerimartinez committed Aug 1, 2023
2 parents b734e61 + 66d8941 commit db62dc5
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 1 deletion.
27 changes: 27 additions & 0 deletions connect_ext_ppr/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,33 @@ def get_deployment(
deployment = get_deployment_schema(dep, dep.product, vendor, hub)
return deployment

@router.get(
'/deployments/{deployment_id}/requests',
summary='List all deployment requests in scope of a deployment',
response_model=List[DeploymentRequestSchema],
)
def list_requests_for_deployment(
self,
deployment_id: str,
client: ConnectClient = Depends(get_installation_client),
db: VerboseBaseSession = Depends(get_db),
installation: dict = Depends(get_installation),
):
dep = get_deployment_by_id(deployment_id, db, installation)

hub = get_hub(client, dep.hub_id)

response_list = []
qs = (
db
.query(DeploymentRequest)
.filter_by(deployment_id=deployment_id)
.order_by(desc(DeploymentRequest.id))
)
for dr in qs:
response_list.append(get_deployment_request_schema(dr, hub))
return response_list

@router.get(
'/deployments',
summary='List all available deployments',
Expand Down
82 changes: 82 additions & 0 deletions tests/api/test_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,85 @@ def test_get_deployments_marketplaces_not_accounts_deployment(
)

assert response.status_code == 404


def test_list_deployments_requests_for_deployment(
dbsession,
mocker,
deployment_factory,
deployment_request_factory,
installation,
api_client,
):
hub_data = {
'id': 'HB-0000-0001',
'name': 'Another Hub for the best',
}
mocker.patch(
'connect_ext_ppr.webapp.get_hub',
return_value=hub_data,
)
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)
dr2 = deployment_request_factory(deployment=dep1)
deployment_request_factory(deployment=dep2)

response = api_client.get(
f'/api/deployments/{dep1.id}/requests',
installation=installation,
)
assert response.status_code == 200
assert len(response.json()) == 2

for response_item, dr in zip(response.json(), [dr2, dr1]):
events = response_item.pop('events')
assert response_item == {
'id': dr.id,
'deployment': {
'id': dep1.id,
'product': {
'id': dep1.product.id,
'name': dep1.product.name,
'icon': dep1.product.logo,
},
'hub': hub_data,
},
'ppr': {
'id': dr.ppr_id,
'version': dr.ppr.version,
},
'status': dr.status.value,
'manually': dr.manually,
'delegate_l2': dr.delegate_l2,

}
assert list(events.keys()) == ['created']
assert list(events['created'].keys()) == ['at', 'by']


def test_list_deployment_request_deployment_not_found(
dbsession,
deployment_factory,
deployment_request_factory,
installation,
api_client,
):

dep1 = deployment_factory(account_id=installation['owner']['id'])
dep2 = deployment_factory(account_id='PA-123-456')

deployment_request_factory(deployment=dep1)
deployment_request_factory(deployment=dep1)

response = api_client.get(
f'/api/deployments/{dep2.id}/requests',
installation=installation,
)
error = response.json()

assert response.status_code == 404
assert error == {
'error_code': 'EXT_001', 'errors': [f'Object `{dep2.id}` not found.'],
}
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def _build_deployment_request(
status=status,
)
dbsession.add(ppr)
dbsession.set_verbose(dep_req)
dbsession.set_next_verbose(dep_req, 'deployment_id')
return dep_req
return _build_deployment_request

Expand Down

0 comments on commit db62dc5

Please sign in to comment.