Skip to content

Commit

Permalink
Code coverage issue
Browse files Browse the repository at this point in the history
  • Loading branch information
spatade committed Oct 10, 2023
1 parent e76dbdb commit d0f8fc6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
4 changes: 3 additions & 1 deletion tests/testing_data/channel_data/channel_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@
"telegram_button_op_one": {"inline_keyboard": [[{"text": "One", "callback_data": "single button is clicked"}]]},
"telegram_button_op_multi": {"inline_keyboard": [[{"text": "Veg", "callback_data": "Vegetables only"},
{"text": "Non-veg", "callback_data": "fish food served"},
{"text": "Desert", "callback_data": "Only Desert food"}]]}
{"text": "Desert", "callback_data": "Only Desert food"}]]},

"button_one_exception": [{"type":"button","value":"single button is clicked","id":"5"},
{"type":"paragraph","children":[{"text":""}]}]
}
21 changes: 18 additions & 3 deletions tests/unit_test/utility_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from kairon.shared.models import TemplateType
from kairon.shared.utils import Utility, MailUtility
from kairon.shared.verification.email import QuickEmailVerification
from kairon.chat.converters.channels.telegram import TelegramResponseConverter


class TestUtility:
Expand Down Expand Up @@ -2751,7 +2752,6 @@ def test_is_picklable_for_mongo_failure(self):
def test_button_transformer_telegram_single_button(self):
json_data = json.load(open("tests/testing_data/channel_data/channel_data.json"))
input_json = json_data.get("button_one")
from kairon.chat.converters.channels.telegram import TelegramResponseConverter
telegram = TelegramResponseConverter("button", "telegram")
response = telegram.button_transformer(input_json)
expected_output = json_data.get("telegram_button_op_one")
Expand All @@ -2760,8 +2760,23 @@ def test_button_transformer_telegram_single_button(self):
def test_button_transformer_telegram_multi_buttons(self):
json_data = json.load(open("tests/testing_data/channel_data/channel_data.json"))
input_json = json_data.get("button_three")
from kairon.chat.converters.channels.telegram import TelegramResponseConverter
telegram = TelegramResponseConverter("button", "telegram")
response = telegram.button_transformer(input_json)
expected_output = json_data.get("telegram_button_op_multi")
assert expected_output == response
assert expected_output == response

@pytest.mark.asyncio
async def test_button_transformer_telegram_messageConverter(self):
json_data = json.load(open("tests/testing_data/channel_data/channel_data.json"))
input_json = json_data.get("button_three")
telegram = ConverterFactory.getConcreteInstance("button", "telegram")
response = await telegram.messageConverter(input_json)
expected_output = json_data.get("telegram_button_op_multi")
assert expected_output == response

def test_button_transformer_telegram_exception(self):
json_data = json.load(open("tests/testing_data/channel_data/channel_data.json"))
input_json = json_data.get("button_one_exception")
telegram = TelegramResponseConverter("button", "telegram")
with pytest.raises(Exception):
telegram.button_transformer(input_json)

0 comments on commit d0f8fc6

Please sign in to comment.