def test_add_decorator(endpoint, config): def f(): pass config.app.view_functions[endpoint.name] = f add_decorator(endpoint) assert config.app.view_functions[endpoint.name].original == f
def set_endpoint_rule(session, endpoint_name, monitor_level): """ :param session: session for the database :param endpoint_name: name of the endpoint :param monitor_level: integer, representing the monitoring-level """ update_endpoint(session, endpoint_name, value=monitor_level) # Remove wrapper original = getattr(config.app.view_functions[endpoint_name], 'original', None) if original: config.app.view_functions[endpoint_name] = original session.commit() add_decorator(get_endpoint_by_name(session, endpoint_name))
def test_add_decorator(self): from flask_monitoringdashboard.core.measurement import add_decorator with self.app.app_context(): for i in range(4): self.assertEqual( add_decorator(Endpoint(name=NAME, monitor_level=i)), None) self.assertRaises(ValueError, add_decorator, Endpoint(name=NAME, monitor_level=-1))
def rules(): """ Renders a table with all rules from the user_app. The fmd_dashboard rules are excluded In case of the POST request, the data from the form is validated and processed, such that the required rules are monitored :return: """ if request.method == 'POST': with session_scope() as db_session: endpoint_name = request.form['name'] value = int(request.form['value']) update_endpoint(db_session, endpoint_name, value=value) # Remove wrapper original = getattr(user_app.view_functions[endpoint_name], 'original', None) if original: user_app.view_functions[endpoint_name] = original with session_scope() as db_session: add_decorator(get_endpoint_by_name(db_session, endpoint_name)) return 'OK' with session_scope() as db_session: last_accessed = get_last_requested(db_session) all_rules = [] for rule in get_rules(): db_rule = get_endpoint_by_name(db_session, rule.endpoint) all_rules.append({ 'color': get_color(rule.endpoint), 'rule': rule.rule, 'endpoint': rule.endpoint, 'methods': rule.methods, 'last_accessed': get_value(last_accessed, rule.endpoint, default=None), 'form': get_monitor_form(rule.endpoint, db_rule.monitor_level) }) return render_template('fmd_rules.html', rules=all_rules, information=get_rules_info())
def test_add_decorator_fails(endpoint, config): config.app.view_functions[endpoint.name] = lambda: 42 with pytest.raises(ValueError): endpoint.monitor_level = -1 add_decorator(endpoint)