Coverage for middle_layer/solicit/application_layer/rest_api/views/proposal_process.py: 100.00%
21 statements
« prev ^ index » next coverage.py v7.10.5, created at 2026-03-09 06:13 +0000
« prev ^ index » next coverage.py v7.10.5, created at 2026-03-09 06:13 +0000
1# Copyright 2024 Associated Universities, Inc.
2#
3# This file is part of Telescope Time Allocation Tools (TTAT).
4#
5# TTAT is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# any later version.
9#
10# TTAT is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with TTAT. If not, see <https://www.gnu.org/licenses/>.
17#
18from http import HTTPStatus
20from pyramid.request import Request
21from pyramid.response import Response
22from pyramid.view import view_config
24from solicit.domain_layer.entities.solicitation import ProposalProcess
27@view_config(route_name="proposal_processes_list", renderer="json", permission="proposal_processes_list")
28def proposal_processes_list(request: Request) -> Response:
29 """
30 Get a list of all ProposalProcess objects
31 URL: proposal_processes
33 :param request: GET request
34 :return: Response with JSON-formatted array of ProposalProcess objects
35 """
36 proposal_processes = request.repo.proposal_process_repo.list_all()
37 response = []
38 for proposal_process in proposal_processes:
39 response.append(proposal_process.__json__())
40 return Response(status_code=HTTPStatus.OK, json_body=response)
43@view_config(route_name="proposal_process_by_id", renderer="json", permission="proposal_process_by_id")
44def proposal_process_by_id(request: Request) -> Response:
45 """
46 Get a ProposalProcess by id
47 URL: proposal_processes/{id}
49 :param request: GET request
50 :return: Response with JSON-formatted ProposalProcess
51 or 400 response (HTTPBadRequest) if the id was not an int
52 or 404 response (HTTPNotFound) if the ProposalProcess cannot be found
53 """
54 proposal_process = request.lookup(request.matchdict["id"], ProposalProcess)
55 return Response(status_code=HTTPStatus.OK, json_body=proposal_process.__json__())
58@view_config(route_name="proposal_process_delete", renderer="json", permission="proposal_process_delete")
59def proposal_process_delete(request: Request) -> Response:
60 """
61 Delete a ProposalProcess
62 URL: proposal_processes/{id}
64 :param request: DELETE request
65 :return: Response with JSON-formatted deleted ProposalProcess
66 or 400 response (HTTPBadRequest) id is not an int
67 or 404 response (HTTPNotFound) if the ProposalProcess cannot be found
68 """
69 proposal_process = request.lookup(request.matchdict["id"], ProposalProcess)
70 request.repo.proposal_process_repo.delete(proposal_process)
71 return Response(status_code=HTTPStatus.CREATED, json_body=proposal_process.__json__())