コード例 #1
0
def get_endpoint_overview(session):
    """
    :param session: session for the database
    :return: A list of properties for each endpoint that is found in the database
    """
    week_ago = datetime.datetime.utcnow() - datetime.timedelta(days=7)
    now_local = to_local_datetime(datetime.datetime.utcnow())
    today_local = now_local.replace(hour=0, minute=0, second=0, microsecond=0)
    today_utc = to_utc_datetime(today_local)

    # First flush last requested info to db
    cache.flush_cache()
    error_hits_criterion = and_(Request.status_code >= 400,
                                Request.status_code < 600)

    hits_today = count_requests_group(session,
                                      Request.time_requested > today_utc)
    hits_today_errors = count_requests_group(
        session, and_(Request.time_requested > today_utc,
                      error_hits_criterion))

    hits_week = count_requests_group(session,
                                     Request.time_requested > week_ago)
    hits_week_errors = count_requests_group(
        session, and_(Request.time_requested > week_ago, error_hits_criterion))

    hits = count_requests_group(session)

    median_today = get_endpoint_data_grouped(
        session, median, Request.time_requested > today_utc)
    median_week = get_endpoint_data_grouped(session, median,
                                            Request.time_requested > week_ago)
    median_overall = get_endpoint_data_grouped(session, median)
    access_times = get_last_requested(session)

    return [{
        'id':
        endpoint.id,
        'name':
        endpoint.name,
        'blueprint':
        get_blueprint(endpoint.name),
        'monitor':
        endpoint.monitor_level,
        'color':
        get_color(endpoint.name),
        'hits-today':
        get_value(hits_today, endpoint.id),
        'hits-today-errors':
        get_value(hits_today_errors, endpoint.id),
        'hits-week':
        get_value(hits_week, endpoint.id),
        'hits-week-errors':
        get_value(hits_week_errors, endpoint.id),
        'hits-overall':
        get_value(hits, endpoint.id),
        'median-today':
        get_value(median_today, endpoint.id),
        'median-week':
        get_value(median_week, endpoint.id),
        'median-overall':
        get_value(median_overall, endpoint.id),
        'last-accessed':
        get_value(access_times, endpoint.name, default=None),
    } for endpoint in get_endpoints(session)]
コード例 #2
0
def test_get_blueprint(name):
    actual = get_blueprint(name)
    assert actual == 'Fiddler'
コード例 #3
0
def test_get_blueprint_triple_gives_first(name):
    actual = get_blueprint(name)
    assert actual == 'Karsa'
コード例 #4
0
def test_get_blueprint_blank_gives_blank(name):
    actual = get_blueprint(name)
    assert actual == ''
コード例 #5
0
def test_get_blueprint_double_gives_first(name):
    actual = get_blueprint(name)
    assert actual == 'Anomander'