def test_http_metrics_provider_no_data(): fake_marathon_service_config = marathon_tools.MarathonServiceConfig( service="fake-service", instance="fake-instance", cluster="fake-cluster", config_dict={}, branch_dict={} ) fake_marathon_tasks = [mock.Mock(id="fake-service.fake-instance", host="fake_host", ports=[30101])] mock_request_result = mock.Mock(json=mock.Mock(return_value="malformed_result")) with mock.patch("paasta_tools.autoscaling_lib.requests.get", autospec=True, return_value=mock_request_result): with raises(autoscaling_lib.MetricsProviderNoDataError): autoscaling_lib.http_metrics_provider(fake_marathon_service_config, fake_marathon_tasks, mock.Mock()) == 0.5
def test_http_metrics_provider_no_data(): fake_marathon_service_config = marathon_tools.MarathonServiceConfig( service='fake-service', instance='fake-instance', cluster='fake-cluster', config_dict={}, branch_dict={}, ) fake_marathon_tasks = [mock.Mock(id='fake-service.fake-instance', host='fake_host', ports=[30101])] mock_request_result = mock.Mock(json=mock.Mock(return_value='malformed_result')) with mock.patch('paasta_tools.autoscaling_lib.requests.get', autospec=True, return_value=mock_request_result): with raises(autoscaling_lib.MetricsProviderNoDataError): autoscaling_lib.http_metrics_provider(fake_marathon_service_config, fake_marathon_tasks, mock.Mock()) == 0.5
def test_http_metrics_provider(): fake_marathon_service_config = marathon_tools.MarathonServiceConfig( service="fake-service", instance="fake-instance", cluster="fake-cluster", config_dict={}, branch_dict={} ) fake_marathon_tasks = [mock.Mock(id="fake-service.fake-instance", host="fake_host", ports=[30101])] mock_request_result = mock.Mock(json=mock.Mock(return_value={"utilization": "0.5"})) with mock.patch("paasta_tools.autoscaling_lib.requests.get", autospec=True, return_value=mock_request_result): assert ( autoscaling_lib.http_metrics_provider(fake_marathon_service_config, fake_marathon_tasks, mock.Mock()) == 0.5 )
def test_http_metrics_provider(): fake_marathon_service_config = marathon_tools.MarathonServiceConfig( service='fake-service', instance='fake-instance', cluster='fake-cluster', config_dict={}, branch_dict={}, ) fake_marathon_tasks = [mock.Mock(id='fake-service.fake-instance', host='fake_host', ports=[30101])] mock_request_result = mock.Mock(json=mock.Mock(return_value={'utilization': '0.5'})) with mock.patch('paasta_tools.autoscaling_lib.requests.get', autospec=True, return_value=mock_request_result): assert autoscaling_lib.http_metrics_provider( fake_marathon_service_config, fake_marathon_tasks, mock.Mock()) == 0.5