Skip to content

Commit

Permalink
sysadmin as user for default bot (#1207)
Browse files Browse the repository at this point in the history
* Default bot components will be created with the sysadmin as user.

* Default bot components will be created with the sysadmin as user.

* Default bot components will be created with the sysadmin as user.

---------

Co-authored-by: Mahesh <mahesh.sattala@digite.com>
  • Loading branch information
maheshsattala and Mahesh committed May 17, 2024
1 parent 59c0746 commit ba322ef
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions kairon/shared/data/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ async def apply_template(self, template: Text, bot: Text, user: Text):
:raises: raise AppException
"""
use_case_path = os.path.join("./template/use-cases", secure_filename(template))
user = "sysadmin" if template in ["Hi-Hello", "Hi-Hello-GPT"] else user
if os.path.exists(use_case_path):
await self.save_from_path(path=use_case_path, bot=bot, user=user)
else:
Expand Down
62 changes: 62 additions & 0 deletions tests/integration_test/services_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18555,6 +18555,68 @@ def mock_reload_model(*args, **kwargs):
assert mock_reload_model.called_with[0][1] == "integ1@gmail.com"


def test_set_templates_with_sysadmin_as_user():
response = client.post(
f"/api/bot/{pytest.bot}/templates/use-case",
headers={"Authorization": pytest.token_type + " " + pytest.access_token},
json={"data": "Hi-Hello-GPT"},
)

actual = response.json()
assert actual["data"] is None
assert actual["error_code"] == 0
assert actual["message"] == "Data applied!"
assert actual["success"]

stories = Stories.objects(bot=pytest.bot)
stories = [{k: v for k, v in story.to_mongo().to_dict().items() if k not in ['_id', 'bot', 'timestamp']} for
story in stories]

assert stories == [
{'block_name': 'greet', 'start_checkpoints': ['STORY_START'], 'end_checkpoints': [],
'events': [{'name': 'greet', 'type': 'user', 'entities': []},
{'name': 'google_search_action', 'type': 'action'},
{'name': 'kairon_faq_action', 'type': 'action'}],
'user': 'sysadmin', 'status': True, 'template_type': 'CUSTOM'},
{'block_name': 'goodbye', 'start_checkpoints': ['STORY_START'], 'end_checkpoints': [],
'events': [{'name': 'goodbye', 'type': 'user', 'entities': []},
{'name': 'google_search_action', 'type': 'action'},
{'name': 'kairon_faq_action', 'type': 'action'}],
'user': 'sysadmin', 'status': True, 'template_type': 'CUSTOM'}
]

intents = Intents.objects(bot=pytest.bot)
intents = [{k: v for k, v in intent.to_mongo().to_dict().items() if k not in ['_id', 'bot', 'timestamp']} for
intent in intents]

assert intents == [
{'name': 'greet', 'user': 'sysadmin', 'status': True, 'is_integration': False, 'use_entities': False},
{'name': 'goodbye', 'user': 'sysadmin', 'status': True, 'is_integration': False, 'use_entities': False},
{'name': 'nlu_fallback', 'user': 'sysadmin', 'status': True, 'is_integration': False, 'use_entities': False},
{'name': 'restart', 'user': 'sysadmin', 'status': True, 'is_integration': False, 'use_entities': True},
{'name': 'back', 'user': 'sysadmin', 'status': True, 'is_integration': False, 'use_entities': True},
{'name': 'out_of_scope', 'user': 'sysadmin', 'status': True, 'is_integration': False, 'use_entities': True},
{'name': 'session_start', 'user': 'sysadmin', 'status': True, 'is_integration': False, 'use_entities': True}
]

training_examples = TrainingExamples.objects(bot=pytest.bot)
training_examples = [{k: v for k, v in example.to_mongo().to_dict().items() if k not in
['_id', 'bot', 'timestamp']} for example in training_examples]

assert training_examples == [
{'intent': 'goodbye', 'text': 'bye', 'user': 'sysadmin', 'status': True},
{'intent': 'goodbye', 'text': 'goodbye', 'user': 'sysadmin', 'status': True},
{'intent': 'goodbye', 'text': 'see you around', 'user': 'sysadmin', 'status': True},
{'intent': 'goodbye', 'text': 'see you later', 'user': 'sysadmin', 'status': True},
{'intent': 'greet', 'text': 'hey', 'user': 'sysadmin', 'status': True},
{'intent': 'greet', 'text': 'hello', 'user': 'sysadmin', 'status': True},
{'intent': 'greet', 'text': 'hi', 'user': 'sysadmin', 'status': True},
{'intent': 'greet', 'text': 'good morning', 'user': 'sysadmin', 'status': True},
{'intent': 'greet', 'text': 'good evening', 'user': 'sysadmin', 'status': True},
{'intent': 'greet', 'text': 'hey there', 'user': 'sysadmin', 'status': True}
]


def test_add_channel_config(monkeypatch):
monkeypatch.setitem(
Utility.environment["model"]["agent"], "url", "http://localhost:5056"
Expand Down

0 comments on commit ba322ef

Please sign in to comment.