aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2022-11-23 19:58:10 +0100
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 11:32:53 +0100
commitf2fc8b771c5f7c93f6bbfd44ad42494eaed107a6 (patch)
treed80072c5eb8b539a6148a4a02e04ec3a4f6d8f8b
parentc3f6d47f902741e99dc1d23e56038d24c383d74e (diff)
downloadwee-slack-f2fc8b771c5f7c93f6bbfd44ad42494eaed107a6.tar.gz
Add some mock data files
-rwxr-xr-xgenerate_types_from_mocks.py66
-rw-r--r--mock_data/slack_info_channel_group.json42
-rw-r--r--mock_data/slack_info_channel_private.json42
-rw-r--r--mock_data/slack_info_channel_public.json49
-rw-r--r--mock_data/slack_info_im.json42
-rw-r--r--mock_data/slack_info_mpim_channel.json42
-rw-r--r--mock_data/slack_info_mpim_group.json42
7 files changed, 325 insertions, 0 deletions
diff --git a/generate_types_from_mocks.py b/generate_types_from_mocks.py
new file mode 100755
index 0000000..d435c51
--- /dev/null
+++ b/generate_types_from_mocks.py
@@ -0,0 +1,66 @@
+#!/usr/bin/python
+
+import ast
+import json
+from typing import Any, Generator, List
+
+
+def create_ann_assign(name: str, type_name: str) -> ast.AnnAssign:
+ return ast.AnnAssign(ast.Name(name), ast.Name(type_name), simple=True)
+
+
+def create_class(name: str, body: List[ast.stmt]) -> ast.ClassDef:
+ return ast.ClassDef(name, [ast.Name("TypedDict")], [], body=body, decorator_list=[])
+
+
+def generate(names: List[str], body: Any) -> Generator[ast.stmt, None, str]:
+ if isinstance(body, dict):
+ class_body: List[ast.stmt] = []
+ for key, value in body.items():
+ if not isinstance(key, str):
+ raise Exception("Only string keys are supported")
+ type_name = yield from generate(names + [key.capitalize()], value)
+ item = create_ann_assign(key, type_name)
+ class_body.append(item)
+ class_name = "".join(names)
+ yield create_class(class_name, class_body)
+ return class_name
+ elif isinstance(body, list):
+ if body:
+ first = yield from generate(names, body[0])
+ return f"List[{first}]"
+ else:
+ return "List"
+ else:
+ if body is None:
+ return "None"
+ else:
+ return type(body).__name__
+
+
+def ast_equal(first: ast.stmt, second: ast.stmt):
+ return ast.unparse(first) == ast.unparse(second)
+
+
+def generate_from_file(path: str, name: str):
+ with open(path) as f:
+ j = json.loads(f.read())
+ yield from generate([name], j)
+
+
+types = [
+ [ast.ImportFrom("typing", [ast.Name("TypedDict"), ast.Name("Union")])],
+ generate_from_file("mock_data/slack_info_channel_group.json", "ChannelGroup"),
+ generate_from_file("mock_data/slack_info_channel_private.json", "ChannelPrivate"),
+ generate_from_file("mock_data/slack_info_channel_public.json", "ChannelPublic"),
+ generate_from_file("mock_data/slack_info_im.json", "Im"),
+ generate_from_file("mock_data/slack_info_mpim_channel.json", "MpimChannel"),
+ generate_from_file("mock_data/slack_info_mpim_group.json", "MpimGroup"),
+]
+
+for x in types:
+ for y in x:
+ print(ast.unparse(y))
+ print()
+
+# print('SlackConversationInfoResponse = Union[]')
diff --git a/mock_data/slack_info_channel_group.json b/mock_data/slack_info_channel_group.json
new file mode 100644
index 0000000..7b84cff
--- /dev/null
+++ b/mock_data/slack_info_channel_group.json
@@ -0,0 +1,42 @@
+{
+ "ok": true,
+ "channel": {
+ "id": "GNLENA84B",
+ "name": "channel-created-as-private-initially",
+ "is_channel": false,
+ "is_group": true,
+ "is_im": false,
+ "is_mpim": false,
+ "is_private": true,
+ "created": 1569952911,
+ "is_archived": false,
+ "is_general": false,
+ "unlinked": 0,
+ "name_normalized": "channel-created-as-private-initially",
+ "is_shared": false,
+ "is_org_shared": false,
+ "is_pending_ext_shared": false,
+ "pending_shared": [],
+ "context_team_id": "T0FC8BFQR",
+ "parent_conversation": null,
+ "creator": "U7JNGMGEB",
+ "is_ext_shared": false,
+ "shared_team_ids": [
+ "T0FC8BFQR"
+ ],
+ "pending_connected_team_ids": [],
+ "is_member": true,
+ "last_read": "1587046064.000200",
+ "is_open": true,
+ "topic": {
+ "value": "",
+ "creator": "",
+ "last_set": 0
+ },
+ "purpose": {
+ "value": "",
+ "creator": "",
+ "last_set": 0
+ }
+ }
+}
diff --git a/mock_data/slack_info_channel_private.json b/mock_data/slack_info_channel_private.json
new file mode 100644
index 0000000..de34e69
--- /dev/null
+++ b/mock_data/slack_info_channel_private.json
@@ -0,0 +1,42 @@
+{
+ "ok": true,
+ "channel": {
+ "id": "CNZQKUU9M",
+ "name": "channel-created-as-public-then-converted-to-private",
+ "is_channel": true,
+ "is_group": false,
+ "is_im": false,
+ "is_mpim": false,
+ "is_private": true,
+ "created": 1569952842,
+ "is_archived": false,
+ "is_general": false,
+ "unlinked": 0,
+ "name_normalized": "channel-created-as-public-then-converted-to-private",
+ "is_shared": false,
+ "is_org_shared": false,
+ "is_pending_ext_shared": false,
+ "pending_shared": [],
+ "context_team_id": "T0FC8BFQR",
+ "parent_conversation": null,
+ "creator": "U7JNGMGEB",
+ "is_ext_shared": false,
+ "shared_team_ids": [
+ "T0FC8BFQR"
+ ],
+ "pending_connected_team_ids": [],
+ "is_member": true,
+ "last_read": "1664834740.783869",
+ "is_open": true,
+ "topic": {
+ "value": "",
+ "creator": "",
+ "last_set": 0
+ },
+ "purpose": {
+ "value": "",
+ "creator": "",
+ "last_set": 0
+ }
+ }
+}
diff --git a/mock_data/slack_info_channel_public.json b/mock_data/slack_info_channel_public.json
new file mode 100644
index 0000000..e0b342a
--- /dev/null
+++ b/mock_data/slack_info_channel_public.json
@@ -0,0 +1,49 @@
+{
+ "ok": true,
+ "channel": {
+ "id": "CK4M8EWJE",
+ "name": "channel1",
+ "is_channel": true,
+ "is_group": false,
+ "is_im": false,
+ "is_mpim": false,
+ "is_private": false,
+ "created": 1560285085,
+ "is_archived": false,
+ "is_general": false,
+ "unlinked": 0,
+ "name_normalized": "channel1",
+ "is_shared": false,
+ "is_org_shared": false,
+ "is_pending_ext_shared": false,
+ "pending_shared": [],
+ "context_team_id": "T0FC8BFQR",
+ "parent_conversation": null,
+ "creator": "U7JNGMGEB",
+ "is_ext_shared": false,
+ "shared_team_ids": [
+ "T0FC8BFQR"
+ ],
+ "pending_connected_team_ids": [],
+ "is_member": true,
+ "last_read": "1667127924.150389",
+ "topic": {
+ "value": "å\nø\næ",
+ "creator": "U7JNGMGEB",
+ "last_set": 1590871910
+ },
+ "purpose": {
+ "value": "",
+ "creator": "",
+ "last_set": 0
+ },
+ "previous_names": [
+ "channel15",
+ "channel1",
+ "channel14",
+ "channel13",
+ "channel12",
+ "channel11"
+ ]
+ }
+}
diff --git a/mock_data/slack_info_im.json b/mock_data/slack_info_im.json
new file mode 100644
index 0000000..bfb43bb
--- /dev/null
+++ b/mock_data/slack_info_im.json
@@ -0,0 +1,42 @@
+{
+ "ok": true,
+ "channel": {
+ "id": "D9N2KD0V6",
+ "created": 1520893592,
+ "is_archived": false,
+ "is_im": true,
+ "is_org_shared": false,
+ "context_team_id": "T0FC8BFQR",
+ "user": "U9NJX9J83",
+ "last_read": "1665038145.797419",
+ "latest": {
+ "client_msg_id": "0f1253bc-9159-47ec-b184-e106eae4bd3c",
+ "type": "message",
+ "text": "7",
+ "user": "U9NJX9J83",
+ "ts": "1665038145.797419",
+ "blocks": [
+ {
+ "type": "rich_text",
+ "block_id": "w6H",
+ "elements": [
+ {
+ "type": "rich_text_section",
+ "elements": [
+ {
+ "type": "text",
+ "text": "7"
+ }
+ ]
+ }
+ ]
+ }
+ ],
+ "team": "T0FC8BFQR"
+ },
+ "unread_count": 0,
+ "unread_count_display": 0,
+ "is_open": true,
+ "priority": 0
+ }
+}
diff --git a/mock_data/slack_info_mpim_channel.json b/mock_data/slack_info_mpim_channel.json
new file mode 100644
index 0000000..1391fa3
--- /dev/null
+++ b/mock_data/slack_info_mpim_channel.json
@@ -0,0 +1,42 @@
+{
+ "ok": true,
+ "channel": {
+ "id": "C042VL9076F",
+ "name": "mpdm-trygveaa029--trygveaa--slack.test-1",
+ "is_channel": true,
+ "is_group": false,
+ "is_im": false,
+ "is_mpim": true,
+ "is_private": true,
+ "created": 1663514345,
+ "is_archived": false,
+ "is_general": false,
+ "unlinked": 0,
+ "name_normalized": "mpdm-trygveaa029--trygveaa--slack.test-1",
+ "is_shared": false,
+ "is_org_shared": false,
+ "is_pending_ext_shared": false,
+ "pending_shared": [],
+ "context_team_id": "T0FC8BFQR",
+ "parent_conversation": null,
+ "creator": "U9NJX9J83",
+ "is_ext_shared": false,
+ "shared_team_ids": [
+ "T0FC8BFQR"
+ ],
+ "pending_connected_team_ids": [],
+ "is_member": true,
+ "last_read": "1664834714.170159",
+ "is_open": true,
+ "topic": {
+ "value": "",
+ "creator": "",
+ "last_set": 0
+ },
+ "purpose": {
+ "value": "Group messaging with: @trygveaa029 @trygveaa @slack.test",
+ "creator": "U9NJX9J83",
+ "last_set": 1663514345
+ }
+ }
+}
diff --git a/mock_data/slack_info_mpim_group.json b/mock_data/slack_info_mpim_group.json
new file mode 100644
index 0000000..ebb05ba
--- /dev/null
+++ b/mock_data/slack_info_mpim_group.json
@@ -0,0 +1,42 @@
+{
+ "ok": true,
+ "channel": {
+ "id": "GKHEJUM1N",
+ "name": "mpdm-trygveaa029--trygveaa--trygveaa243-1",
+ "is_channel": false,
+ "is_group": true,
+ "is_im": false,
+ "is_mpim": true,
+ "is_private": true,
+ "created": 1560376096,
+ "is_archived": false,
+ "is_general": false,
+ "unlinked": 0,
+ "name_normalized": "mpdm-trygveaa029--trygveaa--trygveaa243-1",
+ "is_shared": false,
+ "is_org_shared": false,
+ "is_pending_ext_shared": false,
+ "pending_shared": [],
+ "context_team_id": "T0FC8BFQR",
+ "parent_conversation": null,
+ "creator": "U9NJX9J83",
+ "is_ext_shared": false,
+ "shared_team_ids": [
+ "T0FC8BFQR"
+ ],
+ "pending_connected_team_ids": [],
+ "is_member": true,
+ "last_read": "1664834869.209949",
+ "is_open": true,
+ "topic": {
+ "value": "",
+ "creator": "",
+ "last_set": 0
+ },
+ "purpose": {
+ "value": "Group messaging with: @trygveaa029 @trygveaa @trygveaa243",
+ "creator": "U9NJX9J83",
+ "last_set": 1560376096
+ }
+ }
+}