def test_fetch_service_data_retention_by_notification_type( sample_service, notification_type, alternate): data_retention = create_service_data_retention( service_id=sample_service.id, notification_type=notification_type) create_service_data_retention(service_id=sample_service.id, notification_type=alternate) result = fetch_service_data_retention_by_notification_type( sample_service.id, notification_type) assert result == data_retention
def get_most_recent_inbound_sms_for_service(service_id): # used on the service inbox page page = request.args.get("page", 1) inbound_data_retention = fetch_service_data_retention_by_notification_type( service_id, "sms") limit_days = inbound_data_retention.days_of_retention if inbound_data_retention else 7 # get most recent message for each user for service results = dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service( service_id, int(page), limit_days) return jsonify(data=[row.serialize() for row in results.items], has_next=results.has_next)
def post_inbound_sms_for_service(service_id): form = validate(request.get_json(), get_inbound_sms_for_service_schema) user_number = form.get("phone_number") if user_number: # we use this to normalise to an international phone number - but this may fail if it's an alphanumeric user_number = try_validate_and_format_phone_number(user_number, international=True) inbound_data_retention = fetch_service_data_retention_by_notification_type( service_id, "sms") limit_days = inbound_data_retention.days_of_retention if inbound_data_retention else 7 results = dao_get_inbound_sms_for_service(service_id, user_number=user_number, limit_days=limit_days) return jsonify(data=[row.serialize() for row in results])
def get_data_retention_for_service_notification_type(service_id, notification_type): data_retention = fetch_service_data_retention_by_notification_type( service_id, notification_type) return jsonify(data_retention.serialize() if data_retention else {}), 200
def test_fetch_service_data_retention_by_notification_type_returns_none_when_no_rows( sample_service): assert not fetch_service_data_retention_by_notification_type( sample_service.id, 'email')