Skip to content

Commit aa3d770

Browse files
authored
Merge pull request #715 from asimurka/fix_feedbacks_400_401_swagger_doc
LCORE-759: Updated response dicts for feedback endpoints
2 parents 2f071fd + 8eb46d4 commit aa3d770

File tree

5 files changed

+80
-8
lines changed

5 files changed

+80
-8
lines changed

src/app/endpoints/feedback.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
feedback_status_lock = threading.Lock()
3131

3232
# Response for the feedback endpoint
33-
feedback_response: dict[int | str, dict[str, Any]] = {
33+
feedback_post_response: dict[int | str, dict[str, Any]] = {
3434
200: {
3535
"description": "Feedback received and stored",
3636
"model": FeedbackResponse,
@@ -49,6 +49,32 @@
4949
},
5050
}
5151

52+
feedback_put_response: dict[int | str, dict[str, Any]] = {
53+
200: {
54+
"description": "Feedback status successfully updated",
55+
"model": FeedbackStatusUpdateResponse,
56+
},
57+
400: {
58+
"description": "Missing or invalid credentials provided by client",
59+
"model": UnauthorizedResponse,
60+
},
61+
401: {
62+
"description": "Missing or invalid credentials provided by client",
63+
"model": UnauthorizedResponse,
64+
},
65+
403: {
66+
"description": "Client does not have permission to access resource",
67+
"model": ForbiddenResponse,
68+
},
69+
}
70+
71+
feedback_get_response: dict[int | str, dict[str, Any]] = {
72+
200: {
73+
"description": "Feedback status successfully retrieved",
74+
"model": StatusResponse,
75+
}
76+
}
77+
5278

5379
def is_feedback_enabled() -> bool:
5480
"""
@@ -83,7 +109,7 @@ async def assert_feedback_enabled(_request: Request) -> None:
83109
)
84110

85111

86-
@router.post("", responses=feedback_response)
112+
@router.post("", responses=feedback_post_response)
87113
@authorize(Action.FEEDBACK)
88114
async def feedback_endpoint_handler(
89115
feedback_request: FeedbackRequest,
@@ -161,7 +187,7 @@ def store_feedback(user_id: str, feedback: dict) -> None:
161187
logger.info("Feedback stored successfully at %s", feedback_file_path)
162188

163189

164-
@router.get("/status")
190+
@router.get("/status", responses=feedback_get_response)
165191
def feedback_status() -> StatusResponse:
166192
"""
167193
Handle feedback status requests.
@@ -179,7 +205,7 @@ def feedback_status() -> StatusResponse:
179205
)
180206

181207

182-
@router.put("/status")
208+
@router.put("/status", responses=feedback_put_response)
183209
@authorize(Action.ADMIN)
184210
async def update_feedback_status(
185211
feedback_update_request: FeedbackStatusUpdateRequest,

src/models/responses.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,3 +1140,32 @@ def __init__(self, user_id: str, resource: str, resource_id: str):
11401140
]
11411141
}
11421142
}
1143+
1144+
1145+
class InvalidFeedbackStoragePathResponse(AbstractErrorResponse):
1146+
"""500 Internal Error - Invalid feedback storage path."""
1147+
1148+
def __init__(self, storage_path: str):
1149+
"""Initialize an InvalidFeedbackStoragePathResponse for feedback storage failures."""
1150+
super().__init__(
1151+
detail=DetailModel(
1152+
response="Failed to store feedback",
1153+
cause=f"Invalid feedback storage path: {storage_path}",
1154+
)
1155+
)
1156+
1157+
model_config = {
1158+
"json_schema_extra": {
1159+
"examples": [
1160+
{
1161+
"detail": {
1162+
"response": "Failed to store feedback",
1163+
"cause": (
1164+
"Invalid feedback storage path: "
1165+
"/var/app/data/feedbacks/invalid_path"
1166+
),
1167+
}
1168+
}
1169+
]
1170+
}
1171+
}

tests/e2e/features/environment.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ def before_feature(context: Context, feature: Feature) -> None:
145145
restart_container("lightspeed-stack")
146146

147147
if "Feedback" in feature.tags:
148+
context.hostname = os.getenv("E2E_LSC_HOSTNAME", "localhost")
149+
context.port = os.getenv("E2E_LSC_PORT", "8080")
148150
context.feedback_conversations = []
149151

150152

@@ -156,7 +158,6 @@ def after_feature(context: Context, feature: Feature) -> None:
156158
remove_config_backup(context.default_config_backup)
157159

158160
if "Feedback" in feature.tags:
159-
print(context.feedback_conversations)
160161
for conversation_id in context.feedback_conversations:
161162
url = f"http://{context.hostname}:{context.port}/v1/conversations/{conversation_id}"
162163
headers = context.auth_headers if hasattr(context, "auth_headers") else {}

tests/e2e/features/feedback.feature

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,25 @@ Feature: feedback endpoint API tests
260260
And The body of the response is the following
261261
"""
262262
{
263-
"detail": "No Authorization header found"
263+
"detail": {
264+
"cause": "Missing or invalid credentials provided by client",
265+
"response": "Unauthorized"
266+
}
267+
}
268+
"""
269+
270+
Scenario: Check if update feedback status endpoint is not working when not authorized
271+
Given The system is in default state
272+
And I remove the auth header
273+
When The feedback is enabled
274+
Then The status code of the response is 400
275+
And The body of the response is the following
276+
"""
277+
{
278+
"detail": {
279+
"cause": "Missing or invalid credentials provided by client",
280+
"response": "Unauthorized"
281+
}
264282
}
265283
"""
266284

tests/e2e/features/steps/feedback.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def enable_feedback(context: Context) -> None:
1717
assert context is not None
1818
payload = {"status": True}
1919
access_feedback_put_endpoint(context, payload)
20-
assert context.response.status_code == 200, "Enabling feedback was unsuccessful"
2120

2221

2322
@step("The feedback is disabled") # type: ignore
@@ -26,7 +25,6 @@ def disable_feedback(context: Context) -> None:
2625
assert context is not None
2726
payload = {"status": False}
2827
access_feedback_put_endpoint(context, payload)
29-
assert context.response.status_code == 200, "Disabling feedback was unsuccessful"
3028

3129

3230
@when("I update feedback status with") # type: ignore

0 commit comments

Comments
 (0)