Skip to content

Commit

Permalink
Support for delete command without polish characters
Browse files Browse the repository at this point in the history
  • Loading branch information
kutzowsky committed Nov 19, 2024
1 parent 157c57f commit fc2d77e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/commandhandlers/confirmationshandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def handle_message_content(sender, message_content):
handling_functions = {
'dodaj': _handle_add_or_delete,
'usuń': _handle_add_or_delete,
'usun': _handle_add_or_delete,
'wyslano': _handle_sent_confirmation,
'wysłano': _handle_sent_confirmation,
'nadano': _handle_sent_confirmation,
Expand Down
3 changes: 2 additions & 1 deletion src/commandhandlers/userdatahandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
def handle_message_content(sender, message_content):
handling_functions = {
'dodaj': _handle_add,
'usuń': _handle_delete
'usuń': _handle_delete,
'usun': _handle_delete
}

command = messageparser.get_command_from(message_content).lower()
Expand Down
19 changes: 18 additions & 1 deletion src/tests/test_confirmations_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ def test_when_message_has_delete_command_should_not_try_to_delete_user(mocker):
delete_user_data_mock.assert_not_called()


@pytest.mark.parametrize('message', [
'usuń',
'usun',
'USUŃ',
'USUN',
'Usuń',
'usun:'
])
def test_when_delete_command_synonym_was_provided_should_also_recognize_it(message, mocker):
user = 'someuser'
delete_user_data_mock = mocker.patch('src.dal.datamanager.delete_user_data')

confirmationshandler.handle_message_content(user, message)

delete_user_data_mock.assert_not_called()


@pytest.mark.parametrize('message', [
'wyslano',
'wysłano',
Expand Down Expand Up @@ -337,4 +354,4 @@ def test_when_received_command_synonym_was_provided_should_also_recognize_it(mes

confirmationshandler.handle_message_content(user, message)

save_received_confirmation_mock.assert_called_once()
save_received_confirmation_mock.assert_called_once()
21 changes: 20 additions & 1 deletion src/tests/test_user_data_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_when_there_is_error_with_saving_user_data_should_return_error_text(mock
'Dodaj',
'dodaj:'
])
def test_when_command_synonym_was_provided_should_also_recognize_it(message, mocker):
def test_when_add_command_synonym_was_provided_should_also_recognize_it(message, mocker):
user = 'someuser'
save_user_data_mock = mocker.patch('src.dal.datamanager.save_user_data')

Expand Down Expand Up @@ -123,3 +123,22 @@ def test_when_unknown_user_sends_delete_command_should_not_try_to_delete_data_an

assert answer == expected_answer
delete_user_data_mock.assert_not_called()


@pytest.mark.parametrize('message', [
'usuń',
'usun',
'USUŃ',
'USUN',
'Usuń',
'usun:'
])
def test_when_delete_command_synonym_was_provided_should_also_recognize_it(message, mocker):
user = 'someuser'
delete_user_data_mock = mocker.patch('src.dal.datamanager.delete_user_data')
is_participant_mock = mocker.patch('src.dal.datamanager.is_participant')
is_participant_mock.return_value = True

userdatahandler.handle_message_content(user, message)

delete_user_data_mock.assert_called_once()

0 comments on commit fc2d77e

Please sign in to comment.