Closed mlamina closed 2 months ago
The following test failed:
The test is failing because the list_tasks
endpoint is returning a 405 Method Not Allowed
status code. This indicates that the HTTP method used in the request is not allowed for this endpoint.
The changes in the PR added a new list_tasks
endpoint in api/views.py
and updated the URL configuration in api/urls.py
:
# api/urls.py
urlpatterns = [
path("tasks/", views.create_task, name="create_task"),
path("tasks/<uuid:pk>/", views.get_task, name="get_task"),
path("tasks/", views.list_tasks, name="list_tasks"),
path("openapi.yaml", SpectacularAPIView.as_view(), name="schema"),
]
The issue is due to the duplicate path("tasks/")
in the URL configuration. The first occurrence maps to the create_task
view, which only allows POST requests, causing the GET request to fail. To fix this, you should combine the create_task
and list_tasks
views into a single path with different allowed methods:
# api/urls.py
urlpatterns = [
path("tasks/", views.create_task, name="create_task", methods=['POST']),
path("tasks/", views.list_tasks, name="list_tasks", methods=['GET']),
path("tasks/<uuid:pk>/", views.get_task, name="get_task"),
path("openapi.yaml", SpectacularAPIView.as_view(), name="schema"),
]
Alternatively, you can use a class-based view to handle both methods in a single view.
/pilot Please apply the fix
The following tests failed:
test_create_task_via_api
test_create_task_via_api_with_pr_number
test_create_task_via_api__repo_not_found
test_image_upload
test_create_task_via_api__branch_setting
test_list_tasks
The tests are failing due to a TypeError
caused by the use of the methods
argument in the path
function in api/urls.py
. The path
function does not accept a methods
argument.
The changes in the PR added the methods
argument to the path
function in api/urls.py
:
# api/urls.py
urlpatterns = [
path("tasks/", views.create_task, name="create_task", methods=['POST']),
path("tasks/", views.list_tasks, name="list_tasks", methods=['GET']),
path("tasks/<uuid:pk>/", views.get_task, name="get_task"),
path("openapi.yaml", SpectacularAPIView.as_view(), name="schema"),
]
To fix this issue, you should remove the methods
argument from the path
function and use the @api_view
decorator in the views to specify the allowed methods:
# api/urls.py
urlpatterns = [
path("tasks/", views.create_task, name="create_task"),
path("tasks/", views.list_tasks, name="list_tasks"),
path("tasks/<uuid:pk>/", views.get_task, name="get_task"),
path("openapi.yaml", SpectacularAPIView.as_view(), name="schema"),
]
Ensure that the @api_view
decorator in views.py
specifies the allowed methods for each view:
# api/views.py
@api_view(["POST"])
@permission_classes([HasUserAPIKey])
def create_task(request):
# ...
@api_view(["GET"])
@permission_classes([HasUserAPIKey])
def list_tasks(request):
# ...
The refactoring of the list_tasks
and get_task
function-based views into a single model-based view (TaskView
) has been successfully completed. The URL configuration has also been updated accordingly to use this new class-based view for handling task-related endpoints.
This change should streamline the handling of task-related requests and make the codebase cleaner and more maintainable.
This PR introduces a new endpoint for listing tasks and refactors the task-related views for better maintainability and functionality.
Changes Made
API Enhancements
TaskViewSet
class-based view to handle task creation and listing.TASK_LIST_LIMIT
constant to limit the number of tasks returned by the list endpoint.api/urls.py
to use the newTaskViewSet
for task-related endpoints.Testing Improvements
api/tests/test_api.py
.Documentation and Configuration
.pilot-hints.md
with information about the API structure..github/workflows/unit_tests.yml
to use the latestpr-pilot-cli
version.prompts/create_api_endpoint.md.jinja2
for creating API endpoints.Miscellaneous
1.4.5
inversion.txt
.These changes enhance the API's functionality and improve the overall code quality and maintainability of the project.