Fix exception type in cloudwatch get_metric_statistics (#4775)
This commit is contained in:
parent
245443d910
commit
4c309e7dd7
@ -15,6 +15,13 @@ class InvalidParameterValue(RESTError):
|
|||||||
super().__init__(__class__.__name__, message)
|
super().__init__(__class__.__name__, message)
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidParameterCombination(RESTError):
|
||||||
|
code = 400
|
||||||
|
|
||||||
|
def __init__(self, message):
|
||||||
|
super().__init__(__class__.__name__, message)
|
||||||
|
|
||||||
|
|
||||||
class ResourceNotFound(RESTError):
|
class ResourceNotFound(RESTError):
|
||||||
code = 404
|
code = 404
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ from dateutil.parser import parse as dtparse
|
|||||||
from moto.core.responses import BaseResponse
|
from moto.core.responses import BaseResponse
|
||||||
from moto.core.utils import amzn_request_id
|
from moto.core.utils import amzn_request_id
|
||||||
from .models import cloudwatch_backends, MetricDataQuery, MetricStat, Metric, Dimension
|
from .models import cloudwatch_backends, MetricDataQuery, MetricStat, Metric, Dimension
|
||||||
|
from .exceptions import InvalidParameterCombination
|
||||||
|
|
||||||
|
|
||||||
class CloudWatchResponse(BaseResponse):
|
class CloudWatchResponse(BaseResponse):
|
||||||
@ -187,9 +188,8 @@ class CloudWatchResponse(BaseResponse):
|
|||||||
unit = self._get_param("Unit")
|
unit = self._get_param("Unit")
|
||||||
extended_statistics = self._get_param("ExtendedStatistics")
|
extended_statistics = self._get_param("ExtendedStatistics")
|
||||||
|
|
||||||
# TODO: this should instead throw InvalidParameterCombination
|
|
||||||
if not statistics and not extended_statistics:
|
if not statistics and not extended_statistics:
|
||||||
raise NotImplementedError(
|
raise InvalidParameterCombination(
|
||||||
"Must specify either Statistics or ExtendedStatistics"
|
"Must specify either Statistics or ExtendedStatistics"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -105,6 +105,31 @@ def test_get_metric_statistics():
|
|||||||
datapoint["Sum"].should.equal(1.5)
|
datapoint["Sum"].should.equal(1.5)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_cloudwatch
|
||||||
|
def test_get_metric_invalid_parameter_combination():
|
||||||
|
conn = boto3.client("cloudwatch", region_name="us-east-1")
|
||||||
|
utc_now = datetime.now(tz=pytz.utc)
|
||||||
|
|
||||||
|
conn.put_metric_data(
|
||||||
|
Namespace="tester",
|
||||||
|
MetricData=[dict(MetricName="metric", Value=1.5, Timestamp=utc_now)],
|
||||||
|
)
|
||||||
|
|
||||||
|
with pytest.raises(ClientError) as exc:
|
||||||
|
# make request without both statistics or extended statistics parameters
|
||||||
|
conn.get_metric_statistics(
|
||||||
|
Namespace="tester",
|
||||||
|
MetricName="metric",
|
||||||
|
StartTime=utc_now - timedelta(seconds=60),
|
||||||
|
EndTime=utc_now + timedelta(seconds=60),
|
||||||
|
Period=60,
|
||||||
|
)
|
||||||
|
|
||||||
|
err = exc.value.response["Error"]
|
||||||
|
err["Code"].should.equal("InvalidParameterCombination")
|
||||||
|
err["Message"].should.equal("Must specify either Statistics or ExtendedStatistics")
|
||||||
|
|
||||||
|
|
||||||
@mock_cloudwatch
|
@mock_cloudwatch
|
||||||
def test_get_metric_statistics_dimensions():
|
def test_get_metric_statistics_dimensions():
|
||||||
conn = boto3.client("cloudwatch", region_name="us-east-1")
|
conn = boto3.client("cloudwatch", region_name="us-east-1")
|
||||||
|
Loading…
Reference in New Issue
Block a user