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
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# change black settings
108955b601e768fd56696be903fc8b471c73ebf7
4 changes: 1 addition & 3 deletions integration_tests/audit_logs/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

class TestAuditLogsClient(unittest.TestCase):
def setUp(self):
self.client = AsyncAuditLogsClient(
token=os.environ[SLACK_SDK_TEST_GRID_ORG_ADMIN_USER_TOKEN]
)
self.client = AsyncAuditLogsClient(token=os.environ[SLACK_SDK_TEST_GRID_ORG_ADMIN_USER_TOKEN])

def tearDown(self):
pass
Expand Down
4 changes: 1 addition & 3 deletions integration_tests/audit_logs/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

class TestAuditLogsClient(unittest.TestCase):
def setUp(self):
self.client = AuditLogsClient(
token=os.environ[SLACK_SDK_TEST_GRID_ORG_ADMIN_USER_TOKEN]
)
self.client = AuditLogsClient(token=os.environ[SLACK_SDK_TEST_GRID_ORG_ADMIN_USER_TOKEN])

def tearDown(self):
pass
Expand Down
10 changes: 2 additions & 8 deletions integration_tests/audit_logs/test_pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

class TestAuditLogsClient(unittest.TestCase):
def setUp(self):
self.client = AuditLogsClient(
token=os.environ[SLACK_SDK_TEST_GRID_ORG_ADMIN_USER_TOKEN]
)
self.client = AuditLogsClient(token=os.environ[SLACK_SDK_TEST_GRID_ORG_ADMIN_USER_TOKEN])

def tearDown(self):
pass
Expand All @@ -22,11 +20,7 @@ def test_pagination(self):
response = None
ids = []
while call_count < 10 and (response is None or response.status_code != 429):
cursor = (
response.body["response_metadata"]["next_cursor"]
if response is not None
else None
)
cursor = response.body["response_metadata"]["next_cursor"] if response is not None else None
response = self.client.logs(action="user_login", limit=1, cursor=cursor)
ids += map(lambda v: v["id"], response.body.get("entries", []))
call_count += 1
Expand Down
20 changes: 5 additions & 15 deletions integration_tests/env_variable_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

# Testing with Grid workspaces
SLACK_SDK_TEST_GRID_ORG_ADMIN_USER_TOKEN = "SLACK_SDK_TEST_GRID_ORG_ADMIN_USER_TOKEN"
SLACK_SDK_TEST_GRID_WORKSPACE_ADMIN_USER_TOKEN = (
"SLACK_SDK_TEST_GRID_WORKSPACE_ADMIN_USER_TOKEN"
)
SLACK_SDK_TEST_GRID_WORKSPACE_ADMIN_USER_TOKEN = "SLACK_SDK_TEST_GRID_WORKSPACE_ADMIN_USER_TOKEN"
SLACK_SDK_TEST_GRID_WORKSPACE_USER_TOKEN = "SLACK_SDK_TEST_GRID_WORKSPACE_USER_TOKEN"
SLACK_SDK_TEST_GRID_WORKSPACE_BOT_TOKEN = "SLACK_SDK_TEST_GRID_WORKSPACE_BOT_TOKEN"
SLACK_SDK_TEST_GRID_IDP_USERGROUP_ID = "SLACK_SDK_TEST_GRID_IDP_USERGROUP_ID"
Expand All @@ -32,17 +30,9 @@

# Webhook
SLACK_SDK_TEST_INCOMING_WEBHOOK_URL = "SLACK_SDK_TEST_INCOMING_WEBHOOK_URL"
SLACK_SDK_TEST_INCOMING_WEBHOOK_CHANNEL_NAME = (
"SLACK_SDK_TEST_INCOMING_WEBHOOK_CHANNEL_NAME"
)
SLACK_SDK_TEST_INCOMING_WEBHOOK_CHANNEL_NAME = "SLACK_SDK_TEST_INCOMING_WEBHOOK_CHANNEL_NAME"

# For Slack Connect shared tests
SLACK_SDK_TEST_CONNECT_INVITE_SENDER_BOT_TOKEN = (
"SLACK_SDK_TEST_CONNECT_INVITE_SENDER_BOT_TOKEN"
)
SLACK_SDK_TEST_CONNECT_INVITE_RECEIVER_BOT_TOKEN = (
"SLACK_SDK_TEST_CONNECT_INVITE_RECEIVER_BOT_TOKEN"
)
SLACK_SDK_TEST_CONNECT_INVITE_RECEIVER_BOT_USER_ID = (
"SLACK_SDK_TEST_CONNECT_INVITE_RECEIVER_BOT_USER_ID"
)
SLACK_SDK_TEST_CONNECT_INVITE_SENDER_BOT_TOKEN = "SLACK_SDK_TEST_CONNECT_INVITE_SENDER_BOT_TOKEN"
SLACK_SDK_TEST_CONNECT_INVITE_RECEIVER_BOT_TOKEN = "SLACK_SDK_TEST_CONNECT_INVITE_RECEIVER_BOT_TOKEN"
SLACK_SDK_TEST_CONNECT_INVITE_RECEIVER_BOT_USER_ID = "SLACK_SDK_TEST_CONNECT_INVITE_RECEIVER_BOT_USER_ID"
10 changes: 3 additions & 7 deletions integration_tests/rtm/test_issue_530.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,12 @@ def tearDown(self):

def test_issue_530(self):
try:
rtm_client = RTMClient(
token="I am not a token", run_async=False, loop=asyncio.new_event_loop()
)
rtm_client = RTMClient(token="I am not a token", run_async=False, loop=asyncio.new_event_loop())
rtm_client.start()
self.fail("Raising an error here was expected")
except Exception as e:
self.assertEqual(
"The request to the Slack API failed.\n"
"The server responded with: {'ok': False, 'error': 'invalid_auth'}",
"The request to the Slack API failed.\n" "The server responded with: {'ok': False, 'error': 'invalid_auth'}",
str(e),
)
finally:
Expand All @@ -45,8 +42,7 @@ async def test_issue_530_async(self):
self.fail("Raising an error here was expected")
except Exception as e:
self.assertEqual(
"The request to the Slack API failed.\n"
"The server responded with: {'ok': False, 'error': 'invalid_auth'}",
"The request to the Slack API failed.\n" "The server responded with: {'ok': False, 'error': 'invalid_auth'}",
str(e),
)
finally:
Expand Down
8 changes: 2 additions & 6 deletions integration_tests/rtm/test_issue_558.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ async def process_reactions(**payload):
await asyncio.sleep(3)

try:
first_reaction = await web_client.reactions_add(
channel=channel_id, timestamp=ts, name="eyes"
)
first_reaction = await web_client.reactions_add(channel=channel_id, timestamp=ts, name="eyes")
self.assertFalse("error" in first_reaction)
await asyncio.sleep(2)

Expand All @@ -72,9 +70,7 @@ async def process_reactions(**payload):
# used to start blocking here

# This reaction_add event won't be handled due to a bug
second_reaction = await web_client.reactions_add(
channel=channel_id, timestamp=ts, name="tada"
)
second_reaction = await web_client.reactions_add(channel=channel_id, timestamp=ts, name="tada")
self.assertFalse("error" in second_reaction)
await asyncio.sleep(2)

Expand Down
20 changes: 5 additions & 15 deletions integration_tests/rtm/test_issue_569.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ def run_cpu_monitor(self):
if current_cpu_usage > TestRTMClient.cpu_usage:
TestRTMClient.cpu_usage = current_cpu_usage

TestRTMClient.cpu_monitor = threading.Thread(
target=run_cpu_monitor, args=[self]
)
TestRTMClient.cpu_monitor = threading.Thread(target=run_cpu_monitor, args=[self])
TestRTMClient.cpu_monitor.daemon = True
TestRTMClient.cpu_monitor.start()

Expand All @@ -59,13 +57,9 @@ def tearDown(self):
if hasattr(self, "rtm_client") and not self.rtm_client._stopped:
self.rtm_client.stop()

@pytest.mark.skipif(
condition=is_not_specified(), reason="To avoid rate_limited errors"
)
@pytest.mark.skipif(condition=is_not_specified(), reason="To avoid rate_limited errors")
def test_cpu_usage(self):
self.rtm_client = RTMClient(
token=self.bot_token, run_async=False, loop=asyncio.new_event_loop()
)
self.rtm_client = RTMClient(token=self.bot_token, run_async=False, loop=asyncio.new_event_loop())
self.web_client = WebClient(token=self.bot_token)

self.call_count = 0
Expand Down Expand Up @@ -97,9 +91,7 @@ def connect():
time.sleep(5)

text = "This message was sent by <https://slack.dev/python-slackclient/|python-slackclient>! (test_cpu_usage)"
new_message = self.web_client.chat_postMessage(
channel=self.channel_id, text=text
)
new_message = self.web_client.chat_postMessage(channel=self.channel_id, text=text)
self.assertFalse("error" in new_message)

