alerts: Teams webhook fan-out + contract 0.14.0
This commit is contained in:
@@ -25,18 +25,18 @@ def test_noop_when_unset(app):
|
|||||||
def test_posts_when_configured(app):
|
def test_posts_when_configured(app):
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
with patch('shopdb.utils.mailer.get_webhook_config', return_value=CFG), \
|
with patch('shopdb.utils.mailer.get_webhook_config', return_value=CFG), \
|
||||||
patch('shopdb.utils.mailer.requests') as req:
|
patch('shopdb.utils.mailer.requests') as mock_requests:
|
||||||
req.post.return_value.status_code = 200
|
mock_requests.post.return_value.status_code = 200
|
||||||
ok, err = send_webhook('Low stock', 'x down')
|
ok, err = send_webhook('Low stock', 'x down')
|
||||||
assert ok is True and err is None
|
assert ok is True and err is None
|
||||||
assert req.post.call_args[0][0] == CFG['url']
|
assert mock_requests.post.call_args[0][0] == CFG['url']
|
||||||
assert req.post.call_args[1]['json']['@type'] == 'MessageCard'
|
assert mock_requests.post.call_args[1]['json']['@type'] == 'MessageCard'
|
||||||
|
|
||||||
|
|
||||||
def test_send_alert_fans_out_to_webhook(app):
|
def test_send_alert_fans_out_to_webhook(app):
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
with patch('shopdb.utils.mailer.get_webhook_config', return_value=CFG), \
|
with patch('shopdb.utils.mailer.get_webhook_config', return_value=CFG), \
|
||||||
patch('shopdb.utils.mailer.requests') as req:
|
patch('shopdb.utils.mailer.requests') as mock_requests:
|
||||||
req.post.return_value.status_code = 200
|
mock_requests.post.return_value.status_code = 200
|
||||||
send_alert('Subject', '<p>Body</p>')
|
send_alert('Subject', '<p>Body</p>')
|
||||||
assert req.post.called # webhook fired even with no email recipients
|
assert mock_requests.post.called # webhook fired even with no email recipients
|
||||||
|
|||||||
Reference in New Issue
Block a user