def test_route_generator(self, auth, produces, consumes): # WARNING : You are not expected to understand this the first time. # Go read up on how parameterized decorators work in python # # This test checks that an action is wrapped in multiple decorators and # the order in which the decorators are called. def action(): pass blueprint = Mock(Blueprint) decorated_route = blueprint.route.return_value = Mock() route_generator = RouteGenerator(blueprint) decorated_login_required = auth.login_required.return_value = Mock() parameterized_produces = produces.return_value = Mock() decorated_produces = parameterized_produces.return_value = Mock() route_generator('')(action) auth.login_required.assert_called_once_with(action) produces.assert_called_once_with('application/json') parameterized_produces.assert_called_once_with( decorated_login_required) blueprint.route.assert_called_once_with('') decorated_route.assert_called_once_with(decorated_produces)
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/> from xivo_restapi.resources.configuration.routes import blueprint from xivo_restapi.helpers.route_generator import RouteGenerator from xivo_restapi.helpers import serializer from xivo_dao.data_handler.configuration import services from flask.helpers import make_response from flask.globals import request from xivo_restapi.flask_http_server import content_parser from xivo_restapi.helpers.premacop import Field, Boolean route = RouteGenerator(blueprint) document = content_parser.document(Field('enabled', Boolean())) @route('/live_reload', methods=['GET']) def get_live_reload(): result = services.get_live_reload_status() return make_response(serializer.encode(result), 200) @route('/live_reload', methods=['PUT']) def set_live_reload(): data = document.parse(request) services.set_live_reload_status(data) return make_response('', 204)
# it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. from flask import Blueprint from xivo_restapi import config from xivo_restapi.helpers.route_generator import RouteGenerator from xivo_restapi.resources.lines.actions_sip import blueprint as line_sip_blueprint line_blueprint = Blueprint('lines', __name__, url_prefix='/%s/lines' % config.VERSION_1_1) line_route = RouteGenerator(line_blueprint) from xivo_restapi.resources.lines import actions def register_blueprints(app): app.register_blueprint(line_blueprint) app.register_blueprint(line_sip_blueprint)
# # Copyright (C) 2013 Avencall # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. from flask import Blueprint from xivo_restapi import config from xivo_restapi.helpers.route_generator import RouteGenerator extension_blueprint = Blueprint('extensions', __name__, url_prefix='/%s/extensions' % config.VERSION_1_1) extension_route = RouteGenerator(extension_blueprint) from xivo_restapi.resources.extensions import actions def register_blueprints(app): app.register_blueprint(extension_blueprint)