Esempio n. 1
0
def test_prettyprint_statistics_timeseries(capsys):
    setup_httpretty()

    sample_ts_response = {
        'statistics': {
            'from': 123123,
            'to': 123123,
            'count': 1234,
            'stats': {
                'global_timeseries': {
                    'count': 27733.0
                }
            },
            'granularity': 120000,
            'timeseries': {
                'global_timeseries': [{
                    'count': 2931.0
                }, {
                    'count': 2869.0
                }, {
                    'count': 2852.0
                }, {
                    'count': 2946.0
                }, {
                    'count': 2733.0
                }, {
                    'count': 2564.0
                }, {
                    'count': 2801.0
                }, {
                    'count': 2773.0
                }, {
                    'count': 2698.0
                }, {
                    'count': 2566.0
                }]
            }
        }
    }

    httpretty.register_uri(httpretty.GET,
                           MOCK_API_URL,
                           content_type='application/json',
                           body=json.dumps(sample_ts_response))
    response = requests.get(MOCK_API_URL)
    api.prettyprint_statistics(response)

    out, err = capsys.readouterr()
    assert "Total" in out
    assert "Timeseries" in out

    teardown_httpretty()
Esempio n. 2
0
def test_prettyprint_statistics_timeseries_with_empty_result(capsys):
    setup_httpretty()

    sample_empty_ts_response = {
        'statistics': {
            'from': 123123,
            'to': 123123,
            'count': 0.0,
            'stats': {
                'global_timeseries': {}  # empty global timeseries object
            },
            'granularity': 120000,
            'timeseries': {
                'global_timeseries': [{
                    'count': 0.0
                }, {
                    'count': 0.0
                }, {
                    'count': 0.0
                }, {
                    'count': 0.0
                }, {
                    'count': 0.0
                }, {
                    'count': 0.0
                }, {
                    'count': 0.0
                }, {
                    'count': 0.0
                }, {
                    'count': 0.0
                }, {
                    'count': 0.0
                }]
            }
        }
    }

    httpretty.register_uri(httpretty.GET,
                           MOCK_API_URL,
                           content_type='application/json',
                           body=json.dumps(sample_empty_ts_response))
    response = requests.get(MOCK_API_URL)
    api.prettyprint_statistics(response)

    out, err = capsys.readouterr()
    assert "Total" in out
    assert "Timeseries" in out

    teardown_httpretty()
Esempio n. 3
0
def test_prettyprint_statistics_timeseries_with_empty_result(capsys):
    setup_httpretty()

    httpretty.register_uri(httpretty.GET,
                           misc_ex.MOCK_QUERYAPI_URL,
                           content_type='application/json',
                           body=json.dumps(resp_ex.empty_ts_response))
    response = requests.get(misc_ex.MOCK_QUERYAPI_URL)
    api.prettyprint_statistics(response)

    out, err = capsys.readouterr()
    assert "Total" in out
    assert "Timeseries" in out

    teardown_httpretty()
Esempio n. 4
0
def test_prettyprint_statistics_groups(capsys):
    setup_httpretty()

    httpretty.register_uri(httpretty.GET,
                           misc_ex.MOCK_QUERYAPI_URL,
                           content_type='application/json',
                           body=json.dumps(resp_ex.group_response))
    response = requests.get(misc_ex.MOCK_QUERYAPI_URL)
    api.prettyprint_statistics(response)

    out, err = capsys.readouterr()
    for group in response.json()['statistics']['groups']:
        for key, value in group.iteritems():
            assert key in out

    teardown_httpretty()
Esempio n. 5
0
def test_prettyprint_statistics_timeseries(capsys):
    setup_httpretty()

    sample_ts_response = {
        'statistics': {
            'from': 123123,
            'to': 123123,
            'count': 1234,
            'stats': {
                'global_timeseries':
                    {'count': 27733.0}
            },
            'granularity': 120000,
            'timeseries': {
                'global_timeseries': [
                    {'count': 2931.0},
                    {'count': 2869.0},
                    {'count': 2852.0},
                    {'count': 2946.0},
                    {'count': 2733.0},
                    {'count': 2564.0},
                    {'count': 2801.0},
                    {'count': 2773.0},
                    {'count': 2698.0},
                    {'count': 2566.0}
                ]
            }
        }
    }

    httpretty.register_uri(httpretty.GET, MOCK_API_URL,
                           content_type='application/json',
                           body=json.dumps(sample_ts_response))
    response = requests.get(MOCK_API_URL)
    api.prettyprint_statistics(response)

    out, err = capsys.readouterr()
    assert "Total" in out
    assert "Timeseries" in out

    teardown_httpretty()
