Skip to content

Commit 99638da

Browse files
committed
More test fixes
1 parent 5ac8709 commit 99638da

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

ansible_ai_connect/ai/api/serializers.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -654,22 +654,17 @@ class ExplanationRoleRequestSerializer(Metadata):
654654
label="Files",
655655
help_text="A list of role files to be explained.",
656656
)
657-
role_name = serializers.CharField(
657+
roleName = serializers.CharField(
658658
required=True,
659659
label="Role name",
660660
help_text="The name of the role.",
661661
)
662-
model_id = serializers.CharField(required=False, allow_blank=True, default="")
663-
focus_on_file = serializers.CharField(required=False, allow_blank=True, default="")
662+
model = serializers.CharField(required=False, allow_blank=True, default="")
663+
focusOnFile = serializers.CharField(required=False, allow_blank=True, default="")
664664

665665
def validate(self, attrs):
666-
attrs = super().validate(attrs)
667-
668-
if "model_id" in attrs and not attrs["model_id"].strip():
669-
del attrs["model_id"]
670-
if "focus_on_file" in attrs and not attrs["focus_on_file"].strip():
671-
del attrs["focus_on_file"]
672-
return attrs
666+
data = super().validate(attrs)
667+
return data
673668

674669

675670
class ContentMatchRequestSerializer(Metadata):

ansible_ai_connect/ai/api/tests/test_role_explanation_view.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,21 @@ class TestRoleExplanationView(
3232
APIVersionTestCaseBase, WisdomAppsBackendMocking, WisdomServiceAPITestCaseBase
3333
):
3434
def test_ok(self):
35-
payload = {}
35+
payload = {
36+
"files": [
37+
{
38+
"path": "dummy_path",
39+
"content": "dummy_content",
40+
"file_type": "dummy_file_type",
41+
}
42+
],
43+
"roleName": "dummy_role",
44+
}
3645
self.client.force_authenticate(user=self.user)
3746
r = self.client.post(self.api_version_reverse("explanations/role"), payload, format="json")
3847
self.assertEqual(r.status_code, HTTPStatus.OK)
3948
self.assertIsNotNone(r.data)
40-
self.assertEqual(r.data, {})
49+
self.assertEqual(r.data["format"], "markdown")
4150

4251
def test_unauthorized(self):
4352
payload = {}

ansible_ai_connect/ai/api/versions/v1/ai/tests/test_role_explanation_view.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from ansible_ai_connect.ai.api.versions.v1.test_base import API_VERSION
1919

2020

21-
class TestRoleGenerationViewVersion1(TestRoleExplanationView):
21+
class TestRoleExplanationViewVersion1(TestRoleExplanationView):
2222
api_version = API_VERSION
2323

2424
def test_explanation_role_version_url(self):

ansible_ai_connect/ai/api/views.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -861,15 +861,16 @@ class ExplanationRole(AACSAPIView):
861861
summary="Inline code suggestions",
862862
)
863863
def post(self, request) -> Response:
864-
self.event.explanationId = self.validated_data["explanationId"]
865864
llm: ModelPipelineRoleExplanation = apps.get_app_config("ai").get_model_pipeline(
866865
ModelPipelineRoleExplanation
867866
)
868867
explanation = llm.invoke(
869868
RoleExplanationParameters.init(
870869
request=request,
871-
content=self.validated_data["content"],
872-
explanation_id=self.validated_data["explanationId"],
870+
files=self.validated_data["files"],
871+
role_name=self.validated_data["roleName"],
872+
model_id=self.validated_data["model"],
873+
focus_on_file=self.validated_data["focusOnFile"],
873874
)
874875
)
875876

@@ -882,7 +883,6 @@ def post(self, request) -> Response:
882883
answer = {
883884
"content": anonymized_explanation,
884885
"format": "markdown",
885-
"explanationId": self.validated_data["explanationId"],
886886
}
887887

888888
return Response(

0 commit comments

Comments
 (0)