diff --git a/slack_sdk/oauth/installation_store/sqlite3/__init__.py b/slack_sdk/oauth/installation_store/sqlite3/__init__.py index 40350bf7d..67da8eef4 100644 --- a/slack_sdk/oauth/installation_store/sqlite3/__init__.py +++ b/slack_sdk/oauth/installation_store/sqlite3/__init__.py @@ -536,6 +536,9 @@ def find_installation( self.logger.warning(message) return None + async def async_delete_bot(self, *, enterprise_id: Optional[str], team_id: Optional[str]) -> None: + return self.delete_bot(enterprise_id=enterprise_id, team_id=team_id) + def delete_bot(self, *, enterprise_id: Optional[str], team_id: Optional[str]) -> None: try: with self.connect() as conn: @@ -561,6 +564,15 @@ def delete_bot(self, *, enterprise_id: Optional[str], team_id: Optional[str]) -> else: self.logger.warning(message) + async def async_delete_installation( + self, + *, + enterprise_id: Optional[str], + team_id: Optional[str], + user_id: Optional[str] = None, + ) -> None: + return self.delete_installation(enterprise_id=enterprise_id, team_id=team_id, user_id=user_id) + def delete_installation( self, *, diff --git a/tests/slack_sdk/oauth/installation_store/test_sqlite3.py b/tests/slack_sdk/oauth/installation_store/test_sqlite3.py index 5395c286c..e45d640a7 100644 --- a/tests/slack_sdk/oauth/installation_store/test_sqlite3.py +++ b/tests/slack_sdk/oauth/installation_store/test_sqlite3.py @@ -2,6 +2,7 @@ from slack_sdk.oauth.installation_store import Installation from slack_sdk.oauth.installation_store.sqlite3 import SQLite3InstallationStore +from tests.helpers import async_test class TestSQLite3(unittest.TestCase): @@ -158,6 +159,40 @@ def test_org_installation(self): bot = store.find_bot(enterprise_id="EO111", team_id=None) self.assertIsNone(bot) + @async_test + async def test_async_delete(self): + store = SQLite3InstallationStore(database="logs/test.db", client_id="111.222") + installation = Installation( + app_id="A111", + enterprise_id="E111", + team_id="T111", + user_id="U111", + bot_id="B111", + bot_token="xoxb-111", + bot_scopes=["chat:write"], + bot_user_id="U222", + ) + await store.async_save(installation) + + # delete installations + await store.async_delete_installation(enterprise_id="E111", team_id="T111", user_id="U111") + i = await store.async_find_installation(enterprise_id="E111", team_id="T111", user_id="U111") + self.assertIsNone(i) + + # delete bots + await store.async_delete_bot(enterprise_id="E111", team_id="T111") + bot = await store.async_find_bot(enterprise_id="E111", team_id="T111") + self.assertIsNone(bot) + + # delete all + await store.async_save(installation) + await store.async_delete_all(enterprise_id="E111", team_id="T111") + + i = await store.async_find_installation(enterprise_id="E111", team_id="T111") + self.assertIsNone(i) + bot = await store.async_find_bot(enterprise_id="E111", team_id="T111") + self.assertIsNone(bot) + def test_save_and_find_token_rotation(self): store = SQLite3InstallationStore(database="logs/test.db", client_id="111.222")