Skip to content

Commit 3a7ab09

Browse files
author
patched.codes[bot]
committed
Patched tests/steps/test_SlackMessage.py
1 parent d642da5 commit 3a7ab09

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tests/steps/test_SlackMessage.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ def mocked_slack_key():
1414

1515
@pytest.fixture
1616
def mocked_slack_client(mocker, mocked_slack_key):
17+
"""Creates and configures a mocked Slack client for testing purposes.
18+
19+
Args:
20+
mocker (MagicMock): The pytest mocker fixture used for creating mock objects.
21+
mocked_slack_key (str): The mocked Slack API key (not used in the function body).
22+
23+
Returns:
24+
MagicMock: A configured mock Slack client with predefined return values for various methods.
25+
"""
1726
mocked_slack_client = mocker.MagicMock()
1827
mocker.patch.object(WebClient, "__new__", return_value=mocked_slack_client)
1928

@@ -27,6 +36,18 @@ def mocked_slack_client(mocker, mocked_slack_key):
2736

2837

2938
def test_slack_message_init_valid_inputs(mocked_slack_client, mocked_slack_key):
39+
"""Test the initialization of SlackMessage with valid inputs.
40+
41+
Args:
42+
mocked_slack_client (MagicMock): A mocked Slack client object.
43+
mocked_slack_key (str): A mocked Slack API key.
44+
45+
Returns:
46+
None: This test method doesn't return anything.
47+
48+
Raises:
49+
AssertionError: If the assertions for slack_channel or slack_message fail.
50+
"""
3051
inputs = {
3152
"slack_token": mocked_slack_key,
3253
"slack_channel": "channel-name",
@@ -72,13 +93,39 @@ def test_slack_message_init_valid_inputs(mocked_slack_client, mocked_slack_key):
7293
],
7394
)
7495
def test_slack_message_init_missing_required_key(mocked_slack_client, mocked_slack_key, inputs):
96+
"""Test the initialization of SlackMessage with missing required key.
97+
98+
Args:
99+
mocked_slack_client (MagicMock): A mocked Slack client object.
100+
mocked_slack_key (str): A mocked Slack API key.
101+
inputs (dict): A dictionary of input parameters for SlackMessage initialization.
102+
103+
Raises:
104+
ValueError: If a required key is missing from the inputs dictionary.
105+
106+
Returns:
107+
None
108+
109+
"""
75110
if "slack_token" in inputs:
76111
inputs["slack_token"] = mocked_slack_key
77112
with pytest.raises(ValueError):
78113
SlackMessage(inputs)
79114

80115

81116
def test_slack_message_run(mocked_slack_client, mocked_slack_key):
117+
"""Test the SlackMessage.run() method with mocked Slack client.
118+
119+
Args:
120+
mocked_slack_client (MagicMock): A mocked Slack client object.
121+
mocked_slack_key (str): A mocked Slack API key.
122+
123+
Returns:
124+
None: This test method doesn't return anything, it uses assertions.
125+
126+
Raises:
127+
AssertionError: If the assertion for successful message sending fails.
128+
"""
82129
mocked_slack_client.chat_postMessage.return_value = {"ok": True}
83130
inputs = {
84131
"slack_token": mocked_slack_key,

0 commit comments

Comments
 (0)