Esempio n. 1
0
def test_should_set_status_for_all_send_notifications(notify_api, notify_db, notify_db_session, notify_config, mocker):
    mocker.patch('app.sms_wrapper.status', return_value="delivered")

    sent_at = datetime.utcnow()
    create_notification = Notification(
        id=1000,
        to="to",
        message="message",
        created_at=datetime.utcnow(),
        sent_at=sent_at,
        status='sent',
        method='sms',
        job_id=1234,
        sender_id="1",
        sender="twilio"
    )
    db.session.add(create_notification)

    notification = Notification.query.get(1234)
    notification.status = 'sent'
    notification.sender_id = '2'
    notification.sender = 'twilio'
    db.session.add(notification)
    db.session.commit()

    fetch_sms_status()
    read_notification = Notification.query.get(1234)
    assert read_notification.status == 'delivered'
    assert read_notification.delivered_at >= read_notification.created_at
    sms_wrapper.status.assert_has_calls([call("1", "twilio"), call("2", "twilio")])
Esempio n. 2
0
def test_should_not_check_status_unless_sent(notify_api, notify_db, notify_db_session, notify_config, mocker):
    mocker.patch('app.sms_wrapper.status')

    fetch_sms_status()
    read_notification = Notification.query.get(1234)
    assert read_notification.status == 'created'
    assert not read_notification.delivered_at
    sms_wrapper.status.assert_not_called
Esempio n. 3
0
def test_should_not_set_delivered_at_if_not_delivered(notify_api, notify_db, notify_db_session, notify_config, mocker):
    mocker.patch('app.sms_wrapper.status', return_value="failed")
    notification = Notification.query.get(1234)
    notification.status = 'sent'
    notification.sender_id = '1234'
    notification.sender = 'twilio'
    db.session.add(notification)
    db.session.commit()

    fetch_sms_status()
    read_notification = Notification.query.get(1234)
    assert read_notification.status == 'failed'
    assert not read_notification.delivered_at
    sms_wrapper.status.assert_called_once_with("1234", 'twilio')