def test_connect(self): handler = XMLRPCHandler('api') app = Flask(__name__) handler.connect(app, '/api') if PY2: app_handler = app.view_functions[handler.endpoint_name].im_self else: app_handler = app.view_functions[handler.endpoint_name].__self__ assert app_handler is handler
def test_namespaces(self): handler = XMLRPCHandler('api') ns = handler.namespace('ns') assert ns.prefix == 'ns' assert ns.handler is handler misc = ns.namespace('misc') assert misc.prefix == 'ns.misc' assert misc.handler is handler misc.register(hello) assert handler.funcs['ns.misc.hello'] is hello
def test_creation(self): handler = XMLRPCHandler('api') assert handler.endpoint_name == 'api' assert 'system.listMethods' in handler.funcs assert 'system.methodHelp' in handler.funcs assert 'system.methodSignature' in handler.funcs assert 'system.multicall' not in handler.funcs
def test_test_xmlrpc_call(self): handler = XMLRPCHandler('api') app = Flask(__name__) handler.connect(app, '/api') handler.register(hello) assert (test_xmlrpc_call(app.test_client(), '/api', 'hello') == 'Hello, world!')
def test_call(self): handler = XMLRPCHandler('api') app = Flask(__name__) handler.connect(app, '/api') handler.register(hello) data = dump_method_call('hello', 'Steve') client = app.test_client() rv = client.post('/api', data=data, content_type='text/xml') res = load_method_response(rv.data) assert res == 'Hello, Steve!'
def test_register(self): handler = XMLRPCHandler('api') handler.register(hello) assert handler.funcs['hello'] is hello handler.register(hello, 'hi') assert handler.funcs['hi'] is hello
def test_instance(self): handler = XMLRPCHandler('api') obj = object() handler.register_instance(obj) assert handler.instance is obj
error = 'Invalid password' else: session['logged_in'] = True flash('You were logged in') return redirect(url_for('show_entries')) return render_template('login.html', error=error) @app.route('/logout') def logout(): session.pop('logged_in', None) flash('You were logged out') return redirect(url_for('show_entries')) api = XMLRPCHandler('api') api.connect(app, '/api') flaskr = api.namespace('flaskr') @flaskr.register def new_post(username, password, title, text): if username != USERNAME or password != PASSWORD: raise Fault('bad_credentials', "The username and password are " "incorrect.") g.db.execute('insert into entries (title, text) values (?, ?)', [title, text]) g.db.commit() return True