Skip to content

Commit

Permalink
Refactor/module atip (#405)
Browse files Browse the repository at this point in the history
* feat: move atip to its own module

* feat: register atip module

* fix: module tests imports
  • Loading branch information
gcharest authored Feb 9, 2024
1 parent ac19f8b commit ebca789
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
12 changes: 4 additions & 8 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +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, sre, role, google_service
from modules import secret
from commands import aws, incident, sre, role, google_service
from modules import secret, atip
from commands.helpers import incident_helper, webhook_helper
from server import bot_middleware, server

Expand All @@ -32,12 +32,8 @@ def main(bot):
bot.view("role_view")(role.role_view_handler)
bot.action("role_change_locale")(role.update_modal_locale)

# Register ATIP commands
bot.command(f"/{PREFIX}atip")(atip.atip_command)
bot.command(f"/{PREFIX}aiprp")(atip.atip_command)
bot.action("ati_search_width")(atip.atip_width_action)
bot.view("atip_view")(atip.atip_view_handler)
bot.action("atip_change_locale")(atip.update_modal_locale)
# Register ATIP module
atip.register(bot)

# Register AWS commands
bot.command(f"/{PREFIX}aws")(aws.aws_command)
Expand Down
1 change: 1 addition & 0 deletions app/modules/atip/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .atip import register # noqa: F401
21 changes: 21 additions & 0 deletions app/commands/atip.py → app/modules/atip/atip.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@
i18n.set("locale", "en-US")
i18n.set("fallback", "en-US")

PREFIX = os.environ.get("PREFIX", "")


def register(bot):
"""
Registers the ATIP commands and events in the Slack Bot. Import the ATIP module in the main.py file and call the register function.
Example in main.py:
```
from modules import atip
def main(bot):
atip.register(bot)
```
"""
bot.command(f"/{PREFIX}atip")(atip_command)
bot.command(f"/{PREFIX}aiprp")(atip_command)
bot.action("ati_search_width")(atip_width_action)
bot.view("atip_view")(atip_view_handler)
bot.action("atip_change_locale")(update_modal_locale)


def atip_command(ack, command, logger, respond, client, body):
ack()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from commands import atip
from modules.atip import atip

from unittest.mock import ANY, MagicMock, patch

Expand Down Expand Up @@ -134,7 +134,7 @@ def test_atip_command_handles_unknown_command_FR_client():
)


@patch("commands.atip.request_start_modal")
@patch("modules.atip.atip.request_start_modal")
def test_atip_command_handles_access_EN_command(request_start_modal):
ack = MagicMock()
respond = MagicMock()
Expand All @@ -147,7 +147,7 @@ def test_atip_command_handles_access_EN_command(request_start_modal):
request_start_modal.assert_called_with(client, body, "en-US")


@patch("commands.atip.request_start_modal")
@patch("modules.atip.atip.request_start_modal")
def test_atip_command_handles_access_FR_command(request_start_modal):
ack = MagicMock()
respond = MagicMock()
Expand All @@ -160,7 +160,7 @@ def test_atip_command_handles_access_FR_command(request_start_modal):
request_start_modal.assert_called_with(client, body, "fr-FR")


@patch("commands.atip.atip_modal_view")
@patch("modules.atip.atip.atip_modal_view")
def test_atip_action_update_locale_to_FR(atip_modal_view):
ack = MagicMock()
client = MagicMock()
Expand All @@ -171,7 +171,7 @@ def test_atip_action_update_locale_to_FR(atip_modal_view):
atip_modal_view.assert_called_with("user_id", "", "fr-FR")


@patch("commands.atip.atip_modal_view")
@patch("modules.atip.atip.atip_modal_view")
def test_atip_action_update_locale_to_EN(atip_modal_view):
ack = MagicMock()
client = MagicMock()
Expand Down

0 comments on commit ebca789

Please sign in to comment.