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

Fix status code in GET aliases service #1881

Merged
merged 2 commits into from
Feb 22, 2025
Merged
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
1 change: 1 addition & 0 deletions news/1862.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Correct the HTTP response status code to `200 OK` from `201 Create` for the `aliases` GET service. @Faakhir30
6 changes: 3 additions & 3 deletions src/plone/restapi/services/aliases/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def reply_item(self):
context_path = "/".join(self.context.getPhysicalPath())
redirects = storage.redirects(context_path)
aliases = [deroot_path(alias) for alias in redirects]
self.request.response.setStatus(201)
self.request.response.setStatus(200)
self.request.response.setHeader("Content-Type", "application/json")
return [{"path": alias} for alias in aliases], len(aliases)

Expand All @@ -42,7 +42,7 @@ def reply_root(self):
for redirect in redirects:
del redirect["redirect"]
redirect["datetime"] = datetimelike_to_iso(redirect["datetime"])
self.request.response.setStatus(201)
self.request.response.setStatus(200)

self.request.form["b_start"] = "0"
self.request.form["b_size"] = "1000000"
Expand All @@ -61,7 +61,7 @@ def reply_root_csv(self):
for redirect in redirects:
del redirect["redirect"]
redirect["datetime"] = datetimelike_to_iso(redirect["datetime"])
self.request.response.setStatus(201)
self.request.response.setStatus(200)

self.request.form["b_start"] = "0"
self.request.form["b_size"] = "1000000"
Expand Down
2 changes: 1 addition & 1 deletion src/plone/restapi/tests/http-examples/aliases_get.resp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
HTTP/1.1 201 Created
HTTP/1.1 200 OK
Content-Type: application/json

{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
HTTP/1.1 201 Created
HTTP/1.1 200 OK
Content-Type: application/json

{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
HTTP/1.1 201 Created
HTTP/1.1 200 OK
Content-Type: application/json

{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
HTTP/1.1 201 Created
HTTP/1.1 200 OK
Content-Type: text/csv; charset=utf-8

old path,new path,datetime,manual
Expand Down
12 changes: 6 additions & 6 deletions src/plone/restapi/tests/test_services_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_alias_non_root(self):

# Verify alias exists
response = self.api_session.get("/front-page/@aliases")
self.assertEqual(response.status_code, 201)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.json()["items"]), 1)

def test_alias_add_invalid_datetime(self):
Expand All @@ -66,7 +66,7 @@ def test_alias_add_invalid_datetime(self):
response = self.api_session.post("/@aliases", json=data)
self.assertEqual(response.status_code, 204)
response = self.api_session.get("/@aliases")
self.assertEqual(response.status_code, 201)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.json()["items"]), 2)

def test_alias_add_invalid_path(self):
Expand All @@ -76,7 +76,7 @@ def test_alias_add_invalid_path(self):
response = self.api_session.post("/@aliases", json=data)
self.assertEqual(response.status_code, 400)
response = self.api_session.get("/@aliases")
self.assertEqual(response.status_code, 201)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.json()["items"]), 0)

def test_duplicate_alias(self):
Expand Down Expand Up @@ -108,7 +108,7 @@ def test_alias_csv_upload(self):
self.assertEqual(response.status_code, 204)
self.assertEqual(response.content, b"")
response = self.api_session.get("/@aliases")
self.assertEqual(response.status_code, 201)
self.assertEqual(response.status_code, 200)
self.assertEqual(
response.json().get("items"),
[
Expand Down Expand Up @@ -136,7 +136,7 @@ def test_alias_csv_download(self):
self.api_session.post("/@aliases", json=data)
headers = {"Accept": "text/csv"}
response = self.api_session.get("/@aliases", headers=headers)
self.assertEqual(response.status_code, 201)
self.assertEqual(response.status_code, 200)
self.assertIn("Content-Disposition", response.headers)
self.assertEqual(response.headers["Content-Type"], "text/csv; charset=utf-8")
content = b"old path,new path,datetime,manual\r\n/alias-page,/front-page,2022/01/01 00:00:00 GMT+0,True\r\n"
Expand All @@ -158,5 +158,5 @@ def test_alias_delete(self):
self.assertEqual(response.status_code, 204)

response = self.api_session.get("/@aliases")
self.assertEqual(response.status_code, 201)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.json()["items"]), 0)