def test_fail_send(): responses.add(responses.POST, 'https://api.courier.com/send', status=400, content_type='application/json', body='{"message": "An error occured"}') c = Courier(auth_token='123456789ABCDF') with pytest.raises(CourierAPIException): c.send(event='1234', recipient='4321')
def test_success_send(): responses.add(responses.POST, 'https://api.courier.com/send', status=200, content_type='application/json', body='{"status": "ok"}') c = Courier(auth_token='123456789ABCDF') r = c.send(event='1234', recipient='4321') assert r == {"status": "ok"}
def test_success_send_idempotent(): responses.add(responses.POST, 'https://api.courier.com/send', status=200, content_type='application/json', body='{"status": "ok"}') c = Courier(auth_token='123456789ABCDF') r = c.send(event='1234', recipient='4321', idempotency_key='1234ABCD') assert responses.calls[0].request.headers.get( 'Idempotency-Key') == '1234ABCD' assert r == {"status": "ok"}
def test_success_send_idempotent(): responses.add(responses.POST, 'https://api.courier.com/send', status=200, content_type='application/json', body='{"status": "ok"}') c = Courier(auth_token='123456789ABCDF') expiration_date = (datetime.now() + timedelta(days=7)).isoformat() r = c.send(event='1234', recipient='4321', idempotency_key='1234ABCD', idempotency_expiration=expiration_date) assert responses.calls[0].request.headers.get( 'Idempotency-Key') == '1234ABCD' assert responses.calls[0].request.headers.get( 'x-idempotency-expiration') == expiration_date assert r == {"status": "ok"}
def test_success_send_with_options(): responses.add(responses.POST, 'https://api.trycourier.app/send', status=200, content_type='application/json', body='{"status": "ok"}') c = Courier(auth_token='123456789ABCDF') r = c.send(event='1234', recipient='4321', profile={'email': '*****@*****.**'}, preferences={'preferrred_channel': 'email'}, override={'provider': {}}) request_params = json.loads( responses.calls[0].request.body.decode('utf-8')) assert r == {"status": "ok"} assert request_params["profile"] == {'email': '*****@*****.**'} assert request_params["preferences"] == {'preferrred_channel': 'email'} assert request_params["override"] == {'provider': {}}