Skip to content

Commit

Permalink
Refactor/module secret (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
gcharest authored Feb 8, 2024
1 parent 1e3548e commit ac19f8b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
7 changes: 3 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
Empty file added app/modules/__init__.py
Empty file.
1 change: 1 addition & 0 deletions app/modules/secret/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .secret import register # noqa: F401
9 changes: 9 additions & 0 deletions app/commands/secret.py → app/modules/secret/secret.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import i18n
import requests
import time
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ac19f8b

Please sign in to comment.