11import sys
22import pytest
3- from unittest .mock import patch
3+ from unittest .mock import Mock , patch
44from botocore .exceptions import ClientError
55
66
77@patch ("app.services.dynamo.store_state_information" )
88@patch ("app.services.dynamo.get_state_information" )
9- def test_store_feedback (mock_get_state_information , mock_store_state_information , mock_env ):
9+ @patch ("app.services.slack.get_friendly_channel_name" )
10+ def test_store_feedback (
11+ mock_get_friendly_channel_name , mock_get_state_information , mock_store_state_information , mock_env
12+ ):
1013 """Test feedback storage functionality"""
1114 # set up mocks
15+ mock_client = Mock ()
1216
1317 # delete and import module to test
1418 if "app.slack.slack_events" in sys .modules :
1519 del sys .modules ["app.slack.slack_events" ]
1620 from app .slack .slack_events import store_feedback
1721
1822 # perform operation
19- store_feedback ("test-conversation" , "positive" , "U123" , "C123" )
23+ store_feedback ("test-conversation" , "positive" , "U123" , "C123" , mock_client )
2024
2125 # assertions
2226 mock_store_state_information .assert_called_once ()
@@ -27,17 +31,23 @@ def test_store_feedback(mock_get_state_information, mock_store_state_information
2731
2832@patch ("app.services.dynamo.store_state_information" )
2933@patch ("app.services.dynamo.get_state_information" )
30- def test_feedback_storage_with_additional_text (mock_get_state_information , mock_store_state_information , mock_env ):
34+ @patch ("app.services.slack.get_friendly_channel_name" )
35+ def test_feedback_storage_with_additional_text (
36+ mock_get_friendly_channel_name , mock_get_state_information , mock_store_state_information , mock_env
37+ ):
3138 """Test feedback storage with additional feedback text"""
3239 # set up mocks
40+ mock_client = Mock ()
3341
3442 # delete and import module to test
3543 if "app.slack.slack_events" in sys .modules :
3644 del sys .modules ["app.slack.slack_events" ]
3745 from app .slack .slack_events import store_feedback
3846
3947 # perform operation
40- store_feedback ("test-conversation" , "additional" , "U123" , "C123" , feedback_text = "This is additional feedback" )
48+ store_feedback (
49+ "test-conversation" , "additional" , "U123" , "C123" , mock_client , feedback_text = "This is additional feedback"
50+ )
4151
4252 # assertions
4353 mock_store_state_information .assert_called_once ()
@@ -239,18 +249,22 @@ def test_cleanup_previous_unfeedback_qa_does_not_throw_error(delete_state_inform
239249
240250@patch ("app.services.dynamo.store_state_information" )
241251@patch ("app.slack.slack_events.get_latest_message_ts" )
242- def test_store_feedback_no_message_ts_fallback (mock_get_latest_message_ts , mock_store_state_information , mock_env ):
252+ @patch ("app.services.slack.get_friendly_channel_name" )
253+ def test_store_feedback_no_message_ts_fallback (
254+ mock_get_friendly_channel_name , mock_get_latest_message_ts , mock_store_state_information , mock_env
255+ ):
243256 """Test store_feedback fallback path when no message_ts"""
244257 # set up mocks
245258 mock_get_latest_message_ts .return_value = None
259+ mock_client = Mock ()
246260
247261 # delete and import module to test
248262 if "app.slack.slack_events" in sys .modules :
249263 del sys .modules ["app.slack.slack_events" ]
250264 from app .slack .slack_events import store_feedback
251265
252266 # perform operation
253- store_feedback ("conv-key" , "positive" , "user-id" , "channel-id" )
267+ store_feedback ("conv-key" , "positive" , "user-id" , "channel-id" , mock_client )
254268
255269 # assertions
256270 mock_store_state_information .assert_called_once ()
@@ -361,12 +375,16 @@ def test_get_latest_message_ts_no_item(mock_get_state_information, mock_env):
361375
362376@patch ("app.services.dynamo.store_state_information" )
363377@patch ("app.slack.slack_events.get_latest_message_ts" )
364- def test_store_feedback_client_error_reraise (mock_get_latest_message_ts , mock_store_state_information , mock_env ):
378+ @patch ("app.services.slack.get_friendly_channel_name" )
379+ def test_store_feedback_client_error_reraise (
380+ mock_get_friendly_channel_name , mock_get_latest_message_ts , mock_store_state_information , mock_env
381+ ):
365382 """Test store_feedback re-raises ClientError"""
366383 # set up mocks
367384 error = ClientError ({"Error" : {"Code" : "ValidationException" }}, "PutItem" )
368385 mock_store_state_information .side_effect = error
369386 mock_get_latest_message_ts .return_value = "123"
387+ mock_client = Mock ()
370388
371389 # delete and import module to test
372390 if "app.slack.slack_events" in sys .modules :
@@ -375,7 +393,7 @@ def test_store_feedback_client_error_reraise(mock_get_latest_message_ts, mock_st
375393
376394 # perform operation
377395 with pytest .raises (ClientError ):
378- store_feedback ("conv-key" , "positive" , "user-id" , "channel-id" )
396+ store_feedback ("conv-key" , "positive" , "user-id" , "channel-id" , mock_client )
379397
380398
381399@patch ("app.services.dynamo.store_state_information" )
0 commit comments