First couple of tests. Added httpretty

This commit is contained in:
Pablo Martin 2023-01-09 14:53:54 +01:00
parent 547cb4d059
commit fd854dd8d4
2 changed files with 35 additions and 7 deletions

View file

@ -1,12 +1,39 @@
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():
# Build flow
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)
# Check that server got the thingy
pass
send_message_to_slack_channel(
webhook_url=mock_webhook_url, text_to_send=mock_message_to_channel
)
def test_send_message_to_slack_channel_raises_error():
assert 1 == 0
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():
@ -14,4 +41,4 @@ def test_flow_with_positive_outcome():
def test_flow_with_negative_outcome():
assert 1 == 0
assert 1 == 0