Skip to content

Commit

Permalink
add has_route to plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
zpriddy committed Apr 20, 2020
1 parent 8503e9c commit d223676
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = glados
version = 0.0.1-dev22
version = 0.0.1-dev23
description = A library to help with slackbot development
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
20 changes: 20 additions & 0 deletions src/glados/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,26 @@ def respond_to_url(self, request: GladosRequest, text: str, **kwargs):
r = requests.post(request.response_url, json=kwargs)
logging.info(f"slack response: {r}")

def has_route(self, route: str) -> bool:
"""See if route exists.
Parameters
----------
route : route to check
Returns
-------
True if route exists else false
"""
route_extended = f"{self.bot.name}_{route}"
for r_type, route_entry in self._routes.items():
try:
if list(route_entry.keys())[0] in [route, route_extended]:
return True
except IndexError:
continue
return False

@property
def routes(self) -> List[GladosRoute]:
"""List all routes for the plugin."""
Expand Down
2 changes: 2 additions & 0 deletions tests/test_glados_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def test_add_route(MockGladosPlugin):
assert len(MockGladosPlugin.routes) == 1

route = MockGladosPlugin.routes[0]
print(MockGladosPlugin._routes)

assert MockGladosPlugin.has_route("send_message") == True
assert route.route == "bot_send_message"
assert route.function(None)

Expand Down

0 comments on commit d223676

Please sign in to comment.