44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
import json
|
|
|
|
import httpretty
|
|
import pytest
|
|
|
|
from lolafect.slack import send_message_to_slack_channel
|
|
|
|
|
|
@httpretty.activate(allow_net_connect=False, verbose=True)
|
|
def test_send_message_to_slack_channel_works_properly():
|
|
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)
|
|
|
|
send_message_to_slack_channel(
|
|
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}
|
|
)
|
|
|
|
|
|
@httpretty.activate(allow_net_connect=False, verbose=True)
|
|
def test_send_message_to_slack_channel_response_400_raises_exception():
|
|
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):
|
|
send_message_to_slack_channel(
|
|
webhook_url=mock_webhook_url, text_to_send=mock_message_to_channel
|
|
)
|
|
|
|
|
|
def test_flow_with_positive_outcome():
|
|
assert 1 == 0
|
|
|
|
|
|
def test_flow_with_negative_outcome():
|
|
assert 1 == 0
|