Пример #1
0
def test_inbound_handler_expired_appointment(mock_send_reply, appointment_details):
    contact_0 = '12223333333'
    contact_1 = '12229991111'
    appt_str_time_0 = '2000-01-01T13:00+0000'
    appt_str_time_1 = '2020-01-01T12:00+0000'
    notify_win = 24
    location = 'Flowroute HQ'
    participant_0 = 'Development Teams'
    reminder_0 = Reminder(contact_0, arrow.get(appt_str_time_0), notify_win,
                          location, participant_0)
    reminder_1 = Reminder(contact_1, arrow.get(appt_str_time_1),
                          notify_win, location, participant_0)
    db_session.add(reminder_0)
    db_session.add(reminder_1)
    db_session.commit()
    client = app.test_client()
    inbound_req = {'to': 'myflowroutenumber',
                   'from': reminder_1.contact_num,
                   'body': 'Yes'}
    resp = client.post('/', data=json.dumps(inbound_req),
                       content_type='application/json')
    reminders = Reminder.query.all()
    assert mock_send_reply.apply_async.called is True
    assert len(reminders) == 1
    reminders[0].contact_num == contact_1
    assert resp.status_code == 200
Пример #2
0
def test_inbound_handler_expired_appointment(mock_send_reply,
                                             appointment_details):
    contact_0 = '12223333333'
    contact_1 = '12229991111'
    appt_str_time_0 = '2000-01-01T13:00+0000'
    appt_str_time_1 = '2020-01-01T12:00+0000'
    notify_win = 24
    location = 'Flowroute HQ'
    participant_0 = 'Development Teams'
    reminder_0 = Reminder(contact_0, arrow.get(appt_str_time_0), notify_win,
                          location, participant_0)
    reminder_1 = Reminder(contact_1, arrow.get(appt_str_time_1), notify_win,
                          location, participant_0)
    db_session.add(reminder_0)
    db_session.add(reminder_1)
    db_session.commit()
    client = app.test_client()
    inbound_req = {
        'to': 'myflowroutenumber',
        'from': reminder_1.contact_num,
        'body': 'Yes'
    }
    resp = client.post('/',
                       data=json.dumps(inbound_req),
                       content_type='application/json')
    reminders = Reminder.query.all()
    assert mock_send_reply.apply_async.called is True
    assert len(reminders) == 1
    reminders[0].contact_num == contact_1
    assert resp.status_code == 200
Пример #3
0
def test_get_reminders_success(new_appointments):
    client = app.test_client()
    resp = client.get('/reminder')
    assert resp.status_code == 200
    data = json.loads(resp.data)
    assert len(data['reminders']) == len(new_appointments)
    for reminder in data['reminders']:
        for field in REMINDER_FIELDS:
            assert field in reminder
Пример #4
0
def test_get_reminders_success(new_appointments):
    client = app.test_client()
    resp = client.get('/reminder')
    assert resp.status_code == 200
    data = json.loads(resp.data)
    assert len(data['reminders']) == len(new_appointments)
    for reminder in data['reminders']:
        for field in REMINDER_FIELDS:
            assert field in reminder
Пример #5
0
def test_get_reminder_success(new_appointment):
    reminder_id = new_appointment.id
    db_session.add(new_appointment)
    db_session.commit()
    client = app.test_client()
    resp = client.get('/reminder/{}'.format(reminder_id))
    assert resp.status_code == 200
    details = json.loads(resp.data)
    for field in REMINDER_FIELDS:
        assert field in details
Пример #6
0
def test_get_reminder_success(new_appointment):
    reminder_id = new_appointment.id
    db_session.add(new_appointment)
    db_session.commit()
    client = app.test_client()
    resp = client.get('/reminder/{}'.format(reminder_id))
    assert resp.status_code == 200
    details = json.loads(resp.data)
    for field in REMINDER_FIELDS:
        assert field in details
Пример #7
0
def test_delete_reminder_success(new_appointment):
    reminder_id = new_appointment.id
    db_session.add(new_appointment)
    db_session.commit()
    client = app.test_client()
    stored_reminder = Reminder.query.filter_by(id=reminder_id).one()
    assert stored_reminder is not None
    resp = client.delete('/reminder/{}'.format(reminder_id))
    assert resp.status_code == 200
    with pytest.raises(NoResultFound):
        Reminder.query.filter_by(id=reminder_id).one()
