def test_message_action_on_test_message(client: Client, queue: MagicMock, slack_api_call: MagicMock): with get_mock_data( "interactive/message_action_on_test_message.json") as json_data: resp: Response = client.post( _ENDPOINT, data=json.loads(json_data.read()), content_type="application/x-www-form-urlencoded", ) assert resp.status_code == 200 assert resp.json["response_type"] == "in_channel" queue.assert_not_called() slack_api_call.assert_called_once_with( "dialog.open", dialog={ "title": "Echo dialog", "submit_label": "submit", "callback_id": "echo_dialog_1", "elements": [{ "type": "text", "label": "Echo this text", "name": "echo_element" }], }, trigger_id="TEST_TRIGGER_ID", )
def test_url_verification(client: Client, instrument: MagicMock, queue: MagicMock): with get_mock_data("event/url_verification.json") as json_data: resp: Response = client.post(_ENDPOINT, data=json_data, content_type="application/json") assert resp.status_code == 200 assert (resp.json["challenge"] == "ABCDEFGHIJKLMNOPQRSTUVWXABCDEFGHIJKLMNOPQRSTUVWX1234") instrument.assert_not_called() queue.assert_not_called()
def test_event_callback_test_message(client: Client, instrument: MagicMock, queue: MagicMock): with get_mock_data("event/event_callback_test_message.json") as json_data: event: Dict[str, Any] = json.loads(json_data.read()) resp: Response = client.post(_ENDPOINT, data=json.dumps(event), content_type="application/json") assert resp.status_code == 200 assert resp.json["status"] == "success" instrument.assert_called_once_with(get_test_bot(), event) queue.assert_called_once_with(get_test_bot(), event, "event")
def test_invalid_bot(client: Client, instrument: MagicMock, queue: MagicMock): with get_mock_data("event/event_callback_omnibot_help.json") as json_data: modified_data: Dict[str, Any] = json.loads(json_data.read()) modified_data["api_app_id"] = "something random" resp: Response = client.post(_ENDPOINT, data=json.dumps(modified_data), content_type="application/json") assert resp.status_code == 200 assert resp.json["status"] == "ignored" assert resp.json["warning"] == "Unsupported bot" instrument.assert_not_called() queue.assert_not_called()
def test_missing_team_id(client: Client, instrument: MagicMock, queue: MagicMock): with get_mock_data("event/event_callback_omnibot_help.json") as json_data: modified_data: Dict[str, Any] = json.loads(json_data.read()) modified_data.pop("team_id", None) resp: Response = client.post(_ENDPOINT, data=json.dumps(modified_data), content_type="application/json") assert resp.status_code == 403 assert resp.json["status"] == "failure" assert resp.json["error"] == "No team_id in event." instrument.assert_not_called() queue.assert_not_called()
def test_invalid_verification_token(client: Client, instrument: MagicMock, queue: MagicMock): with get_mock_data("event/url_verification.json") as json_data: modified_data: Dict[str, Any] = json.loads(json_data.read()) modified_data["token"] = "something random" resp: Response = client.post(_ENDPOINT, data=json.dumps(modified_data), content_type="application/json") assert resp.status_code == 403 assert resp.json["status"] == "failure" assert resp.json["error"] == "url_verification failed." instrument.assert_not_called() queue.assert_not_called()
def test_missing_token(client: Client, queue: MagicMock): with get_mock_data( "slash_command/user_issues_echo_command.json") as json_data: modified_data: Dict[str, Any] = json.loads(json_data.read()) modified_data.pop("token", None) resp: Response = client.post( _ENDPOINT, data=modified_data, content_type="application/x-www-form-urlencoded", ) assert resp.status_code == 403 assert resp.json["status"] == "failure" assert resp.json["error"] == "No verification token in slash command." queue.assert_not_called()
def test_event_missing_event_block(client: Client, instrument: MagicMock, queue: MagicMock): with get_mock_data("event/event_callback_omnibot_help.json") as json_data: modified_data: Dict[str, Any] = json.loads(json_data.read()) modified_data.pop("event", None) resp: Response = client.post(_ENDPOINT, data=json.dumps(modified_data), content_type="application/json") assert resp.status_code == 403 assert resp.json["status"] == "failure" assert (resp.json["error"] == "Request does not have an event. Processing will not proceed!") instrument.assert_not_called() queue.assert_not_called()
def test_unsupported_team(client: Client, queue: MagicMock): with get_mock_data( "slash_command/user_issues_echo_command.json") as json_data: modified_data: Dict[str, Any] = json.loads(json_data.read()) modified_data["team_id"] = "something random" resp: Response = client.post( _ENDPOINT, data=modified_data, content_type="application/x-www-form-urlencoded", ) assert resp.status_code == 403 assert resp.json["status"] == "failure" assert resp.json["error"] == "Unsupported team" queue.assert_not_called()
def test_user_issues_echo_command(client: Client, queue: MagicMock): with get_mock_data( "slash_command/user_issues_echo_command.json") as json_data: event: Dict[str, Any] = json.loads(json_data.read()) resp: Response = client.post( _ENDPOINT, data=event, content_type="application/x-www-form-urlencoded", ) assert resp.status_code == 200 command = event.copy() command["omnibot_bot_id"] = "TEST_OMNIBOT_ID" queue.assert_called_once_with(get_test_bot(), command, "slash_command") assert resp.json["response_type"] == "in_channel"
def test_invalid_verification_token(client: Client, queue: MagicMock): with get_mock_data( "slash_command/user_issues_echo_command.json") as json_data: modified_data: Dict[str, Any] = json.loads(json_data.read()) modified_data["token"] = "something random" resp: Response = client.post( _ENDPOINT, data=modified_data, content_type="application/x-www-form-urlencoded", ) assert resp.status_code == 403 assert resp.json["status"] == "failure" assert ( resp.json["error"] == "Token sent with slash command does not match any configured app.") queue.assert_not_called()
def test_dialog_submission_echo_test(client: Client, queue: MagicMock, slack_api_call: MagicMock): with get_mock_data( "interactive/dialog_submission_echo_test.json") as json_data: event: Dict[str, Any] = json.loads(json_data.read()) resp: Response = client.post( _ENDPOINT, data=event, content_type="application/x-www-form-urlencoded", ) assert resp.status_code == 200 component = json.loads(event["payload"]) component["omnibot_bot_id"] = "TEST_OMNIBOT_ID" queue.assert_called_once_with(get_test_bot(), component, "interactive_component") slack_api_call.assert_not_called()
def test_unsupported_team(client: Client, queue: MagicMock, slack_api_call: MagicMock): with get_mock_data( "interactive/dialog_submission_echo_test.json") as json_data: payload: Dict[str, Any] = json.loads(json_data.read()) modified_data: Dict[str, Any] = json.loads(payload["payload"]) modified_data["team"]["id"] = "something random" resp: Response = client.post( _ENDPOINT, data={"payload": json.dumps(modified_data)}, content_type="application/x-www-form-urlencoded", ) assert resp.status_code == 403 assert resp.json["status"] == "failure" assert resp.json["error"] == "Unsupported team" queue.assert_not_called() slack_api_call.assert_not_called()
def test_missing_handler(client: Client, queue: MagicMock): with get_mock_data( "slash_command/user_issues_echo_command.json") as json_data: modified_data: Dict[str, Any] = json.loads(json_data.read()) modified_data["command"] = "/somethingrandom" resp: Response = client.post( _ENDPOINT, data=modified_data, content_type="application/x-www-form-urlencoded", ) assert resp.status_code == 200 assert resp.json["response_type"] == "ephemeral" assert ( resp.json["text"] == "This slash command does not have any omnibot handler associated with it." # noqa: E501 ) queue.assert_not_called()
def test_missing_token(client: Client, queue: MagicMock, slack_api_call: MagicMock): with get_mock_data( "interactive/dialog_submission_echo_test.json") as json_data: payload: Dict[str, Any] = json.loads(json_data.read()) modified_data: Dict[str, Any] = json.loads(payload["payload"]) modified_data.pop("token", None) resp: Response = client.post( _ENDPOINT, data={"payload": json.dumps(modified_data)}, content_type="application/x-www-form-urlencoded", ) assert resp.status_code == 403 assert resp.json["status"] == "failure" assert resp.json[ "error"] == "No verification token in interactive component." queue.assert_not_called() slack_api_call.assert_not_called()
def test_invalid_callback_id(client: Client, queue: MagicMock, slack_api_call: MagicMock): with get_mock_data( "interactive/dialog_submission_echo_test.json") as json_data: payload: Dict[str, Any] = json.loads(json_data.read()) modified_data: Dict[str, Any] = json.loads(payload["payload"]) modified_data["callback_id"] = "something random" resp: Response = client.post( _ENDPOINT, data={"payload": json.dumps(modified_data)}, content_type="application/x-www-form-urlencoded", ) assert resp.status_code == 200 assert resp.json["response_type"] == "ephemeral" assert ( resp.json["text"] == "This interactive component does not have any omnibot handler associated with it." # noqa: E501 ) queue.assert_not_called() slack_api_call.assert_not_called()
def test_invalid_token(client: Client, queue: MagicMock, slack_api_call: MagicMock): with get_mock_data( "interactive/dialog_submission_echo_test.json") as json_data: payload: Dict[str, Any] = json.loads(json_data.read()) modified_data: Dict[str, Any] = json.loads(payload["payload"]) modified_data["token"] = "something random" resp: Response = client.post( _ENDPOINT, data={"payload": json.dumps(modified_data)}, content_type="application/x-www-form-urlencoded", ) assert resp.status_code == 403 assert resp.json["status"] == "failure" assert ( resp.json["error"] == "Token sent with interactive component does not match any configured app." # noqa: E501 ) queue.assert_not_called() slack_api_call.assert_not_called()