Skip to content

Commit

Permalink
refactor: webserver echo output using template file (#1654)
Browse files Browse the repository at this point in the history
* refactor: webserver echo output using template file

* docs: add details to CHANGES

* test: fix assertion in plugin output
  • Loading branch information
sijis authored Sep 1, 2023
1 parent 3b5d859 commit 31f6b11
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fixes:
- chore: bump mr-smithers-excellent/docker-build-push version (#1633)
- docs: fix example code in the testing section (#1643)
- chore: update all core dependencies (#1651)
- fix: use template file for webserver plugin echo output (#1654)


v6.1.9 (2022-06-11)
Expand Down
5 changes: 5 additions & 0 deletions errbot/core_plugins/templates/webserver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*** Test Report
URL: {{url}}
Content: {{content}}
Detected your post as: {{contenttype}}
Status code: {{response.status_code}}
15 changes: 7 additions & 8 deletions errbot/core_plugins/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
from errbot import BotPlugin, botcmd, webhook
from errbot.core_plugins import flask_app

TEST_REPORT = """*** Test Report
URL : %s
Detected your post as : %s
Status code : %i
"""


def make_ssl_certificate(key_path, cert_path):
"""
Expand Down Expand Up @@ -155,7 +149,7 @@ def echo(self, incoming_request):
self.log.debug("Your incoming request is: %s", incoming_request)
return str(incoming_request)

@botcmd(split_args_with=" ")
@botcmd(split_args_with=" ", template="webserver")
def webhook_test(self, _, args):
"""
Test your webhooks from within err.
Expand Down Expand Up @@ -187,7 +181,12 @@ def webhook_test(self, _, args):
self.log.debug("Detected your post as : %s.", contenttype)

response = self.test_app.post(url, params=content, content_type=contenttype)
return TEST_REPORT % (url, contenttype, response.status_code)
return {
"url": url,
"content": content,
"contenttype": contenttype,
"response": response,
}

@botcmd(admin_only=True)
def generate_certificate(self, _, args):
Expand Down
2 changes: 1 addition & 1 deletion tests/commands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def test_webserver_webhook_test(testbot):
"!plugin config Webserver {'HOST': 'localhost', 'PORT': 3141, 'SSL': None}"
)
assert "Plugin configuration done." in testbot.pop_message()
testbot.assertInCommand("!webhook test /echo toto", "Status code : 200")
testbot.assertInCommand("!webhook test /echo toto", "Status code: 200")


def test_activate_reload_and_deactivate(testbot):
Expand Down

0 comments on commit 31f6b11

Please sign in to comment.