Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle validity and change handling order #14

Merged
merged 1 commit into from
Jul 10, 2024
Merged
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
96 changes: 51 additions & 45 deletions slack_server_mock/servers/http/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,78 +55,84 @@ class AuthTestHandler(BaseSlackHandler): # pylint: disable=W0223

def post(self):
""" Handle post request """
if self._is_request_valid():
self.write(
{
"ok": True,
"url": "https://xyz.slack.com/",
"team": "Testing Workspace",
"user": "bot-user",
"team_id": "T111",
"user_id": "W11",
"bot_id": "B111",
"enterprise_id": "E111",
"is_enterprise_install": False,
}
)
if not self._is_request_valid():
return
self.write(
{
"ok": True,
"url": "https://xyz.slack.com/",
"team": "Testing Workspace",
"user": "bot-user",
"team_id": "T111",
"user_id": "W11",
"bot_id": "B111",
"enterprise_id": "E111",
"is_enterprise_install": False,
}
)


class AppsConnectionsOpenHandler(BaseSlackHandler): # pylint: disable=W0223
""" Handler for apps.connection.open endpoint """

def post(self):
""" Handle post request """
if self._is_request_valid():
port = global_injector.get(Settings).slack_server.websocket_port
self.write(
{
"ok": True,
"url": f"ws://{self.request.host_name}:{port}/link",
}
)
if not self._is_request_valid():
return
port = global_injector.get(Settings).slack_server.websocket_port
self.write(
{
"ok": True,
"url": f"ws://{self.request.host_name}:{port}/link",
}
)


class ApiTestHandler(BaseSlackHandler): # pylint: disable=W0223
""" Handler for api.test endpoint """

def post(self):
""" Handle post request """
if self._is_request_valid():
data = load_json_from_body(self)
if not data:
return
self.write({"ok": True, "args": data})
if not self._is_request_valid():
return
data = load_json_from_body(self)
if not data:
return
self.write({"ok": True, "args": data})


class ChatPostMessageHandler(BaseSlackHandler): # pylint: disable=W0223
""" Handler for chat.postMessage endpoint """

def post(self):
""" Handle post request """
if self._is_request_valid():
data = load_json_from_body(self)
if not data:
return

global_injector.get(Actor).message_received(data['text'])
ts = datetime.timestamp(datetime.now())
self.write(
{
"ok": True,
"channel": data['channel'],
"ts": ts,
"message": {
"text": data['text'],
"type": "message",
"ts": ts
}
if not self._is_request_valid():
return
data = load_json_from_body(self)
if not data:
return

global_injector.get(Actor).message_received(data['text'])
ts = datetime.timestamp(datetime.now())
self.write(
{
"ok": True,
"channel": data['channel'],
"ts": ts,
"message": {
"text": data['text'],
"type": "message",
"ts": ts
}
)
}
)


class ConversationsListHandler(BaseSlackHandler): # pylint: disable=W0223
""" Handler for conversations.list endpoint """
def _handle(self):
if not self._is_request_valid():
return
self.write(
{
"ok": True,
Expand Down