def create_service_callback_api(service_id): data = request.get_json() validate(data, create_service_callback_api_schema) data["service_id"] = service_id data["callback_type"] = DELIVERY_STATUS_CALLBACK_TYPE callback_api = ServiceCallbackApi(**data) try: save_service_callback_api(callback_api) except SQLAlchemyError as e: return handle_sql_error(e, "service_callback_api") return jsonify(data=callback_api.serialize()), 201
def test_update_service_callback_can_add_two_api_of_different_types(sample_service): delivery_status = ServiceCallbackApi( service_id=sample_service.id, url="https://some_service/callback_endpoint", bearer_token="some_unique_string", updated_by_id=sample_service.users[0].id, callback_type='delivery_status' ) save_service_callback_api(delivery_status) complaint = ServiceCallbackApi( service_id=sample_service.id, url="https://some_service/another_callback_endpoint", bearer_token="different_string", updated_by_id=sample_service.users[0].id, callback_type='complaint' ) save_service_callback_api(complaint) results = ServiceCallbackApi.query.order_by(ServiceCallbackApi.callback_type).all() assert len(results) == 2 assert results[0].serialize() == complaint.serialize() assert results[1].serialize() == delivery_status.serialize()