Skip to content
GitLab
Next
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
A
AI Gateway Community Fork
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
GitLab Community
ModelOps
AI Assisted (formerly Applied ML)
Code Suggestions
AI Gateway Community Fork
Commits
ac3de0a3
Commit
ac3de0a3
authored
2 weeks ago
by
Britney Tong
Browse files
Options
Downloads
Patches
Plain Diff
fix(q): test case failures
parent
278aad18
No related branches found
No related tags found
2 merge requests
!50
Q integration bt
,
!45
feat(q): auto MR review
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ai_gateway/integrations/amazon_q/client.py
+9
-7
9 additions, 7 deletions
ai_gateway/integrations/amazon_q/client.py
tests/integrations/amazon_q/test_client.py
+38
-30
38 additions, 30 deletions
tests/integrations/amazon_q/test_client.py
with
47 additions
and
37 deletions
ai_gateway/integrations/amazon_q/client.py
+
9
−
7
View file @
ac3de0a3
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
This diff is collapsed.
Click to expand it.
tests/integrations/amazon_q/test_client.py
+
38
−
30
View file @
ac3de0a3
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment