|
| 1 | +import logging |
| 2 | +import os |
| 3 | +import unittest |
| 4 | + |
| 5 | +from integration_tests.env_variable_names import ( |
| 6 | + SLACK_SDK_TEST_GRID_ORG_ADMIN_USER_TOKEN, |
| 7 | + SLACK_SDK_TEST_GRID_USER_ID_ADMIN_AUTH, |
| 8 | +) |
| 9 | +from integration_tests.helpers import async_test |
| 10 | +from slack_sdk.web import WebClient |
| 11 | +from slack_sdk.web.async_client import AsyncWebClient |
| 12 | + |
| 13 | + |
| 14 | +class TestWebClient(unittest.TestCase): |
| 15 | + """Runs integration tests with real Slack API""" |
| 16 | + |
| 17 | + def setUp(self): |
| 18 | + self.logger = logging.getLogger(__name__) |
| 19 | + self.org_admin_token = os.environ[SLACK_SDK_TEST_GRID_ORG_ADMIN_USER_TOKEN] |
| 20 | + self.sync_client: WebClient = WebClient(token=self.org_admin_token) |
| 21 | + self.async_client: AsyncWebClient = AsyncWebClient(token=self.org_admin_token) |
| 22 | + self.user_ids = [os.environ[SLACK_SDK_TEST_GRID_USER_ID_ADMIN_AUTH]] |
| 23 | + |
| 24 | + def tearDown(self): |
| 25 | + pass |
| 26 | + |
| 27 | + def test_sync(self): |
| 28 | + client = self.sync_client |
| 29 | + |
| 30 | + list = client.admin_auth_policy_getEntities( |
| 31 | + policy_name="email_password", limit=3 |
| 32 | + ) |
| 33 | + self.assertIsNotNone(list) |
| 34 | + |
| 35 | + assignment = client.admin_auth_policy_assignEntities( |
| 36 | + entity_ids=self.user_ids, |
| 37 | + policy_name="email_password", |
| 38 | + entity_type="USER", |
| 39 | + ) |
| 40 | + self.assertIsNotNone(assignment) |
| 41 | + self.assertEqual( |
| 42 | + list["entity_total_count"] + 1, assignment["entity_total_count"] |
| 43 | + ) |
| 44 | + |
| 45 | + removal = client.admin_auth_policy_removeEntities( |
| 46 | + entity_ids=self.user_ids, |
| 47 | + policy_name="email_password", |
| 48 | + entity_type="USER", |
| 49 | + ) |
| 50 | + self.assertIsNotNone(removal) |
| 51 | + self.assertEqual(list["entity_total_count"], removal["entity_total_count"]) |
| 52 | + |
| 53 | + @async_test |
| 54 | + async def test_async(self): |
| 55 | + client = self.async_client |
| 56 | + |
| 57 | + list = await client.admin_auth_policy_getEntities( |
| 58 | + policy_name="email_password", limit=3 |
| 59 | + ) |
| 60 | + self.assertIsNotNone(list) |
| 61 | + |
| 62 | + assignment = await client.admin_auth_policy_assignEntities( |
| 63 | + entity_ids=self.user_ids, |
| 64 | + policy_name="email_password", |
| 65 | + entity_type="USER", |
| 66 | + ) |
| 67 | + self.assertIsNotNone(assignment) |
| 68 | + self.assertEqual( |
| 69 | + list["entity_total_count"] + 1, assignment["entity_total_count"] |
| 70 | + ) |
| 71 | + |
| 72 | + removal = await client.admin_auth_policy_removeEntities( |
| 73 | + entity_ids=self.user_ids, |
| 74 | + policy_name="email_password", |
| 75 | + entity_type="USER", |
| 76 | + ) |
| 77 | + self.assertIsNotNone(removal) |
| 78 | + self.assertEqual(list["entity_total_count"], removal["entity_total_count"]) |
0 commit comments