Пример #8
0
def test_delete_reminder_success(new_appointment):
    reminder_id = new_appointment.id
    db_session.add(new_appointment)
    db_session.commit()
    client = app.test_client()
    stored_reminder = Reminder.query.filter_by(id=reminder_id).one()
    assert stored_reminder is not None
    resp = client.delete('/reminder/{}'.format(reminder_id))
    assert resp.status_code == 200
    with pytest.raises(NoResultFound):
        Reminder.query.filter_by(id=reminder_id).one()
Пример #9
0
def test_add_reminder_unique_constraint(mock_send_reminder, new_appointment,
                                        appointment_details):
    client = app.test_client()
    db_session.add(new_appointment)
    db_session.commit()
    dup_num = new_appointment.contact_num
    appointment_details['contact_number'] = dup_num
    resp = client.post('/reminder', data=json.dumps(appointment_details),
                       content_type='application/json')
    data = json.loads(resp.data)
    assert data['message'] == ("unable to create a new reminder. duplicate "
                               "contact_number {}".format(dup_num))
    assert resp.status_code == 400
Пример #10
0
def test_add_reminder_unique_constraint(mock_send_reminder, new_appointment,
                                        appointment_details):
    client = app.test_client()
    db_session.add(new_appointment)
    db_session.commit()
    dup_num = new_appointment.contact_num
    appointment_details['contact_number'] = dup_num
    resp = client.post('/reminder',
                       data=json.dumps(appointment_details),
                       content_type='application/json')
    data = json.loads(resp.data)
    assert data['message'] == ("unable to create a new reminder. duplicate "
                               "contact_number {}".format(dup_num))
    assert resp.status_code == 400
Пример #11
0
def test_add_reminder_success(mock_send_reminder, appointment_details):
    client = app.test_client()
    resp = client.post('/reminder', data=json.dumps(appointment_details),
                       content_type='application/json')
    assert resp.status_code == 200
    assert mock_send_reminder.apply_async.called == 1
    call_args = mock_send_reminder.apply_async.call_args
    reminder_time = appointment_details['appointment_time']
    dt = arrow.get(reminder_time, "YYYY-MM-DDTHH:mmZ")
    notify_sys_dt = dt.replace(hours=-int(
        appointment_details['notify_window']))
    reminder_id = call_args[1]['args'][0]
    reminder = Reminder.query.one()
    assert reminder.id == reminder_id
    assert arrow.get(call_args[1]['eta']) == notify_sys_dt
Пример #12
0
def test_add_reminder_success(mock_send_reminder, appointment_details):
    client = app.test_client()
    resp = client.post('/reminder',
                       data=json.dumps(appointment_details),
                       content_type='application/json')
    assert resp.status_code == 200
    assert mock_send_reminder.apply_async.called == 1
    call_args = mock_send_reminder.apply_async.call_args
    reminder_time = appointment_details['appointment_time']
    dt = arrow.get(reminder_time, "YYYY-MM-DDTHH:mmZ")
    notify_sys_dt = dt.replace(
        hours=-int(appointment_details['notify_window']))
    reminder_id = call_args[1]['args'][0]
    reminder = Reminder.query.one()
    assert reminder.id == reminder_id
    assert arrow.get(call_args[1]['eta']) == notify_sys_dt
Пример #13
0
def test_inbound_handler_success(mock_send_reply, new_appointment,
                                 response, status):
    appt_id = new_appointment.id
    db_session.add(new_appointment)
    db_session.commit()
    client = app.test_client()
    inbound_req = {'to': 'myflowroutenumber',
                   'from': new_appointment.contact_num,
                   'body': response,
                   }
    resp = client.post('/', data=json.dumps(inbound_req),
                       content_type='application/json')
    assert mock_send_reply.apply_async.called == 1
    assert resp.status_code == 200
    appt = Reminder.query.filter_by(id=appt_id).one()
    assert appt.will_attend is status
Пример #14
0
def test_inbound_handler_success(mock_send_reply, new_appointment, response,
                                 status):
    appt_id = new_appointment.id
    db_session.add(new_appointment)
    db_session.commit()
    client = app.test_client()
    inbound_req = {
        'to': 'myflowroutenumber',
        'from': new_appointment.contact_num,
        'body': response,
    }
    resp = client.post('/',
                       data=json.dumps(inbound_req),
                       content_type='application/json')
    assert mock_send_reply.apply_async.called == 1
    assert resp.status_code == 200
    appt = Reminder.query.filter_by(id=appt_id).one()
    assert appt.will_attend is status