Skip to content

Commit

Permalink
Add missing properties in Audit Logs API responses
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed May 10, 2022
1 parent 5737bfa commit df3eb55
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 19 deletions.
53 changes: 47 additions & 6 deletions slack_sdk/audit_logs/v1/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ def __init__(
self.unknown_fields = kwargs


class FeatureEnablement:
enabled: Optional[bool]

def __init__(
self,
*,
enabled: Optional[bool] = None,
**kwargs,
) -> None:
self.enabled = enabled
self.unknown_fields = kwargs


class Details:
name: Optional[str]
new_value: Optional[Union[str, List[str], Dict[str, Any]]]
Expand Down Expand Up @@ -218,6 +231,9 @@ class Details:
creator: Optional[str]
team: Optional[str]
app_id: Optional[str]
enable_at_here: Optional[FeatureEnablement]
enable_at_channel: Optional[FeatureEnablement]
can_huddle: Optional[FeatureEnablement]

def __init__(
self,
Expand Down Expand Up @@ -288,6 +304,9 @@ def __init__(
creator: Optional[str] = None,
team: Optional[str] = None,
app_id: Optional[str] = None,
enable_at_here: Optional[FeatureEnablement] = None,
enable_at_channel: Optional[FeatureEnablement] = None,
can_huddle: Optional[FeatureEnablement] = None,
**kwargs,
) -> None:
self.name = name
Expand All @@ -299,8 +318,12 @@ def __init__(
self.non_sso_only = non_sso_only
self.type = type
self.is_workflow = is_workflow
self.inviter = inviter if isinstance(inviter, User) else User(**inviter)
self.kicker = kicker if isinstance(kicker, User) else User(**kicker)
self.inviter = (
inviter if inviter is None or isinstance(inviter, User) else User(**inviter)
)
self.kicker = (
kicker if kicker is None or isinstance(kicker, User) else User(**kicker)
)
self.shared_to = shared_to
self.reason = reason
self.origin_team = origin_team
Expand Down Expand Up @@ -347,22 +370,24 @@ def __init__(
self.is_token_rotation_enabled_app = is_token_rotation_enabled_app
self.old_retention_policy = (
old_retention_policy
if isinstance(old_retention_policy, RetentionPolicy)
if old_retention_policy is None
or isinstance(old_retention_policy, RetentionPolicy)
else RetentionPolicy(**old_retention_policy)
)
self.new_retention_policy = (
new_retention_policy
if isinstance(new_retention_policy, RetentionPolicy)
if new_retention_policy is None
or isinstance(new_retention_policy, RetentionPolicy)
else RetentionPolicy(**new_retention_policy)
)
self.who_can_post = (
who_can_post
if isinstance(who_can_post, ConversationPref)
if who_can_post is None or isinstance(who_can_post, ConversationPref)
else ConversationPref(**who_can_post)
)
self.can_thread = (
can_thread
if isinstance(can_thread, ConversationPref)
if can_thread is None or isinstance(can_thread, ConversationPref)
else ConversationPref(**can_thread)
)
self.is_external_limited = is_external_limited
Expand All @@ -373,6 +398,22 @@ def __init__(
self.creator = creator
self.team = team
self.app_id = app_id
self.enable_at_here = (
enable_at_here
if enable_at_here is None or isinstance(enable_at_here, FeatureEnablement)
else FeatureEnablement(**enable_at_here)
)
self.enable_at_channel = (
enable_at_channel
if enable_at_channel is None
or isinstance(enable_at_channel, FeatureEnablement)
else FeatureEnablement(**enable_at_channel)
)
self.can_huddle = (
can_huddle
if can_huddle is None or isinstance(can_huddle, FeatureEnablement)
else FeatureEnablement(**can_huddle)
)


class Channel:
Expand Down
18 changes: 14 additions & 4 deletions tests/slack_sdk/web/test_web_client_issue_891.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,35 @@ def test_missing_text_warning_chat_update(self):
def test_missing_fallback_warning_chat_postMessage(self):
client = WebClient(base_url="http://localhost:8888", token="xoxb-api_test")
with self.assertWarnsRegex(UserWarning, "`fallback` argument is missing"):
resp = client.chat_postMessage(channel="C111", blocks=[], attachments=[{"text": "hi"}])
resp = client.chat_postMessage(
channel="C111", blocks=[], attachments=[{"text": "hi"}]
)
self.assertIsNone(resp["error"])

def test_missing_fallback_warning_chat_postEphemeral(self):
client = WebClient(base_url="http://localhost:8888", token="xoxb-api_test")
with self.assertWarnsRegex(UserWarning, "`fallback` argument is missing"):
resp = client.chat_postEphemeral(channel="C111", user="U111", blocks=[], attachments=[{"text": "hi"}])
resp = client.chat_postEphemeral(
channel="C111", user="U111", blocks=[], attachments=[{"text": "hi"}]
)
self.assertIsNone(resp["error"])

def test_missing_fallback_warning_chat_scheduleMessage(self):
client = WebClient(base_url="http://localhost:8888", token="xoxb-api_test")
with self.assertWarnsRegex(UserWarning, "`fallback` argument is missing"):
resp = client.chat_scheduleMessage(
channel="C111", post_at="299876400", text="", blocks=[], attachments=[{"text": "hi"}]
channel="C111",
post_at="299876400",
text="",
blocks=[],
attachments=[{"text": "hi"}],
)
self.assertIsNone(resp["error"])

def test_missing_fallback_warning_chat_update(self):
client = WebClient(base_url="http://localhost:8888", token="xoxb-api_test")
with self.assertWarnsRegex(UserWarning, "`fallback` argument is missing"):
resp = client.chat_update(channel="C111", ts="111.222", blocks=[], attachments=[{"text": "hi"}])
resp = client.chat_update(
channel="C111", ts="111.222", blocks=[], attachments=[{"text": "hi"}]
)
self.assertIsNone(resp["error"])
22 changes: 17 additions & 5 deletions tests/slack_sdk_async/web/test_web_client_issue_891.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ async def test_missing_text_warning_chat_postMessage(self):
async def test_missing_text_warning_chat_postEphemeral(self):
client = AsyncWebClient(base_url="http://localhost:8888", token="xoxb-api_test")
with self.assertWarnsRegex(UserWarning, "`text` argument is missing"):
resp = await client.chat_postEphemeral(channel="C111", user="U111", blocks=[])
resp = await client.chat_postEphemeral(
channel="C111", user="U111", blocks=[]
)
self.assertIsNone(resp["error"])

@async_test
Expand All @@ -49,28 +51,38 @@ async def test_missing_text_warning_chat_update(self):
async def test_missing_fallback_warning_chat_postMessage(self):
client = AsyncWebClient(base_url="http://localhost:8888", token="xoxb-api_test")
with self.assertWarnsRegex(UserWarning, "`fallback` argument is missing"):
resp = await client.chat_postMessage(channel="C111", blocks=[], attachments=[{"text": "hi"}])
resp = await client.chat_postMessage(
channel="C111", blocks=[], attachments=[{"text": "hi"}]
)
self.assertIsNone(resp["error"])

@async_test
async def test_missing_fallback_warning_chat_postEphemeral(self):
client = AsyncWebClient(base_url="http://localhost:8888", token="xoxb-api_test")
with self.assertWarnsRegex(UserWarning, "`fallback` argument is missing"):
resp = await client.chat_postEphemeral(channel="C111", user="U111", blocks=[], attachments=[{"text": "hi"}])
resp = await client.chat_postEphemeral(
channel="C111", user="U111", blocks=[], attachments=[{"text": "hi"}]
)
self.assertIsNone(resp["error"])

@async_test
async def test_missing_fallback_warning_chat_scheduleMessage(self):
client = AsyncWebClient(base_url="http://localhost:8888", token="xoxb-api_test")
with self.assertWarnsRegex(UserWarning, "`text` argument is missing"):
resp = await client.chat_scheduleMessage(
channel="C111", post_at="299876400", text="", blocks=[], attachments=[{"text": "hi"}]
channel="C111",
post_at="299876400",
text="",
blocks=[],
attachments=[{"text": "hi"}],
)
self.assertIsNone(resp["error"])

@async_test
async def test_missing_fallback_warning_chat_update(self):
client = AsyncWebClient(base_url="http://localhost:8888", token="xoxb-api_test")
with self.assertWarnsRegex(UserWarning, "`text` argument is missing"):
resp = await client.chat_update(channel="C111", ts="111.222", blocks=[], attachments=[{"text": "hi"}])
resp = await client.chat_update(
channel="C111", ts="111.222", blocks=[], attachments=[{"text": "hi"}]
)
self.assertIsNone(resp["error"])
18 changes: 14 additions & 4 deletions tests/web/test_web_client_issue_891.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,35 @@ def test_missing_text_warning_chat_update(self):
def test_missing_fallback_warning_chat_postMessage(self):
client = WebClient(base_url="http://localhost:8888", token="xoxb-api_test")
with self.assertWarnsRegex(UserWarning, "`fallback` argument is missing"):
resp = client.chat_postMessage(channel="C111", blocks=[], attachments=[{"text": "hi"}])
resp = client.chat_postMessage(
channel="C111", blocks=[], attachments=[{"text": "hi"}]
)
self.assertIsNone(resp["error"])

def test_missing_fallback_warning_chat_postEphemeral(self):
client = WebClient(base_url="http://localhost:8888", token="xoxb-api_test")
with self.assertWarnsRegex(UserWarning, "`fallback` argument is missing"):
resp = client.chat_postEphemeral(channel="C111", user="U111", blocks=[], attachments=[{"text": "hi"}])
resp = client.chat_postEphemeral(
channel="C111", user="U111", blocks=[], attachments=[{"text": "hi"}]
)
self.assertIsNone(resp["error"])

def test_missing_fallback_warning_chat_scheduleMessage(self):
client = WebClient(base_url="http://localhost:8888", token="xoxb-api_test")
with self.assertWarnsRegex(UserWarning, "`fallback` argument is missing"):
resp = client.chat_scheduleMessage(
channel="C111", post_at="299876400", text="", blocks=[], attachments=[{"text": "hi"}]
channel="C111",
post_at="299876400",
text="",
blocks=[],
attachments=[{"text": "hi"}],
)
self.assertIsNone(resp["error"])

def test_missing_fallback_warning_chat_update(self):
client = WebClient(base_url="http://localhost:8888", token="xoxb-api_test")
with self.assertWarnsRegex(UserWarning, "`fallback` argument is missing"):
resp = client.chat_update(channel="C111", ts="111.222", blocks=[], attachments=[{"text": "hi"}])
resp = client.chat_update(
channel="C111", ts="111.222", blocks=[], attachments=[{"text": "hi"}]
)
self.assertIsNone(resp["error"])

0 comments on commit df3eb55

Please sign in to comment.