Skip to content

Commit

Permalink
Override _PromptData.model_dump to dump by alias by default
Browse files Browse the repository at this point in the history
Add unit test case to validate PromptData serialization
  • Loading branch information
NeonDaniel committed Jan 10, 2025
1 parent c201796 commit 1dea16a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
6 changes: 5 additions & 1 deletion neon_data_models/models/api/klat/socketio.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class GetPromptData(BaseModel):

class PromptData(BaseModel):
class _PromptData(BaseModel):
_id: str = Field(description="Unique ID for the prompt")
id: str = Field(alias="_id", description="Unique ID for the prompt")
is_completed: Literal['0', '1'] = Field(
description="'1' if a response to the prompt has been determined")
proposed_responses: Dict[str, str] = Field(
Expand All @@ -133,6 +133,10 @@ class _PromptData(BaseModel):
default=[],
description="List of subminds that participated in this prompt")

def model_dump(self, *args, **kwargs):
kwargs.setdefault('by_alias', True)
return BaseModel.model_dump(self, *args, **kwargs)

data: Union[_PromptData, List[_PromptData]] = Field(description="Prompt data")
receiver: str = Field(description="Nickname of user requesting prompt data")
cid: str = Field(description="Conversation ID associated with the prompt")
Expand Down
37 changes: 37 additions & 0 deletions tests/models/api/test_klat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# NEON AI (TM) SOFTWARE, Software Development Kit & Application Development System
# All trademark and other rights reserved by their respective owners
# Copyright 2008-2024 Neongecko.com Inc.
# BSD-3
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from unittest import TestCase


class TestKlat(TestCase):
def test_prompt_data(self):
from neon_data_models.models.api.klat.socketio import PromptData
test_object = PromptData._PromptData(_id="test_id",
is_completed='1')
self.assertIsInstance(test_object, PromptData._PromptData)
self.assertEqual(test_object,
PromptData._PromptData(**test_object.model_dump()))

0 comments on commit 1dea16a

Please sign in to comment.