time.sleep(5)
Expand Down Expand Up @@ -140,9 +132,7 @@ async def send_reply_async(**payload):
await asyncio.sleep(5)

text = "This message was sent by <https://slack.dev/python-slackclient/|python-slackclient>! (test_cpu_usage_async)"
new_message = await self.web_client.chat_postMessage(
channel=self.channel_id, text=text
)
new_message = await self.web_client.chat_postMessage(channel=self.channel_id, text=text)
self.assertFalse("error" in new_message)

await asyncio.sleep(5)
Expand Down
8 changes: 2 additions & 6 deletions integration_tests/rtm/test_issue_605.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ def tearDown(self):
# Reset the decorators by @RTMClient.run_on
RTMClient._callbacks = collections.defaultdict(list)

@pytest.mark.skipif(
condition=is_not_specified(), reason="To avoid rate_limited errors"
)
@pytest.mark.skipif(condition=is_not_specified(), reason="To avoid rate_limited errors")
def test_issue_605(self):
self.text = "This message was sent to verify issue #605"
self.called = False
Expand All @@ -60,9 +58,7 @@ def connect():
token=self.bot_token,
run_async=False,
)
new_message = self.web_client.chat_postMessage(
channel=self.channel_id, text=self.text
)
new_message = self.web_client.chat_postMessage(channel=self.channel_id, text=self.text)
self.assertFalse("error" in new_message)

time.sleep(5)
Expand Down
25 changes: 6 additions & 19 deletions integration_tests/rtm/test_issue_611.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ def tearDown(self):
# Reset the decorators by @RTMClient.run_on
RTMClient._callbacks = collections.defaultdict(list)

@pytest.mark.skipif(
condition=is_not_specified(), reason="To avoid rate limited errors"
)
@pytest.mark.skipif(condition=is_not_specified(), reason="To avoid rate limited errors")
@async_test
async def test_issue_611(self):
channel_id = os.environ[SLACK_SDK_TEST_RTM_TEST_CHANNEL_ID]
Expand All @@ -41,16 +39,11 @@ async def test_issue_611(self):

async def process_messages(**payload):
self.logger.info(payload)
if (
"subtype" in payload["data"]
and payload["data"]["subtype"] == "message_replied"
):
if "subtype" in payload["data"] and payload["data"]["subtype"] == "message_replied":
return # skip

self.message_count += 1
raise Exception(
"something is wrong!"
) # This causes the termination of the process
raise Exception("something is wrong!") # This causes the termination of the process

async def process_reactions(**payload):
self.logger.info(payload)
Expand All @@ -72,21 +65,15 @@ async def process_reactions(**payload):
try:
await asyncio.sleep(3)

first_reaction = await web_client.reactions_add(
channel=channel_id, timestamp=ts, name="eyes"
)
first_reaction = await web_client.reactions_add(channel=channel_id, timestamp=ts, name="eyes")
self.assertFalse("error" in first_reaction)
await asyncio.sleep(2)

should_be_ignored = await web_client.chat_postMessage(
channel=channel_id, text="Hello?", thread_ts=ts
)
should_be_ignored = await web_client.chat_postMessage(channel=channel_id, text="Hello?", thread_ts=ts)
self.assertFalse("error" in should_be_ignored)
await asyncio.sleep(2)

second_reaction = await web_client.reactions_add(
channel=channel_id, timestamp=ts, name="tada"
)
second_reaction = await web_client.reactions_add(channel=channel_id, timestamp=ts, name="tada")
self.assertFalse("error" in second_reaction)
await asyncio.sleep(2)

Expand Down
24 changes: 6 additions & 18 deletions integration_tests/rtm/test_issue_631.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ def tearDown(self):
if hasattr(self, "rtm_client") and not self.rtm_client._stopped:
self.rtm_client.stop()

@pytest.mark.skipif(
condition=is_not_specified(), reason="to avoid rate_limited errors"
)
@pytest.mark.skipif(condition=is_not_specified(), reason="to avoid rate_limited errors")
def test_issue_631_sharing_event_loop(self):
self.success = None
self.text = "This message was sent to verify issue #631"
Expand Down Expand Up @@ -85,9 +83,7 @@ def send_reply(**payload):
if "text" in data and self.text in data["text"]:
channel_id = data["channel"]
thread_ts = data["ts"]
self.success = web_client.chat_postMessage(
channel=channel_id, text="Thanks!", thread_ts=thread_ts
)
self.success = web_client.chat_postMessage(channel=channel_id, text="Thanks!", thread_ts=thread_ts)
except Exception as e:
self.logger.error(traceback.format_exc())
raise e
Expand All @@ -108,9 +104,7 @@ def connect():
token=self.bot_token,
run_async=False,
)
new_message = self.web_client.chat_postMessage(
channel=self.channel_id, text=self.text
)
new_message = self.web_client.chat_postMessage(channel=self.channel_id, text=self.text)
self.assertFalse("error" in new_message)

