def get_inbound_sms_summary_for_service(service_id): count = dao_count_inbound_sms_for_service(service_id) most_recent = dao_get_inbound_sms_for_service(service_id, limit=1) return jsonify(count=count, most_recent=most_recent[0].created_at.isoformat() if most_recent else None)
def get_inbound_sms_summary_for_service(service_id): # this is for the dashboard, so always limit to 7 days, even if they have a longer data retention count = dao_count_inbound_sms_for_service(service_id, limit_days=7) most_recent = dao_get_inbound_sms_for_service(service_id, limit=1) return jsonify(count=count, most_recent=most_recent[0].created_at.isoformat() if most_recent else None)
def test_count_inbound_sms_for_service(notify_db_session): service_one = create_service(service_name='one') service_two = create_service(service_name='two') create_inbound_sms(service_one) create_inbound_sms(service_one) create_inbound_sms(service_two) assert dao_count_inbound_sms_for_service(service_one.id, limit_days=1) == 2
def test_count_inbound_sms_for_service_filters_messages_older_than_n_days( sample_service): # test between evening sunday 2nd of june and morning of monday 3rd create_inbound_sms(sample_service, created_at=datetime(2019, 6, 2, 22, 59)) create_inbound_sms(sample_service, created_at=datetime(2019, 6, 2, 22, 59)) create_inbound_sms(sample_service, created_at=datetime(2019, 6, 2, 23, 1)) with freeze_time('Monday 10th June 2019 12:00'): assert dao_count_inbound_sms_for_service(sample_service.id, limit_days=7) == 1
def test_count_inbound_sms_for_service_filters_messages_older_than_seven_days( sample_service, notify_db_session): create_inbound_sms(sample_service, user_number='447700900111', content='111 2', created_at=datetime(2017, 1, 2)) create_inbound_sms(sample_service, user_number='447700900111', content='111 2', created_at=datetime(2017, 1, 3)) with freeze_time('2017-01-09'): assert dao_count_inbound_sms_for_service(sample_service.id) == 1