Skip to content

Commit

Permalink
Fix Delete Slot Mapping api and added related test cases (#1602)
Browse files Browse the repository at this point in the history
  • Loading branch information
maheshsattala authored Nov 22, 2024
1 parent 6d9901a commit 82e9497
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kairon/api/app/routers/bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ async def delete_slot_mapping(mapping_id: str = Path(description="Slot Mapping i
"""
Deletes a slot mapping.
"""
mongo_processor.delete_single_slot_mapping(mapping_id, user=current_user.get_user())
mongo_processor.delete_singular_slot_mapping(mapping_id)
return Response(message='Slot mapping deleted')


Expand Down
70 changes: 70 additions & 0 deletions tests/integration_test/services_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21438,6 +21438,76 @@ def test_add_http_action_case_insensitivity():
assert actual["success"]


def test_add_slot_mapping_1():
response = client.post(
f"/api/bot/{pytest.bot}/slots",
json={"name": "name_slot", "type": "text"},
headers={"Authorization": pytest.token_type + " " + pytest.access_token},
)

actual = response.json()
assert actual["message"] == "Slot added successfully!"
assert actual["success"]
assert actual["error_code"] == 0
response = client.post(
f"/api/bot/{pytest.bot}/slots/mapping",
json={
"slot": "name_slot",
"mapping": {"type": "from_text", "value": "user", "entity": "name_slot"},
},
headers={"Authorization": pytest.token_type + " " + pytest.access_token},
)
actual = response.json()
assert actual["message"] == "Slot mapping added"
assert actual["success"]
assert actual["error_code"] == 0


def test_delete_slot_mapping_1():
response = client.get(
f"/api/bot/{pytest.bot}/slots/mapping",
headers={"Authorization": pytest.token_type + " " + pytest.access_token},
)
actual = response.json()
assert actual["success"]
for slot_mapping in actual["data"]:
if slot_mapping['slot'] == "name_slot":
mapping_id = slot_mapping['mapping'][0]['_id']
break
assert len(actual["data"]) == 12

response = client.delete(
f"/api/bot/{pytest.bot}/slots/mapping_id/{mapping_id}",
headers={"Authorization": pytest.token_type + " " + pytest.access_token},
)
actual = response.json()
assert actual["success"]
assert actual["message"] == "Slot mapping deleted"
assert actual["error_code"] == 0
assert not actual["data"]

response = client.get(
f"/api/bot/{pytest.bot}/slots/mapping",
headers={"Authorization": pytest.token_type + " " + pytest.access_token},
)
actual = response.json()
assert actual["success"]
assert actual["error_code"] == 0
assert len(actual["data"]) == 11


def test_delete_slot_mapping_does_not_exist():
response = client.delete(
f"/api/bot/{pytest.bot}/slots/mapping_id/{pytest.bot}",
headers={"Authorization": pytest.token_type + " " + pytest.access_token},
)
actual = response.json()
assert not actual["success"]
assert not actual["data"]
assert actual["message"] == 'No slot mapping exists'
assert actual["error_code"] == 422


def test_get_ui_config_empty():
response = client.get(
url=f"/api/account/config/ui",
Expand Down

0 comments on commit 82e9497

Please sign in to comment.