Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions slack_bolt/context/complete/async_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class AsyncComplete:
client: AsyncWebClient
function_execution_id: Optional[str]
_called: bool

def __init__(
self,
Expand All @@ -15,6 +16,7 @@ def __init__(
):
self.client = client
self.function_execution_id = function_execution_id
self._called = False

async def __call__(self, outputs: Optional[Dict[str, Any]] = None) -> AsyncSlackResponse:
"""Signal the successful completion of the custom function.
Expand All @@ -31,6 +33,15 @@ async def __call__(self, outputs: Optional[Dict[str, Any]] = None) -> AsyncSlack
if self.function_execution_id is None:
raise ValueError("complete is unsupported here as there is no function_execution_id")

self._called = True
return await self.client.functions_completeSuccess(
function_execution_id=self.function_execution_id, outputs=outputs or {}
)

def has_been_called(self) -> bool:
"""Check if this complete function has been called.

Returns:
bool: True if the complete function has been called, False otherwise.
"""
return self._called
11 changes: 11 additions & 0 deletions slack_bolt/context/complete/complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class Complete:
client: WebClient
function_execution_id: Optional[str]
_called: bool

def __init__(
self,
Expand All @@ -15,6 +16,7 @@ def __init__(
):
self.client = client
self.function_execution_id = function_execution_id
self._called = False

def __call__(self, outputs: Optional[Dict[str, Any]] = None) -> SlackResponse:
"""Signal the successful completion of the custom function.
Expand All @@ -31,4 +33,13 @@ def __call__(self, outputs: Optional[Dict[str, Any]] = None) -> SlackResponse:
if self.function_execution_id is None:
raise ValueError("complete is unsupported here as there is no function_execution_id")

self._called = True
return self.client.functions_completeSuccess(function_execution_id=self.function_execution_id, outputs=outputs or {})

def has_been_called(self) -> bool:
"""Check if this complete function has been called.

Returns:
bool: True if the complete function has been called, False otherwise.
"""
return self._called
11 changes: 11 additions & 0 deletions slack_bolt/context/fail/async_fail.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class AsyncFail:
client: AsyncWebClient
function_execution_id: Optional[str]
_called: bool

def __init__(
self,
Expand All @@ -15,6 +16,7 @@ def __init__(
):
self.client = client
self.function_execution_id = function_execution_id
self._called = False

async def __call__(self, error: str) -> AsyncSlackResponse:
"""Signal that the custom function failed to complete.
Expand All @@ -31,4 +33,13 @@ async def __call__(self, error: str) -> AsyncSlackResponse:
if self.function_execution_id is None:
raise ValueError("fail is unsupported here as there is no function_execution_id")

self._called = True
return await self.client.functions_completeError(function_execution_id=self.function_execution_id, error=error)

def has_been_called(self) -> bool:
"""Check if this fail function has been called.

Returns:
bool: True if the fail function has been called, False otherwise.
"""
return self._called
11 changes: 11 additions & 0 deletions slack_bolt/context/fail/fail.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class Fail:
client: WebClient
function_execution_id: Optional[str]
_called: bool

def __init__(
self,
Expand All @@ -15,6 +16,7 @@ def __init__(
):
self.client = client
self.function_execution_id = function_execution_id
self._called = False

def __call__(self, error: str) -> SlackResponse:
"""Signal that the custom function failed to complete.
Expand All @@ -31,4 +33,13 @@ def __call__(self, error: str) -> SlackResponse:
if self.function_execution_id is None:
raise ValueError("fail is unsupported here as there is no function_execution_id")

self._called = True
return self.client.functions_completeError(function_execution_id=self.function_execution_id, error=error)

def has_been_called(self) -> bool:
"""Check if this fail function has been called.

Returns:
bool: True if the fail function has been called, False otherwise.
"""
return self._called
4 changes: 4 additions & 0 deletions tests/scenario_tests/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,16 +300,20 @@ def reverse(body, event, context, client, complete, inputs):
assert context.client.token == "xwfp-valid"
assert client.token == "xwfp-valid"
assert complete.client.token == "xwfp-valid"
assert complete.has_been_called() is False
complete(
outputs={"reverseString": "olleh"},
)
assert complete.has_been_called() is True


def reverse_error(body, event, fail):
assert body == function_body
assert event == function_body["event"]
assert fail.function_execution_id == "Fx111"
assert fail.has_been_called() is False
fail(error="there was an error")
assert fail.has_been_called() is True


def complete_it(body, event, complete):
Expand Down
4 changes: 4 additions & 0 deletions tests/scenario_tests_async/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,18 +312,22 @@ async def reverse(body, event, client, context, complete, inputs):
assert context.client.token == "xwfp-valid"
assert client.token == "xwfp-valid"
assert complete.client.token == "xwfp-valid"
assert complete.has_been_called() is False
await complete(
outputs={"reverseString": "olleh"},
)
assert complete.has_been_called() is True


async def reverse_error(body, event, fail):
assert body == function_body
assert event == function_body["event"]
assert fail.function_execution_id == "Fx111"
assert fail.has_been_called() is False
await fail(
error="there was an error",
)
assert fail.has_been_called() is True


async def complete_it(body, event, complete):
Expand Down
9 changes: 9 additions & 0 deletions tests/slack_bolt/context/test_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,12 @@ def test_complete_no_function_execution_id(self):

with pytest.raises(ValueError):
complete(outputs={"key": "value"})

def test_has_been_called_false_initially(self):
complete = Complete(client=self.web_client, function_execution_id="fn1111")
assert complete.has_been_called() is False

def test_has_been_called_true_after_complete(self):
complete = Complete(client=self.web_client, function_execution_id="fn1111")
complete(outputs={"key": "value"})
assert complete.has_been_called() is True
9 changes: 9 additions & 0 deletions tests/slack_bolt/context/test_fail.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,12 @@ def test_fail_no_function_execution_id(self):

with pytest.raises(ValueError):
fail(error="there was an error")

def test_has_been_called_false_initially(self):
fail = Fail(client=self.web_client, function_execution_id="fn1111")
assert fail.has_been_called() is False

def test_has_been_called_true_after_fail(self):
fail = Fail(client=self.web_client, function_execution_id="fn1111")
fail(error="there was an error")
assert fail.has_been_called() is True
11 changes: 11 additions & 0 deletions tests/slack_bolt_async/context/test_async_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,14 @@ async def test_complete_no_function_execution_id(self):

with pytest.raises(ValueError):
await complete(outputs={"key": "value"})

@pytest.mark.asyncio
async def test_has_been_called_false_initially(self):
complete = AsyncComplete(client=self.web_client, function_execution_id="fn1111")
assert complete.has_been_called() is False

@pytest.mark.asyncio
async def test_has_been_called_true_after_complete(self):
complete = AsyncComplete(client=self.web_client, function_execution_id="fn1111")
await complete(outputs={"key": "value"})
assert complete.has_been_called() is True
11 changes: 11 additions & 0 deletions tests/slack_bolt_async/context/test_async_fail.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,14 @@ async def test_fail_no_function_execution_id(self):

with pytest.raises(ValueError):
await fail(error="there was an error")

@pytest.mark.asyncio
async def test_has_been_called_false_initially(self):
fail = AsyncFail(client=self.web_client, function_execution_id="fn1111")
assert fail.has_been_called() is False

@pytest.mark.asyncio
async def test_has_been_called_true_after_fail(self):
fail = AsyncFail(client=self.web_client, function_execution_id="fn1111")
await fail(error="there was an error")
assert fail.has_been_called() is True
Loading