Esempio n. 6
0
def test_prettyprint_statistics_timeseries_with_empty_result(capsys):
    setup_httpretty()

    sample_empty_ts_response = {
        'statistics': {
            'from': 123123,
            'to': 123123,
            'count': 0.0,
            'stats': {
                'global_timeseries':
                    {}  # empty global timeseries object
            },
            'granularity': 120000,
            'timeseries': {
                'global_timeseries': [
                    {'count': 0.0},
                    {'count': 0.0},
                    {'count': 0.0},
                    {'count': 0.0},
                    {'count': 0.0},
                    {'count': 0.0},
                    {'count': 0.0},
                    {'count': 0.0},
                    {'count': 0.0},
                    {'count': 0.0}
                ]
            }
        }
    }

    httpretty.register_uri(httpretty.GET, MOCK_API_URL, content_type='application/json',
                           body=json.dumps(sample_empty_ts_response))
    response = requests.get(MOCK_API_URL)
    api.prettyprint_statistics(response)

    out, err = capsys.readouterr()
    assert "Total" in out
    assert "Timeseries" in out

    teardown_httpretty()
Esempio n. 7
0
def test_prettyprint_statistics_groups(capsys):
    setup_httpretty()

    sample_group_response = {
        'statistics': {
            'from':
            123123,
            'to':
            1231323,
            'granularity':
            0,
            'count':
            1234,
            'timeseries': {},
            'groups': [{
                '200': {
                    'count': 802.0,
                    'min': 802.0,
                    'max': 802.0,
                    'sum': 802.0,
                    'bytes': 802.0,
                    'percentile': 802.0,
                    'unique': 802.0,
                    'average': 802.0
                }
            }, {
                '400': {
                    'count': 839.0,
                    'min': 839.0,
                    'max': 839.0,
                    'sum': 839.0,
                    'bytes': 839.0,
                    'percentile': 839.0,
                    'unique': 839.0,
                    'average': 839.0
                }
            }, {
                '404': {
                    'count': 839.0,
                    'min': 839.0,
                    'max': 839.0,
                    'sum': 839.0,
                    'bytes': 839.0,
                    'percentile': 839.0,
                    'unique': 839.0,
                    'average': 839.0
                }
            }, {
                'status': {
                    'count': 205.0,
                    'min': 205.0,
                    'max': 205.0,
                    'sum': 205.0,
                    'bytes': 205.0,
                    'percentile': 205.0,
                    'unique': 205.0,
                    'average': 205.0
                }
            }],
            'stats': {}
        }
    }

    httpretty.register_uri(httpretty.GET,
                           MOCK_API_URL,
                           content_type='application/json',
                           body=json.dumps(sample_group_response))
    response = requests.get(MOCK_API_URL)
    api.prettyprint_statistics(response)

    out, err = capsys.readouterr()
    for group in response.json()['statistics']['groups']:
        for key, value in group.items():
            assert key in out

    teardown_httpretty()
Esempio n. 8
0
def test_prettyprint_statistics_groups(capsys):
    setup_httpretty()

    sample_group_response = {
        'statistics': {
            'from': 123123,
            'to': 1231323,
            'granularity': 0,
            'count': 1234,
            'timeseries': {},
            'groups': [{
                '200': {
                    'count': 802.0,
                    'min': 802.0,
                    'max': 802.0,
                    'sum': 802.0,
                    'bytes': 802.0,
                    'percentile': 802.0,
                    'unique': 802.0,
                    'average': 802.0
                }
            }, {
                '400': {
                    'count': 839.0,
                    'min': 839.0,
                    'max': 839.0,
                    'sum': 839.0,
                    'bytes': 839.0,
                    'percentile': 839.0,
                    'unique': 839.0,
                    'average': 839.0
                }
            }, {
                '404': {
                    'count': 839.0,
                    'min': 839.0,
                    'max': 839.0,
                    'sum': 839.0,
                    'bytes': 839.0,
                    'percentile': 839.0,
                    'unique': 839.0,
                    'average': 839.0
                }
            }, {
                'status': {
                    'count': 205.0,
                    'min': 205.0,
                    'max': 205.0,
                    'sum': 205.0,
                    'bytes': 205.0,
                    'percentile': 205.0,
                    'unique': 205.0,
                    'average': 205.0
                }
            }],
            'stats': {}
        }
    }

    httpretty.register_uri(httpretty.GET, MOCK_API_URL, content_type='application/json',
                           body=json.dumps(sample_group_response))
    response = requests.get(MOCK_API_URL)
    api.prettyprint_statistics(response)

    out, err = capsys.readouterr()
    for group in response.json()['statistics']['groups']:
        for key, value in group.iteritems():
            assert key in out

    teardown_httpretty()