Skip to content
Snippets Groups Projects
Commit ac3de0a3 authored by Britney Tong's avatar Britney Tong
Browse files

fix(q): test case failures

parent 278aad18
No related branches found
No related tags found
2 merge requests!50Q integration bt,!45feat(q): auto MR review
import json
import boto3
from botocore.exceptions import ClientError
from fastapi import HTTPException, status
......@@ -164,9 +166,7 @@ class AmazonQClient:
print("DEBUG [AmazonQClient]: send_event payload", payload)
print("DEBUG [AmazonQClient]: event_id", event_id)
try:
# DELETE ME
if event_id == "Quick Action":
self._send_event(event_id, payload)
self._send_event(event_id, payload)
except ClientError as ex:
if ex.__class__.__name__ == "AccessDeniedException":
return self._retry_send_event(ex, event_request.code, payload, event_id)
......@@ -201,7 +201,6 @@ class AmazonQClient:
)
def _send_message(self, payload):
print("DEBUG [AmazonQClient]: _send_message payload", payload)
return self.client.send_message(
message=payload["message"], conversationId=payload["conversation_id"]
)
......@@ -242,14 +241,17 @@ class AmazonQClient:
payload = event_request.payload
if payload.__class__.__name__ == "EventHookPayload":
return safe_process_json(
payload.data, EXCLUDE_EVENT_ATTRIBUTES, ignore_null=True
updated_payload = safe_process_json(
payload.model_dump(exclude_none=True),
EXCLUDE_EVENT_ATTRIBUTES,
ignore_null=True,
)
return json.dumps(updated_payload)
elif payload.__class__.__name__ in [
"EventMergeRequestPayload",
"EventIssuePayload",
]:
return payload.model_dump(exclude_none=True)
return payload.model_dump_json(exclude_none=True)
request_log.warn("Unknown event payload, ignore")
return None
......@@ -7,11 +7,12 @@ as various error conditions using mock objects to simulate AWS services.
"""
import json
from typing import Dict
from unittest.mock import Mock, patch
import pytest
from botocore.exceptions import ClientError, ParamValidationError
from botocore.exceptions import ClientError
from fastapi import HTTPException
from ai_gateway.api.auth_utils import StarletteUser
......@@ -478,20 +479,23 @@ class TestAmazonQClient:
(
"event_request_hook",
{
"project_id": 1,
"ref": "refs/heads/main",
"checkout_sha": "abc123",
"user_id": 1,
"user_name": "Test User",
"repository": {
"name": "test-repo",
"url": "git@gitlab.com:group/project.git",
"description": "test repository",
"homepage": "https://gitlab.com/group/project",
},
"project": {
"id": 20,
"name": "Project1",
"source": "system_hook",
"data": {
"project_id": 1,
"ref": "refs/heads/main",
"checkout_sha": "abc123",
"user_id": 1,
"user_name": "Test User",
"repository": {
"name": "test-repo",
"url": "git@gitlab.com:group/project.git",
"description": "test repository",
"homepage": "https://gitlab.com/group/project",
},
"project": {
"id": 20,
"name": "Project1",
},
},
},
["object_kind"], # Exclude 'object_kind' from the result
......@@ -500,21 +504,24 @@ class TestAmazonQClient:
(
"event_request_hook",
{
"object_kind": "merge_request",
"project_id": 1,
"ref": "refs/heads/main",
"checkout_sha": "abc123",
"user_id": 1,
"user_name": "Test User",
"repository": {
"name": "test-repo",
"url": "git@gitlab.com:group/project.git",
"description": "test repository",
"homepage": "https://gitlab.com/group/project",
},
"project": {
"id": 20,
"name": "Project1",
"source": "system_hook",
"data": {
"object_kind": "merge_request",
"project_id": 1,
"ref": "refs/heads/main",
"checkout_sha": "abc123",
"user_id": 1,
"user_name": "Test User",
"repository": {
"name": "test-repo",
"url": "git@gitlab.com:group/project.git",
"description": "test repository",
"homepage": "https://gitlab.com/group/project",
},
"project": {
"id": 20,
"name": "Project1",
},
},
},
[], # No exclusions
......@@ -592,6 +599,7 @@ class TestAmazonQClient:
# Process the payload
result = amazon_q_client._get_payload(event_request)
result = json.loads(result) if result else result
# Verify the result
assert result == expected_result
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment