parent
d8f6f77a0f
commit
81f3cbb548
4 changed files with 62 additions and 9 deletions
|
|
@ -1,5 +1,8 @@
|
|||
import boto
|
||||
from boto.ec2.cloudwatch.alarm import MetricAlarm
|
||||
import boto3
|
||||
from datetime import datetime, timedelta
|
||||
import pytz
|
||||
import sure # noqa
|
||||
|
||||
from moto import mock_cloudwatch_deprecated
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ from __future__ import unicode_literals
|
|||
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
from datetime import datetime, timedelta
|
||||
import pytz
|
||||
import sure # noqa
|
||||
|
||||
from moto import mock_cloudwatch
|
||||
|
|
@ -137,6 +139,52 @@ def test_alarm_state():
|
|||
len(resp['MetricAlarms']).should.equal(2)
|
||||
|
||||
|
||||
@mock_cloudwatch
|
||||
def test_put_metric_data_no_dimensions():
|
||||
conn = boto3.client('cloudwatch', region_name='us-east-1')
|
||||
|
||||
conn.put_metric_data(
|
||||
Namespace='tester',
|
||||
MetricData=[
|
||||
dict(
|
||||
MetricName='metric',
|
||||
Value=1.5,
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
metrics = conn.list_metrics()['Metrics']
|
||||
metrics.should.have.length_of(1)
|
||||
metric = metrics[0]
|
||||
metric['Namespace'].should.equal('tester')
|
||||
metric['MetricName'].should.equal('metric')
|
||||
|
||||
|
||||
@mock_cloudwatch
|
||||
def test_get_metric_statistics():
|
||||
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,
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
stats = conn.get_metric_statistics(
|
||||
Namespace='tester',
|
||||
MetricName='metric',
|
||||
StartTime=utc_now,
|
||||
EndTime=utc_now + timedelta(seconds=60),
|
||||
Period=60,
|
||||
Statistics=['SampleCount', 'Sum']
|
||||
)
|
||||
|
||||
stats['Datapoints'].should.have.length_of(1)
|
||||
datapoint = stats['Datapoints'][0]
|
||||
datapoint['SampleCount'].should.equal(1.0)
|
||||
datapoint['Sum'].should.equal(1.5)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue