Path: blob/develop/tests/functional/cloudwatch/test_put_metric_data.py
1567 views
#!/usr/bin/env python1# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License"). You4# may not use this file except in compliance with the License. A copy of5# the License is located at6#7# http://aws.amazon.com/apache2.0/8#9# or in the "license" file accompanying this file. This file is10# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF11# ANY KIND, either express or implied. See the License for the specific12# language governing permissions and limitations under the License.13import decimal1415from awscli.testutils import BaseAWSCommandParamsTest161718class TestPutMetricData(BaseAWSCommandParamsTest):19maxDiff = None2021prefix = 'cloudwatch put-metric-data '2223expected_output = {24'MetricData': [25{'MetricName': 'FreeMemoryBytes',26'Unit': 'Bytes',27'Timestamp': '2013-08-22T10:58:12.283Z',28'Value': decimal.Decimal("9130160128")}],29'Namespace': '"Foo/Bar"'}3031def test_using_json(self):32args = ('--namespace "Foo/Bar" '33'--metric-data [{"MetricName":"FreeMemoryBytes",'34'"Unit":"Bytes",'35'"Timestamp":"2013-08-22T10:58:12.283Z",'36'"Value":9130160128}]')37cmdline = self.prefix + args38self.assert_params_for_cmd(cmdline, self.expected_output)3940def test_using_promoted_params(self):41# This is equivalent to the json version in test_using_json42# above.43args = ('--namespace "Foo/Bar" '44'--metric-name FreeMemoryBytes '45'--unit Bytes '46'--timestamp 2013-08-22T10:58:12.283Z '47'--value 9130160128')48cmdline = self.prefix + args49self.assert_params_for_cmd(cmdline, self.expected_output)5051def test_using_shorthand_syntax(self):52args = (53'--metric-name PageViewCount '54'--namespace MyService '55'--statistic-value Sum=11,Minimum=2,Maximum=5,SampleCount=3 '56'--timestamp 2014-02-14T12:00:00.000Z'57)58cmdline = self.prefix + args59expected = {60'MetricData': [61{'MetricName': 'PageViewCount',62'StatisticValues': {63'Maximum': decimal.Decimal('5'),64'Minimum': decimal.Decimal('2'),65'SampleCount': decimal.Decimal('3'),66'Sum': decimal.Decimal('11')},67'Timestamp': '2014-02-14T12:00:00.000Z'}68],69'Namespace': 'MyService'70}71self.assert_params_for_cmd(cmdline, expected)7273def test_using_storage_resolution(self):74args = (75'--metric-name Foo '76'--namespace Bar '77'--value 5 '78'--storage-resolution 1 '79)80cmdline = self.prefix + args81expected = {82'MetricData': [{83'MetricName': 'Foo',84'Value': decimal.Decimal('5'),85'StorageResolution': 186}],87'Namespace': 'Bar'88}89self.assert_params_for_cmd(cmdline, expected)909192