Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

singletone action upload in appendmode fix #1609

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions kairon/shared/data/action_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ def deserialize(bot: str, user: str, actions: Optional[dict] = None, other_colle
elif action_info.get('single_instance'):
if overwrite:
filtered_actions[action_type] = actions[action_type]
else:
existing_action = action_info.get("db_model").objects(bot=bot).first()
if not existing_action:
filtered_actions[action_type] = actions[action_type]
else:
new_actions = []
action_names = []
Expand Down
35 changes: 34 additions & 1 deletion tests/unit_test/data_processor/action_serializer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from mongoengine import connect

from kairon import Utility
from kairon.shared.actions.data_objects import Actions, HttpActionConfig, PyscriptActionConfig
from kairon.shared.actions.data_objects import Actions, HttpActionConfig, PyscriptActionConfig, LiveAgentActionConfig
from kairon.shared.actions.models import ActionType, ActionParameterType, DbActionOperationType
from kairon.shared.callback.data_objects import CallbackConfig
from kairon.shared.data.data_validation import DataValidation
Expand Down Expand Up @@ -588,6 +588,39 @@ def test_action_serializer_deserialize():
assert callback.name == "cb1"


def test_action_serializer_deserialize_single_instance_append():
bot = "my_test_bot"
user = "test_user@test_user.com"

actions = {
"live_agent_action": [
{
'name': 'live_agent_action',
}
]
}

other_collections = {}

# Case : action doesn't exist
ActionSerializer.deserialize(bot, user, actions, other_collections)

actions_added = Actions.objects(bot=bot, user=user)
action_names = [action.name for action in actions_added]
print(action_names)
assert len(list(actions_added)) == 3
names = [action.name for action in actions_added]
assert "live_agent_action" in names

# Case : action already exists

ActionSerializer.deserialize(bot, user, actions, other_collections)
assert len(list(actions_added)) == 3
la_action_count = Actions.objects(bot=bot, user=user, name="live_agent_action").count()
assert la_action_count == 1
live_agent_action = LiveAgentActionConfig.objects(bot=bot, user=user).get()
assert live_agent_action.name == "live_agent_action"

def test_action_serializer_deserialize_overwrite():
bot = "my_test_bot"
user = "test_user@test_user.com"
Expand Down
Loading