예제 #1
0
 def test_add_request(self):
     """
         Test whether the function returns the right values.
     """
     from flask_monitoringdashboard.database.request import add_request
     name2 = 'main2'
     execution_time = 1234
     self.assertNotEqual(
         NAME, name2, 'Both cannot be equal, otherwise the test will fail')
     with session_scope() as db_session:
         endpoint = get_endpoint_by_name(db_session, name2)
         self.assertEqual(count_requests(db_session, endpoint.id), 0)
         add_request(db_session, execution_time, endpoint.id, ip=IP)
         self.assertEqual(count_requests(db_session, endpoint.id), 1)
예제 #2
0
def test_add_request(endpoint, session):
    num_requests = len(endpoint.requests)
    add_request(
        session,
        duration=200,
        endpoint_id=endpoint.id,
        ip='127.0.0.1',
        group_by=None,
        status_code=200,
    )
    assert count_requests(session, endpoint.id) == num_requests + 1
예제 #3
0
def get_endpoint_details(db_session, endpoint_id):
    """
    Returns details about an endpoint.
    :param db_session: session for the database
    :param endpoint_id: id of the endpoint
    :return dictionary
    """
    endpoint = get_endpoint_by_id(db_session, endpoint_id)
    endpoint.time_added = to_local_datetime(endpoint.time_added)
    return {
        'id': endpoint_id,
        'endpoint': endpoint.name,
        'rules': ', '.join([r.rule for r in get_rules(endpoint.name)]),
        'rule': endpoint,
        'url': get_url(endpoint.name),
        'total_hits': count_requests(db_session, endpoint.id)
    }
예제 #4
0
def get_endpoint_details(db_session, endpoint_id):
    """
    Returns details about an endpoint.
    :param db_session: session for the database
    :param endpoint_id: id of the endpoint
    :return dictionary
    """
    endpoint = get_endpoint_by_id(db_session, endpoint_id)
    endpoint.time_added = to_local_datetime(endpoint.time_added)
    flask_rule = get_rules(endpoint.name)
    methods = [list(rule.methods) for rule in flask_rule]
    methods = sum(methods, [])  # flatten list
    return {
        'id': endpoint_id,
        'color': get_color(endpoint.name),
        'methods': list(dict.fromkeys(methods)),
        'endpoint': endpoint.name,
        'rules': [r.rule for r in get_rules(endpoint.name)],
        'monitor-level': endpoint.monitor_level,
        'url': get_url(endpoint.name),
        'total_hits': count_requests(db_session, endpoint.id)
    }
 def test_count_requests(self):
     with session_scope() as db_session:
         self.assertEqual(count_requests(db_session, ENDPOINT_ID),
                          len(REQUESTS))
         self.assertEqual(count_requests(db_session, ENDPOINT_ID + 1), 0)
예제 #6
0
def test_count_requests(session, endpoint, non_existing_endpoint_id):
    assert count_requests(session, endpoint.id) == 1
    assert count_requests(session, non_existing_endpoint_id) == 0