time.sleep(5)
Expand All @@ -119,9 +113,7 @@ def connect():
t.join(0.3)

# Solution (2) for #631
@pytest.mark.skipif(
condition=is_not_specified(), reason="this is just for reference"
)
@pytest.mark.skipif(condition=is_not_specified(), reason="this is just for reference")
@async_test
async def test_issue_631_sharing_event_loop_async(self):
self.success = None
Expand All @@ -141,9 +133,7 @@ async def send_reply(**payload):
if "text" in data and self.text in data["text"]:
channel_id = data["channel"]
thread_ts = data["ts"]
self.success = await web_client.chat_postMessage(
channel=channel_id, text="Thanks!", thread_ts=thread_ts
)
self.success = await web_client.chat_postMessage(channel=channel_id, text="Thanks!", thread_ts=thread_ts)
except Exception as e:
self.logger.error(traceback.format_exc())
raise e
Expand All @@ -158,9 +148,7 @@ async def send_reply(**payload):
token=self.bot_token,
run_async=True, # all need to be async here
)
new_message = await self.web_client.chat_postMessage(
channel=self.channel_id, text=self.text
)
new_message = await self.web_client.chat_postMessage(channel=self.channel_id, text=self.text)
self.assertFalse("error" in new_message)

await asyncio.sleep(5)
Expand Down
20 changes: 5 additions & 15 deletions integration_tests/rtm/test_issue_701.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ def test_receiving_all_messages(self):
def send_reply(**payload):
self.logger.debug(payload)
web_client, data = payload["web_client"], payload["data"]
web_client.reactions_add(
channel=data["channel"], timestamp=data["ts"], name="eyes"
)
web_client.reactions_add(channel=data["channel"], timestamp=data["ts"], name="eyes")
self.call_count += 1

def connect():
Expand Down Expand Up @@ -84,13 +82,9 @@ def sent_bulk_message():
time.sleep(1)
wait_seconds += 1

self.assertEqual(
total_num * num_of_senders, self.call_count, "The RTM handler failed"
)
self.assertEqual(total_num * num_of_senders, self.call_count, "The RTM handler failed")

@pytest.mark.skipif(
condition=is_not_specified(), reason="to avoid rate_limited errors"
)
@pytest.mark.skipif(condition=is_not_specified(), reason="to avoid rate_limited errors")
@async_test
async def test_receiving_all_messages_async(self):
self.rtm_client = RTMClient(token=self.bot_token, run_async=True)
Expand All @@ -102,9 +96,7 @@ async def test_receiving_all_messages_async(self):
async def send_reply(**payload):
self.logger.debug(payload)
web_client, data = payload["web_client"], payload["data"]
await web_client.reactions_add(
channel=data["channel"], timestamp=data["ts"], name="eyes"
)
await web_client.reactions_add(channel=data["channel"], timestamp=data["ts"], name="eyes")
self.call_count += 1

# intentionally not waiting here
Expand Down Expand Up @@ -141,6 +133,4 @@ def sent_bulk_message():
await asyncio.sleep(1)
wait_seconds += 1

self.assertEqual(
total_num * num_of_senders, self.call_count, "The RTM handler failed"
)
self.assertEqual(total_num * num_of_senders, self.call_count, "The RTM handler failed")
8 changes: 2 additions & 6 deletions integration_tests/rtm/test_rtm_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ def connect():
time.sleep(5)

text = "This message was sent by <https://slack.dev/python-slackclient/|python-slackclient>! (test_basic_operations)"
new_message = self.web_client.chat_postMessage(
channel=self.channel_id, text=text
)
new_message = self.web_client.chat_postMessage(channel=self.channel_id, text=text)
self.assertFalse("error" in new_message)

time.sleep(5)
Expand All @@ -86,9 +84,7 @@ async def send_reply(**payload):
await asyncio.sleep(5)

text = "This message was sent by <https://slack.dev/python-slackclient/|python-slackclient>! (test_basic_operations_async)"
new_message = await self.async_web_client.chat_postMessage(
channel=self.channel_id, text=text
)
new_message = await self.async_web_client.chat_postMessage(channel=self.channel_id, text=text)
self.assertFalse("error" in new_message)
await asyncio.sleep(5)
self.assertEqual(self.sent_text, text)
Loading