Added tests for slack messaging
This commit is contained in:
parent
fd854dd8d4
commit
4eabcdf6e7
1 changed files with 26 additions and 5 deletions
|
|
@ -3,7 +3,7 @@ import json
|
||||||
import httpretty
|
import httpretty
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from lolafect.slack import send_message_to_slack_channel
|
from lolafect.slack import send_message_to_slack_channel, SendSlackMessageTask
|
||||||
|
|
||||||
|
|
||||||
@httpretty.activate(allow_net_connect=False, verbose=True)
|
@httpretty.activate(allow_net_connect=False, verbose=True)
|
||||||
|
|
@ -36,9 +36,30 @@ def test_send_message_to_slack_channel_response_400_raises_exception():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_flow_with_positive_outcome():
|
@httpretty.activate(allow_net_connect=False, verbose=True)
|
||||||
assert 1 == 0
|
def test_slack_task_reaches_server_successfully():
|
||||||
|
mock_webhook_url = "http://the-webhook-url.com"
|
||||||
|
mock_message_to_channel = "Hi there!"
|
||||||
|
httpretty.register_uri(method=httpretty.POST, uri=mock_webhook_url, status=200)
|
||||||
|
|
||||||
|
slack_task = SendSlackMessageTask()
|
||||||
|
slack_task.run(webhook_url=mock_webhook_url, text_to_send=mock_message_to_channel)
|
||||||
|
|
||||||
|
request_observed_by_server = httpretty.last_request()
|
||||||
|
assert (request_observed_by_server.method == "POST") and (
|
||||||
|
json.loads(request_observed_by_server.body.decode("UTF-8"))
|
||||||
|
== {"text": mock_message_to_channel}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_flow_with_negative_outcome():
|
@httpretty.activate(allow_net_connect=False, verbose=True)
|
||||||
assert 1 == 0
|
def test_slack_task_raises_value_error():
|
||||||
|
mock_webhook_url = "http://the-webhook-url.com"
|
||||||
|
mock_message_to_channel = "Hi there!"
|
||||||
|
httpretty.register_uri(method=httpretty.POST, uri=mock_webhook_url, status=400)
|
||||||
|
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
slack_task = SendSlackMessageTask()
|
||||||
|
slack_task.run(
|
||||||
|
webhook_url=mock_webhook_url, text_to_send=mock_message_to_channel
|
||||||
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue