Skip to content

Commit

Permalink
fix: Add deprecation warnings to Steps from Apps methods (#1504)
Browse files Browse the repository at this point in the history
* Added deprecation warnings for workflow step deprecation

* Update format
  • Loading branch information
WilliamBergamin authored Jun 7, 2024
1 parent 7d13c3b commit 5f941f4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
11 changes: 11 additions & 0 deletions slack_sdk/web/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

deprecated_method_prefixes_2023_07 = ["stars."]

deprecated_method_prefixes_2024_09 = ["workflows.stepCompleted", "workflows.updateStep", "workflows.stepFailed"]


def show_deprecation_warning_if_any(method_name: str):
"""Prints a warning if the given method is deprecated"""
Expand Down Expand Up @@ -40,3 +42,12 @@ def show_deprecation_warning_if_any(method_name: str):
"https://api.slack.com/changelog/2023-07-its-later-already-for-stars-and-reminders"
)
warnings.warn(message)

# 2024/09 workflow steps API deprecation
matched_prefixes = [prefix for prefix in deprecated_method_prefixes_2024_09 if method_name.startswith(prefix)]
if len(matched_prefixes) > 0:
message = (
f"{method_name} is deprecated. For more info, go to "
"https://api.slack.com/changelog/2023-08-workflow-steps-from-apps-step-back"
)
warnings.warn(message)
35 changes: 35 additions & 0 deletions tests/slack_sdk/web/test_web_client_workflow_step_deprecation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import unittest
import pytest

from slack_sdk.web import WebClient
from tests.helpers import remove_os_env_temporarily, restore_os_env
from tests.slack_sdk.web.mock_web_api_server import (
setup_mock_web_api_server,
cleanup_mock_web_api_server,
)


class TestWebClient(unittest.TestCase):
def setUp(self):
setup_mock_web_api_server(self)
self.env_values = remove_os_env_temporarily()

def tearDown(self):
cleanup_mock_web_api_server(self)
restore_os_env(self.env_values)

# You can enable this test to verify if the warning can be printed as expected
@pytest.mark.skip()
def test_workflow_step_completed_deprecation(self):
client = WebClient(base_url="http://localhost:8888")
client.workflows_stepCompleted(token="xoxb-api_test", workflow_step_execute_id="W1234")

@pytest.mark.skip()
def test_workflow_step_failed_deprecation(self):
client = WebClient(base_url="http://localhost:8888")
client.workflows_stepFailed(token="xoxb-api_test", workflow_step_execute_id="W1234", error={})

@pytest.mark.skip()
def test_workflow_update_step_deprecation(self):
client = WebClient(base_url="http://localhost:8888")
client.workflows_updateStep(token="xoxb-api_test", workflow_step_edit_id="W1234", inputs={}, outputs={})

0 comments on commit 5f941f4

Please sign in to comment.