Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/functional/cloudwatch/test_put_metric_data.py
1567 views
1
#!/usr/bin/env python
2
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License"). You
5
# may not use this file except in compliance with the License. A copy of
6
# the License is located at
7
#
8
# http://aws.amazon.com/apache2.0/
9
#
10
# or in the "license" file accompanying this file. This file is
11
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12
# ANY KIND, either express or implied. See the License for the specific
13
# language governing permissions and limitations under the License.
14
import decimal
15
16
from awscli.testutils import BaseAWSCommandParamsTest
17
18
19
class TestPutMetricData(BaseAWSCommandParamsTest):
20
maxDiff = None
21
22
prefix = 'cloudwatch put-metric-data '
23
24
expected_output = {
25
'MetricData': [
26
{'MetricName': 'FreeMemoryBytes',
27
'Unit': 'Bytes',
28
'Timestamp': '2013-08-22T10:58:12.283Z',
29
'Value': decimal.Decimal("9130160128")}],
30
'Namespace': '"Foo/Bar"'}
31
32
def test_using_json(self):
33
args = ('--namespace "Foo/Bar" '
34
'--metric-data [{"MetricName":"FreeMemoryBytes",'
35
'"Unit":"Bytes",'
36
'"Timestamp":"2013-08-22T10:58:12.283Z",'
37
'"Value":9130160128}]')
38
cmdline = self.prefix + args
39
self.assert_params_for_cmd(cmdline, self.expected_output)
40
41
def test_using_promoted_params(self):
42
# This is equivalent to the json version in test_using_json
43
# above.
44
args = ('--namespace "Foo/Bar" '
45
'--metric-name FreeMemoryBytes '
46
'--unit Bytes '
47
'--timestamp 2013-08-22T10:58:12.283Z '
48
'--value 9130160128')
49
cmdline = self.prefix + args
50
self.assert_params_for_cmd(cmdline, self.expected_output)
51
52
def test_using_shorthand_syntax(self):
53
args = (
54
'--metric-name PageViewCount '
55
'--namespace MyService '
56
'--statistic-value Sum=11,Minimum=2,Maximum=5,SampleCount=3 '
57
'--timestamp 2014-02-14T12:00:00.000Z'
58
)
59
cmdline = self.prefix + args
60
expected = {
61
'MetricData': [
62
{'MetricName': 'PageViewCount',
63
'StatisticValues': {
64
'Maximum': decimal.Decimal('5'),
65
'Minimum': decimal.Decimal('2'),
66
'SampleCount': decimal.Decimal('3'),
67
'Sum': decimal.Decimal('11')},
68
'Timestamp': '2014-02-14T12:00:00.000Z'}
69
],
70
'Namespace': 'MyService'
71
}
72
self.assert_params_for_cmd(cmdline, expected)
73
74
def test_using_storage_resolution(self):
75
args = (
76
'--metric-name Foo '
77
'--namespace Bar '
78
'--value 5 '
79
'--storage-resolution 1 '
80
)
81
cmdline = self.prefix + args
82
expected = {
83
'MetricData': [{
84
'MetricName': 'Foo',
85
'Value': decimal.Decimal('5'),
86
'StorageResolution': 1
87
}],
88
'Namespace': 'Bar'
89
}
90
self.assert_params_for_cmd(cmdline, expected)
91
92