From ac19f8b6fcda1ae40b82869069f19b9e4748632e Mon Sep 17 00:00:00 2001 From: Guillaume Charest <1690085+gcharest@users.noreply.github.com> Date: Thu, 8 Feb 2024 17:02:41 -0500 Subject: [PATCH] Refactor/module secret (#404) --- app/main.py | 7 +++---- app/modules/__init__.py | 0 app/modules/secret/__init__.py | 1 + app/{commands => modules/secret}/secret.py | 9 +++++++++ app/tests/{commands => modules}/test_secret.py | 16 ++++++++-------- 5 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 app/modules/__init__.py create mode 100644 app/modules/secret/__init__.py rename app/{commands => modules/secret}/secret.py (95%) rename app/tests/{commands => modules}/test_secret.py (95%) diff --git a/app/main.py b/app/main.py index 6cbf48b6..4f0fdf44 100644 --- a/app/main.py +++ b/app/main.py @@ -5,7 +5,8 @@ from slack_bolt.adapter.socket_mode import SocketModeHandler from slack_bolt import App from dotenv import load_dotenv -from commands import atip, aws, incident, secret, sre, role, google_service +from commands import atip, aws, incident, sre, role, google_service +from modules import secret from commands.helpers import incident_helper, webhook_helper from server import bot_middleware, server @@ -61,9 +62,7 @@ def main(bot): bot.view("view_save_incident_roles")(incident_helper.save_incident_roles) # Register Secret command - bot.command(f"/{PREFIX}secret")(secret.secret_command) - bot.action("secret_change_locale")(secret.handle_change_locale_button) - bot.view("secret_view")(secret.secret_view_handler) + secret.register(bot) # Register SRE events bot.command(f"/{PREFIX}sre")(sre.sre_command) diff --git a/app/modules/__init__.py b/app/modules/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/app/modules/secret/__init__.py b/app/modules/secret/__init__.py new file mode 100644 index 00000000..d0e9aa80 --- /dev/null +++ b/app/modules/secret/__init__.py @@ -0,0 +1 @@ +from .secret import register # noqa: F401 diff --git a/app/commands/secret.py b/app/modules/secret/secret.py similarity index 95% rename from app/commands/secret.py rename to app/modules/secret/secret.py index 1cf86c7d..e1138a38 100644 --- a/app/commands/secret.py +++ b/app/modules/secret/secret.py @@ -1,3 +1,4 @@ +import os import i18n import requests import time @@ -8,6 +9,14 @@ i18n.set("locale", "en-US") i18n.set("fallback", "en-US") +PREFIX = os.environ.get("PREFIX", "") + + +def register(bot): + bot.command(f"/{PREFIX}secret")(secret_command) + bot.action("secret_change_locale")(handle_change_locale_button) + bot.view("secret_view")(secret_view_handler) + def secret_command(client, ack, command, body): ack() diff --git a/app/tests/commands/test_secret.py b/app/tests/modules/test_secret.py similarity index 95% rename from app/tests/commands/test_secret.py rename to app/tests/modules/test_secret.py index 2e6294a6..8a7e553a 100644 --- a/app/tests/commands/test_secret.py +++ b/app/tests/modules/test_secret.py @@ -1,10 +1,10 @@ -from commands import secret +from modules.secret import secret from unittest.mock import MagicMock, patch -@patch("commands.secret.generate_secret_command_modal_view") -@patch("commands.secret.get_user_locale") +@patch("modules.secret.secret.generate_secret_command_modal_view") +@patch("modules.secret.secret.get_user_locale") def test_secret_command(mock_get_user_locale, mock_generate_secret_command_modal_view): client = MagicMock() ack = MagicMock() @@ -31,8 +31,8 @@ def test_secret_command(mock_get_user_locale, mock_generate_secret_command_modal ) -@patch("commands.secret.requests") -@patch("commands.secret.time") +@patch("modules.secret.secret.requests") +@patch("modules.secret.secret.time") def test_secret_view_handler_with_succesfull_request(mock_time, mock_requests): ack = MagicMock() client = MagicMock() @@ -89,8 +89,8 @@ def test_secret_view_handler_with_succesfull_request(mock_time, mock_requests): ) -@patch("commands.secret.requests") -@patch("commands.secret.time") +@patch("modules.secret.secret.requests") +@patch("modules.secret.secret.time") def test_secret_view_handler_with_failed_request(mock_time, mock_requests): ack = MagicMock() client = MagicMock() @@ -147,7 +147,7 @@ def test_secret_view_handler_with_failed_request(mock_time, mock_requests): ) -@patch("commands.secret.generate_secret_command_modal_view") +@patch("modules.secret.secret.generate_secret_command_modal_view") def test_handle_change_locale_button(mock_generate_secret_command_modal_view): ack = MagicMock() client = MagicMock()