Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/unit/customizations/datapipeline/test_arg_serialize.py
1569 views
1
#!/usr/bin/env python
2
# Copyright 2014 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
from awscli.testutils import BaseAWSCommandParamsTest, unittest
15
from awscli.testutils import temporary_file
16
17
from awscli.customizations.datapipeline import QueryArgBuilder
18
from dateutil.parser import parse
19
20
21
# We're not interested in testing the def->api
22
# translation process (that has its own test suite),
23
# but we need something basic enough that shows us
24
# that we're serializing arguments properly.
25
TEST_JSON = """\
26
{"objects": [
27
{
28
"id" : "S3ToS3Copy",
29
"type" : "CopyActivity",
30
"schedule" : { "ref" : "CopyPeriod" },
31
"input" : { "ref" : "InputData" },
32
"output" : { "ref" : "OutputData" }
33
}
34
]}"""
35
36
37
class TestPutPipelineDefinition(BaseAWSCommandParamsTest):
38
39
prefix = 'datapipeline put-pipeline-definition'
40
41
def test_put_pipeline_definition_with_json(self):
42
with temporary_file('r+') as f:
43
f.write(TEST_JSON)
44
f.flush()
45
cmdline = self.prefix
46
cmdline += ' --pipeline-id name'
47
cmdline += ' --pipeline-definition file://%s' % f.name
48
result = {
49
'pipelineId': 'name',
50
'pipelineObjects': [
51
{"id": "S3ToS3Copy",
52
"name": "S3ToS3Copy",
53
"fields": [
54
{
55
"key": "input",
56
"refValue": "InputData"
57
},
58
{
59
"key": "output",
60
"refValue": "OutputData"
61
},
62
{
63
"key": "schedule",
64
"refValue": "CopyPeriod"
65
},
66
{
67
"key": "type",
68
"stringValue": "CopyActivity"
69
},
70
]}]
71
}
72
self.assert_params_for_cmd(cmdline, result)
73
74
75
class TestErrorMessages(BaseAWSCommandParamsTest):
76
prefix = 'datapipeline list-runs'
77
78
def test_unknown_status(self):
79
self.assert_params_for_cmd(
80
self.prefix + ' --pipeline-id foo --status foo',
81
expected_rc=255,
82
stderr_contains=('Invalid status: foo, must be one of: waiting, '
83
'pending, cancelled, running, finished, '
84
'failed, waiting_for_runner, '
85
'waiting_on_dependencies'))
86
87
88
class FakeParsedArgs(object):
89
def __init__(self, start_interval=None, schedule_interval=None,
90
status=None):
91
self.start_interval = start_interval
92
self.schedule_interval = schedule_interval
93
self.status = status
94
95
96
class TestCLIArgumentSerialize(unittest.TestCase):
97
maxDiff = None
98
99
# These tests verify that we go from --cli-args
100
# to the proper structure needed for the "Query"
101
# argument to describe objects.
102
def test_build_query_args_default(self):
103
parsed_args = FakeParsedArgs()
104
current_time = '2014-02-21T00:00:00'
105
start_time = '2014-02-17T00:00:00'
106
builder = QueryArgBuilder(current_time=parse(current_time))
107
query = builder.build_query(parsed_args)
108
self.assertEqual(query, {
109
'selectors': [{
110
'fieldName': '@actualStartTime',
111
'operator': {
112
'type': 'BETWEEN',
113
'values': [start_time, current_time]
114
}
115
}]
116
})
117
118
def test_build_args_with_start_interval(self):
119
parsed_args = FakeParsedArgs(
120
start_interval=['2014-02-01T00:00:00',
121
'2014-02-04T00:00:00',]
122
)
123
builder = QueryArgBuilder()
124
query = builder.build_query(parsed_args)
125
self.assertEqual(query, {
126
'selectors': [{
127
'fieldName': '@actualStartTime',
128
'operator': {
129
'type': 'BETWEEN',
130
'values': ['2014-02-01T00:00:00',
131
'2014-02-04T00:00:00']
132
}
133
}]
134
})
135
136
def test_build_args_with_end_interval(self):
137
parsed_args = FakeParsedArgs(
138
schedule_interval=['2014-02-01T00:00:00',
139
'2014-02-04T00:00:00',]
140
)
141
builder = QueryArgBuilder()
142
query = builder.build_query(parsed_args)
143
self.assertEqual(query, {
144
'selectors': [{
145
'fieldName': '@scheduledStartTime',
146
'operator': {
147
'type': 'BETWEEN',
148
'values': ['2014-02-01T00:00:00',
149
'2014-02-04T00:00:00']
150
}
151
}]
152
})
153
154
def test_build_args_with_single_status(self):
155
# --status pending
156
parsed_args = FakeParsedArgs(
157
status=['pending']
158
)
159
current_time = '2014-02-21T00:00:00'
160
start_time = '2014-02-17T00:00:00'
161
builder = QueryArgBuilder(current_time=parse(current_time))
162
query = builder.build_query(parsed_args)
163
self.assertEqual(query, {
164
'selectors': [{
165
'fieldName': '@actualStartTime',
166
'operator': {
167
'type': 'BETWEEN',
168
'values': [start_time, current_time]
169
}
170
}, {
171
'fieldName': '@status',
172
'operator': {
173
'type': 'EQ',
174
'values': ['PENDING']
175
}
176
},
177
]
178
})
179
180
def test_build_args_with_csv_status(self):
181
# --status pending,waiting_on_dependencies
182
parsed_args = FakeParsedArgs(
183
status=['pending', 'waiting_on_dependencies']
184
)
185
current_time = '2014-02-21T00:00:00'
186
start_time = '2014-02-17T00:00:00'
187
builder = QueryArgBuilder(current_time=parse(current_time))
188
query = builder.build_query(parsed_args)
189
self.assertEqual(query, {
190
'selectors': [{
191
'fieldName': '@actualStartTime',
192
'operator': {
193
'type': 'BETWEEN',
194
'values': [start_time, current_time]
195
}
196
}, {
197
'fieldName': '@status',
198
'operator': {
199
'type': 'EQ',
200
'values': ['PENDING', 'WAITING_ON_DEPENDENCIES']
201
}
202
},
203
]
204
})
205
206
def test_build_args_with_all_values_set(self):
207
# --status pending,waiting_on_dependencies
208
# --start-interval pending,waiting_on_dependencies
209
# --schedule-schedule pending,waiting_on_dependencies
210
parsed_args = FakeParsedArgs(
211
start_interval=['2014-02-01T00:00:00',
212
'2014-02-04T00:00:00',],
213
schedule_interval=['2014-02-05T00:00:00',
214
'2014-02-09T00:00:00',],
215
status=['pending', 'waiting_on_dependencies'],
216
)
217
builder = QueryArgBuilder()
218
query = builder.build_query(parsed_args)
219
self.assertEqual(query, {
220
'selectors': [{
221
'fieldName': '@actualStartTime',
222
'operator': {
223
'type': 'BETWEEN',
224
'values': ['2014-02-01T00:00:00',
225
'2014-02-04T00:00:00',],
226
}
227
}, {
228
'fieldName': '@scheduledStartTime',
229
'operator': {
230
'type': 'BETWEEN',
231
'values': ['2014-02-05T00:00:00',
232
'2014-02-09T00:00:00']
233
}
234
}, {
235
'fieldName': '@status',
236
'operator': {
237
'type': 'EQ',
238
'values': ['PENDING', 'WAITING_ON_DEPENDENCIES']
239
}
240
},]
241
})
242
243