Skip to content

Commit d9daaf9

Browse files
authored
Merge pull request #37 from GabrielSalla/change-external-requests-to-commands
Change external requests to commands
2 parents 2b51874 + eb95a8f commit d9daaf9

File tree

10 files changed

+39
-39
lines changed

10 files changed

+39
-39
lines changed

src/components/http_server/alert_routes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from aiohttp.web_request import Request
33
from aiohttp.web_response import Response
44

5-
import external_requests as external_requests
5+
import commands as commands
66
from models import Alert
77

88
alert_routes = web.RouteTableDef()
@@ -20,7 +20,7 @@ async def alert_acknowledge(request: Request) -> Response:
2020
error_response = {"status": "error", "message": f"alert '{alert_id}' not found"}
2121
return web.json_response(error_response, status=404)
2222

23-
await external_requests.alert_acknowledge(alert_id)
23+
await commands.alert_acknowledge(alert_id)
2424

2525
success_response = {
2626
"status": "request_queued",
@@ -41,7 +41,7 @@ async def alert_lock(request: Request) -> Response:
4141
error_response = {"status": "error", "message": f"alert '{alert_id}' not found"}
4242
return web.json_response(error_response, status=404)
4343

44-
await external_requests.alert_lock(alert_id)
44+
await commands.alert_lock(alert_id)
4545

4646
success_response = {
4747
"status": "request_queued",
@@ -62,7 +62,7 @@ async def alert_solve(request: Request) -> Response:
6262
error_response = {"status": "error", "message": f"alert '{alert_id}' not found"}
6363
return web.json_response(error_response, status=404)
6464

65-
await external_requests.alert_solve(alert_id)
65+
await commands.alert_solve(alert_id)
6666

6767
success_response = {
6868
"status": "request_queued",

src/components/http_server/issue_routes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from aiohttp.web_request import Request
33
from aiohttp.web_response import Response
44

5-
import external_requests as external_requests
5+
import commands as commands
66
from models import Issue
77

88
issue_routes = web.RouteTableDef()
@@ -20,7 +20,7 @@ async def issue_drop(request: Request) -> Response:
2020
error_response = {"status": "error", "message": f"issue '{issue_id}' not found"}
2121
return web.json_response(error_response, status=404)
2222

23-
await external_requests.issue_drop(issue_id)
23+
await commands.issue_drop(issue_id)
2424

2525
success_response = {
2626
"status": "request_queued",

src/components/http_server/monitor_routes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from aiohttp.web_request import Request
88
from aiohttp.web_response import Response
99

10-
import external_requests as external_requests
10+
import commands as commands
1111
from components.monitors_loader import MonitorValidationError
1212
from models import CodeModule, Monitor
1313

@@ -73,7 +73,7 @@ async def monitor_disable(request: Request) -> Response:
7373
monitor_name = request.match_info["monitor_name"]
7474

7575
try:
76-
await external_requests.disable_monitor(monitor_name)
76+
await commands.disable_monitor(monitor_name)
7777
success_response = {
7878
"status": "monitor_disabled",
7979
"monitor_name": monitor_name,
@@ -95,7 +95,7 @@ async def monitor_enable(request: Request) -> Response:
9595
monitor_name = request.match_info["monitor_name"]
9696

9797
try:
98-
await external_requests.enable_monitor(monitor_name)
98+
await commands.enable_monitor(monitor_name)
9999
success_response = {
100100
"status": "monitor_enabled",
101101
"monitor_name": monitor_name,
@@ -133,7 +133,7 @@ async def monitor_register(request: Request) -> Response:
133133
monitor_name = monitor_name.replace(".", "_")
134134

135135
try:
136-
monitor = await external_requests.monitor_register(
136+
monitor = await commands.monitor_register(
137137
monitor_name, monitor_code, additional_files
138138
)
139139
except pydantic.ValidationError as e:

src/plugins/slack/services/pattern_match.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
import re
22
from typing import Any, Coroutine
33

4-
import external_requests as external_requests
4+
import commands as commands
55
import message_queue as message_queue
66

77

88
def disable_monitor(
99
message_match: re.Match[Any], context: dict[str, Any]
1010
) -> Coroutine[Any, Any, Any]:
1111
"""Disable a monitor"""
12-
return external_requests.disable_monitor(message_match.group(1))
12+
return commands.disable_monitor(message_match.group(1))
1313

1414

1515
def enable_monitor(
1616
message_match: re.Match[Any], context: dict[str, Any]
1717
) -> Coroutine[Any, Any, Any]:
1818
"""Enable a monitor"""
19-
return external_requests.enable_monitor(message_match.group(1))
19+
return commands.enable_monitor(message_match.group(1))
2020

2121

2222
def alert_acknowledge(
2323
message_match: re.Match[Any], context: dict[str, Any]
2424
) -> Coroutine[Any, Any, Any]:
2525
"""Get the alert acknowledge action"""
2626
alert_id = int(message_match.group(1))
27-
return external_requests.alert_acknowledge(alert_id)
27+
return commands.alert_acknowledge(alert_id)
2828

2929

3030
def alert_lock(message_match: re.Match[Any], context: dict[str, Any]) -> Coroutine[Any, Any, Any]:
3131
"""Get the alert lock action"""
3232
alert_id = int(message_match.group(1))
33-
return external_requests.alert_lock(alert_id)
33+
return commands.alert_lock(alert_id)
3434

3535

3636
def alert_solve(message_match: re.Match[Any], context: dict[str, Any]) -> Coroutine[Any, Any, Any]:
3737
"""Get the alert solve action"""
3838
alert_id = int(message_match.group(1))
39-
return external_requests.alert_solve(alert_id)
39+
return commands.alert_solve(alert_id)
4040

4141

4242
def issue_drop(message_match: re.Match[Any], context: dict[str, Any]) -> Coroutine[Any, Any, Any]:
4343
"""Get the issue drop action"""
4444
issue_id = int(message_match.group(1))
45-
return external_requests.issue_drop(issue_id)
45+
return commands.issue_drop(issue_id)
4646

4747

4848
def resend_notifications(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
import pytest
55

6+
import commands.requests as requests
67
import components.monitors_loader as monitors_loader
7-
import external_requests.requests as requests
88
import message_queue as message_queue
99
from models import CodeModule, Monitor
1010

tests/components/http_server/test_monitor_routes.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import pytest
55
import pytest_asyncio
66

7+
import commands as commands
78
import components.controller.controller as controller
89
import components.http_server as http_server
910
import databases as databases
10-
import external_requests as external_requests
1111
from models import CodeModule, Monitor
1212

1313
pytestmark = pytest.mark.asyncio(loop_scope="session")
@@ -93,7 +93,7 @@ async def test_get_monitor_invalid_code_module(clear_database, sample_monitor: M
9393

9494
async def test_monitor_disable(mocker, clear_database, sample_monitor: Monitor):
9595
"""The 'monitor disable' route should disable a monitor"""
96-
monitor_disable_spy: AsyncMock = mocker.spy(external_requests, "disable_monitor")
96+
monitor_disable_spy: AsyncMock = mocker.spy(commands, "disable_monitor")
9797

9898
assert sample_monitor.enabled
9999

@@ -114,7 +114,7 @@ async def test_monitor_disable(mocker, clear_database, sample_monitor: Monitor):
114114

115115
async def test_monitor_disable_not_found(mocker, clear_database):
116116
"""The 'monitor disable' route should return an error if the monitor is not found"""
117-
monitor_disable_spy: AsyncMock = mocker.spy(external_requests, "disable_monitor")
117+
monitor_disable_spy: AsyncMock = mocker.spy(commands, "disable_monitor")
118118

119119
url = BASE_URL + "/not_found/disable"
120120
async with aiohttp.ClientSession() as session:
@@ -130,7 +130,7 @@ async def test_monitor_disable_not_found(mocker, clear_database):
130130

131131
async def test_monitor_disable_error(mocker, clear_database):
132132
"""The 'monitor disable' route should return an error if an exception is raised"""
133-
monitor_disable_spy: AsyncMock = mocker.spy(external_requests, "disable_monitor")
133+
monitor_disable_spy: AsyncMock = mocker.spy(commands, "disable_monitor")
134134
monitor_disable_spy.side_effect = Exception("Something went wrong")
135135

136136
url = BASE_URL + "/error/disable"
@@ -147,7 +147,7 @@ async def test_monitor_disable_error(mocker, clear_database):
147147

148148
async def test_monitor_enable(mocker, clear_database, sample_monitor: Monitor):
149149
"""The 'monitor enable' route should enable a monitor"""
150-
monitor_enable_spy: AsyncMock = mocker.spy(external_requests, "enable_monitor")
150+
monitor_enable_spy: AsyncMock = mocker.spy(commands, "enable_monitor")
151151

152152
await sample_monitor.set_enabled(False)
153153
assert not sample_monitor.enabled
@@ -169,7 +169,7 @@ async def test_monitor_enable(mocker, clear_database, sample_monitor: Monitor):
169169

170170
async def test_monitor_enable_not_found(mocker, clear_database):
171171
"""The 'monitor enable' route should return an error if the monitor is not found"""
172-
monitor_enable_spy: AsyncMock = mocker.spy(external_requests, "enable_monitor")
172+
monitor_enable_spy: AsyncMock = mocker.spy(commands, "enable_monitor")
173173

174174
url = BASE_URL + "/not_found/enable"
175175
async with aiohttp.ClientSession() as session:
@@ -185,7 +185,7 @@ async def test_monitor_enable_not_found(mocker, clear_database):
185185

186186
async def test_monitor_enable_error(mocker, clear_database):
187187
"""The 'monitor enable' route should return an error if an exception is raised"""
188-
monitor_enable_spy: AsyncMock = mocker.spy(external_requests, "enable_monitor")
188+
monitor_enable_spy: AsyncMock = mocker.spy(commands, "enable_monitor")
189189
monitor_enable_spy.side_effect = Exception("Something went wrong")
190190

191191
url = BASE_URL + "/error/enable"
@@ -208,7 +208,7 @@ async def test_monitor_enable_error(mocker, clear_database):
208208
async def test_monitor_register(mocker, clear_database, monitor_name):
209209
"""The 'monitor register' route should register a new monitor with the provided module code if
210210
it doesn't exists. The monitor name should replace any dots with underscores"""
211-
monitor_register_spy: AsyncMock = mocker.spy(external_requests, "monitor_register")
211+
monitor_register_spy: AsyncMock = mocker.spy(commands, "monitor_register")
212212

213213
monitor = await Monitor.get(Monitor.name == monitor_name)
214214
assert monitor is None
@@ -267,7 +267,7 @@ async def test_monitor_register_batch(mocker, clear_database):
267267
async def test_monitor_register_additional_files(mocker, clear_database):
268268
"""The 'monitor register' route should register a new monitor with the provided module code and
269269
additional files if it not exists"""
270-
monitor_register_spy: AsyncMock = mocker.spy(external_requests, "monitor_register")
270+
monitor_register_spy: AsyncMock = mocker.spy(commands, "monitor_register")
271271

272272
monitor_name = "test_monitor_register_additional_files"
273273
monitor = await Monitor.get(Monitor.name == monitor_name)

tests/plugins/slack/services/test_pattern_match.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pytest
77

8-
import external_requests as external_requests
8+
import commands as commands
99
import message_queue as message_queue
1010
import plugins.slack.services.pattern_match as pattern_match
1111

@@ -14,7 +14,7 @@
1414

1515
async def test_disable_monitor(mocker):
1616
"""'disable_monitor' should return the coroutine to disable the monitor"""
17-
disable_monitor_spy: MagicMock = mocker.spy(external_requests, "disable_monitor")
17+
disable_monitor_spy: MagicMock = mocker.spy(commands, "disable_monitor")
1818

1919
action = pattern_match.disable_monitor(
2020
message_match=re.match(r"disable monitor +(\w+)", "disable monitor abc"),
@@ -31,7 +31,7 @@ async def test_disable_monitor(mocker):
3131

3232
async def test_enable_monitor(mocker):
3333
"""'enable_monitor' should return the coroutine to enable the monitor"""
34-
enable_monitor_spy: MagicMock = mocker.spy(external_requests, "enable_monitor")
34+
enable_monitor_spy: MagicMock = mocker.spy(commands, "enable_monitor")
3535

3636
action = pattern_match.enable_monitor(
3737
message_match=re.match(r"enable monitor +(\w+)", "enable monitor abc"),
@@ -48,7 +48,7 @@ async def test_enable_monitor(mocker):
4848

4949
async def test_alert_acknowledge(mocker):
5050
"""'alert_acknowledge' should return the coroutine to acknowledge the alert"""
51-
alert_acknowledge_spy: MagicMock = mocker.spy(external_requests, "alert_acknowledge")
51+
alert_acknowledge_spy: MagicMock = mocker.spy(commands, "alert_acknowledge")
5252

5353
action = pattern_match.alert_acknowledge(
5454
message_match=re.match(r"ack +(\d+)", "ack 12345"),
@@ -65,7 +65,7 @@ async def test_alert_acknowledge(mocker):
6565

6666
async def test_alert_lock(mocker):
6767
"""'alert_lock' should return the coroutine to lock the alert"""
68-
alert_lock_spy: MagicMock = mocker.spy(external_requests, "alert_lock")
68+
alert_lock_spy: MagicMock = mocker.spy(commands, "alert_lock")
6969

7070
action = pattern_match.alert_lock(
7171
message_match=re.match(r"lock +(\d+)", "lock 12345"),
@@ -82,7 +82,7 @@ async def test_alert_lock(mocker):
8282

8383
async def test_alert_solve(mocker):
8484
"""'alert_solve' should return the coroutine to solve the alert"""
85-
alert_solve_spy: MagicMock = mocker.spy(external_requests, "alert_solve")
85+
alert_solve_spy: MagicMock = mocker.spy(commands, "alert_solve")
8686

8787
action = pattern_match.alert_solve(
8888
message_match=re.match(r"solve +(\d+)", "solve 12345"),
@@ -99,7 +99,7 @@ async def test_alert_solve(mocker):
9999

100100
async def test_issue_drop(mocker):
101101
"""'issue_drop' should return the coroutine to drop the issue"""
102-
issue_drop_spy: MagicMock = mocker.spy(external_requests, "issue_drop")
102+
issue_drop_spy: MagicMock = mocker.spy(commands, "issue_drop")
103103

104104
action = pattern_match.issue_drop(
105105
message_match=re.match(r"drop issue +(\d+)", "drop issue 12345"),
@@ -172,7 +172,7 @@ async def test_get_message_request_match_external(
172172
):
173173
"""'get_message_request' should return the correct request coroutine based on the received
174174
message, using the external requests"""
175-
action_spy: MagicMock = mocker.spy(external_requests, expected_request)
175+
action_spy: MagicMock = mocker.spy(commands, expected_request)
176176

177177
context = {
178178
"channel": "C1234567890",

tests/plugins/slack/services/test_websocket.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
import external_requests as external_requests
5+
import commands as commands
66
import plugins.slack.services.websocket as websocket
77
import plugins.slack.slack as slack
88

@@ -18,7 +18,7 @@
1818
async def test_app_mention(mocker, message, action_name):
1919
"""'app_mention' should call the correct action for the event if there's an action mapped for
2020
it, reacting to the message with a check mark"""
21-
action_spy: AsyncMock = mocker.spy(external_requests, action_name)
21+
action_spy: AsyncMock = mocker.spy(commands, action_name)
2222
slack_add_reaction_spy: AsyncMock = mocker.spy(slack, "add_reaction")
2323

2424
body = {
@@ -49,7 +49,7 @@ async def test_app_mention_invalid_action(mocker):
4949
async def test_app_mention_error(mocker):
5050
"""'app_mention' should react to the message with an 'x' and send the error message if an
5151
exception is raised"""
52-
action_spy: AsyncMock = mocker.spy(external_requests, "alert_acknowledge")
52+
action_spy: AsyncMock = mocker.spy(commands, "alert_acknowledge")
5353
slack_add_reaction_spy: AsyncMock = mocker.spy(slack, "add_reaction")
5454
slack_send_spy: AsyncMock = mocker.spy(slack, "send")
5555

@@ -77,7 +77,7 @@ async def test_command(mocker, message, action_name):
7777
"""'command' should ack the command and call the correct action for the event if there's an
7878
action mapped for it"""
7979
ack_mock = AsyncMock()
80-
action_spy: AsyncMock = mocker.spy(external_requests, action_name)
80+
action_spy: AsyncMock = mocker.spy(commands, action_name)
8181

8282
body = {
8383
"actions": [{"value": message}]

0 commit comments

Comments
 (0)