def test_bar_chart_push(): httpretty.register_uri(httpretty.POST, req_ex.DEST_URL, body="OK") gecko_job_bar_chart = GeckoboardService(LeRestResponse(resp_ex.FULL_GROUP_RESP), req_ex.SERVICE_API_KEY, conf_ex.GECKO_BAR_CHART_CONFIG) gecko_job_bar_chart.push({}) assert httpretty.has_request()
def test__number_stat_push(): httpretty.register_uri(httpretty.POST, req_ex.DEST_URL, body="OK") gecko_job_number_stat = GeckoboardService(LeRestResponse(resp_ex.FULL_GROUP_RESP), req_ex.SERVICE_API_KEY, conf_ex.GECKO_NUMBER_STAT_CONFIG) gecko_job_number_stat.push({}) assert httpretty.has_request()
def test_format_pie_chart_data(): gecko_job_pie_chart = GeckoboardService(LeRestResponse(resp_ex.FULL_GROUP_RESP), req_ex.SERVICE_API_KEY, conf_ex.GECKO_PIE_CHART_CONFIG) pie_data = gecko_job_pie_chart.format_pie_chart_data() assert "data" in pie_data item_data = pie_data["data"] assert "item" in item_data assert len(resp_ex.GROUP_STATISTICS.get('groups')) == len(pie_data['data']['item'])
def test_format_bar_chart_data(): gecko_job_bar_chart = GeckoboardService(LeRestResponse(resp_ex.FULL_GROUP_RESP), req_ex.SERVICE_API_KEY, conf_ex.GECKO_BAR_CHART_CONFIG) bar_chart_json = gecko_job_bar_chart.format_bar_chart_data() assert "data" in bar_chart_json bar_chart_data = bar_chart_json.get("data") assert "x_axis" in bar_chart_data assert "y_axis" in bar_chart_data assert "series" in bar_chart_data
def test_push(): hosted_graphite_job = HostedGraphiteService( LeRestResponse(resp_ex.FULL_TIMESERIES_RESP), req_ex.SERVICE_API_KEY, conf_ex.SEARCH_HOSTED_GRAPHITE) httpretty.register_uri(httpretty.PUT, req_ex.DEST_URL, body="OK") hosted_graphite_job.push("payload") assert httpretty.has_request()
def test_process(): with patch.object(HostedGraphiteService, 'push', return_value=None) as mock_push: hosted_graphite_job = HostedGraphiteService( LeRestResponse(resp_ex.FULL_TIMESERIES_RESP), req_ex.SERVICE_API_KEY, conf_ex.SEARCH_HOSTED_GRAPHITE) hosted_graphite_job.process() assert mock_push.called
def test_convert_to_hostedgraphite_data(): full_ts_resp_object = LeRestResponse({ "logs": resp_ex.LOGS, "statistics": resp_ex.TIMESERIES_STATISTICS, "leql": resp_ex.LEQL }) hosted_graphite_job = HostedGraphiteService(full_ts_resp_object, req_ex.SERVICE_API_KEY, conf_ex.SEARCH_HOSTED_GRAPHITE) hg_data = hosted_graphite_job.transform() pattern = re.compile("(\w+\s\d+\.\d+\s\d+\\n)+") assert pattern.match(hg_data)
def test_format_number_stat_data(): gecko_job_number_stat = GeckoboardService(LeRestResponse(resp_ex.FULL_GROUP_RESP), req_ex.SERVICE_API_KEY, conf_ex.GECKO_NUMBER_STAT_CONFIG) number_stat = gecko_job_number_stat.format_number_stat_data() assert "data" in number_stat number_stat_data = number_stat.get("data") assert "item" in number_stat_data item = number_stat_data["item"] assert item[0] the_item = item[0] assert "value" in the_item assert the_item["value"] == 1234 assert "text" in the_item assert the_item["text"] == "number_stat_text"
def test_has_groups(): group_obj = LeRestResponse(resp_ex.FULL_GROUP_RESP) ts_obj = LeRestResponse(resp_ex.FULL_TIMESERIES_RESP) assert group_obj.has_groups() is True assert ts_obj.has_groups() is False
def test_get_logs(): group_obj = LeRestResponse(resp_ex.FULL_GROUP_RESP) ts_obj = LeRestResponse(resp_ex.FULL_TIMESERIES_RESP) assert len(group_obj.get_logs()) == EXPECTED_LOG_KEY_COUNT assert len(ts_obj.get_logs()) == EXPECTED_LOG_KEY_COUNT
def test_get_leql(): group_obj = LeRestResponse(resp_ex.FULL_GROUP_RESP) ts_obj = LeRestResponse(resp_ex.FULL_TIMESERIES_RESP) assert group_obj.get_leql() == resp_ex.LEQL assert ts_obj.get_leql() == resp_ex.LEQL
def test_get_data_length(): group_obj = LeRestResponse(resp_ex.FULL_GROUP_RESP) ts_obj = LeRestResponse(resp_ex.FULL_TIMESERIES_RESP) assert group_obj.get_data_length() == EXPECTED_GROUP_COUNT assert ts_obj.get_data_length() == EXPECTED_TS_COUNT
def test_get_count(): group_obj = LeRestResponse(resp_ex.FULL_GROUP_RESP) ts_obj = LeRestResponse(resp_ex.FULL_TIMESERIES_RESP) assert group_obj.get_statistics_count() == EXPECTED_COUNT assert ts_obj.get_statistics_count() == EXPECTED_COUNT
def test_get_granularity(): group_obj = LeRestResponse(resp_ex.FULL_GROUP_RESP) ts_obj = LeRestResponse(resp_ex.FULL_TIMESERIES_RESP) assert group_obj.get_granularity() == EXPECTED_GRANULARITY assert ts_obj.get_granularity() == EXPECTED_GRANULARITY
def test_number_stat_process_calls_push(): with patch.object(GeckoboardService, 'push') as mocked_number_stat_push: gecko_job_number_stat = GeckoboardService(LeRestResponse(resp_ex.FULL_GROUP_RESP), req_ex.SERVICE_API_KEY, conf_ex.GECKO_NUMBER_STAT_CONFIG) gecko_job_number_stat.process() assert mocked_number_stat_push.called
def test_format_line_chart_data(): gecko_job_line_chart = GeckoboardService(LeRestResponse(resp_ex.FULL_TIMESERIES_RESP), req_ex.SERVICE_API_KEY, conf_ex.GECKO_LINE_CHART_CONFIG) line_chart_data = gecko_job_line_chart.format_line_chart_data() assert "data" in line_chart_data assert line_chart_data["data"]["series"][0]["name"] == conf_ex.GECKO_LINE_CHART_CONFIG["name"]
def test_number_stat_transform(): with patch.object(GeckoboardService, 'transform', return_value=None) as mock_transform: gecko_job_number_stat = GeckoboardService(LeRestResponse(resp_ex.FULL_GROUP_RESP), req_ex.SERVICE_API_KEY, conf_ex.GECKO_NUMBER_STAT_CONFIG) gecko_job_number_stat.transform() assert mock_transform.called
def test_bar_chart_process_calls_push(): with patch.object(GeckoboardService, 'push') as mocked_bar_chart_push: gecko_job_bar_chart = GeckoboardService(LeRestResponse(resp_ex.FULL_GROUP_RESP), req_ex.SERVICE_API_KEY, conf_ex.GECKO_BAR_CHART_CONFIG) gecko_job_bar_chart.process() assert mocked_bar_chart_push.called
def test_bar_chart_transform(): with patch.object(GeckoboardService, 'transform', return_value=None) as mock_transform: gecko_job_bar_chart = GeckoboardService(LeRestResponse(resp_ex.FULL_GROUP_RESP), req_ex.SERVICE_API_KEY, conf_ex.GECKO_BAR_CHART_CONFIG) gecko_job_bar_chart.transform() assert mock_transform.called