2015-09-16 14:00:38 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import boto.datapipeline
|
|
|
|
import sure # noqa
|
|
|
|
|
2017-02-16 03:35:45 +00:00
|
|
|
from moto import mock_datapipeline_deprecated
|
2015-09-16 21:49:13 +00:00
|
|
|
from moto.datapipeline.utils import remove_capitalization_of_dict_keys
|
2015-09-16 14:00:38 +00:00
|
|
|
|
|
|
|
|
2015-09-16 15:22:52 +00:00
|
|
|
def get_value_from_fields(key, fields):
|
|
|
|
for field in fields:
|
|
|
|
if field['key'] == key:
|
|
|
|
return field['stringValue']
|
|
|
|
|
|
|
|
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_datapipeline_deprecated
|
2015-09-16 14:00:38 +00:00
|
|
|
def test_create_pipeline():
|
|
|
|
conn = boto.datapipeline.connect_to_region("us-west-2")
|
|
|
|
|
|
|
|
res = conn.create_pipeline("mypipeline", "some-unique-id")
|
|
|
|
|
|
|
|
pipeline_id = res["pipelineId"]
|
2017-02-24 02:37:43 +00:00
|
|
|
pipeline_descriptions = conn.describe_pipelines(
|
|
|
|
[pipeline_id])["pipelineDescriptionList"]
|
2015-09-16 14:00:38 +00:00
|
|
|
pipeline_descriptions.should.have.length_of(1)
|
|
|
|
|
|
|
|
pipeline_description = pipeline_descriptions[0]
|
2015-09-16 22:13:44 +00:00
|
|
|
pipeline_description['name'].should.equal("mypipeline")
|
|
|
|
pipeline_description["pipelineId"].should.equal(pipeline_id)
|
|
|
|
fields = pipeline_description['fields']
|
2015-09-16 14:00:38 +00:00
|
|
|
|
2015-09-16 15:22:52 +00:00
|
|
|
get_value_from_fields('@pipelineState', fields).should.equal("PENDING")
|
2015-09-16 14:00:38 +00:00
|
|
|
get_value_from_fields('uniqueId', fields).should.equal("some-unique-id")
|
|
|
|
|
|
|
|
|
|
|
|
PIPELINE_OBJECTS = [
|
|
|
|
{
|
|
|
|
"id": "Default",
|
|
|
|
"name": "Default",
|
|
|
|
"fields": [{
|
|
|
|
"key": "workerGroup",
|
|
|
|
"stringValue": "workerGroup"
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": "Schedule",
|
|
|
|
"name": "Schedule",
|
|
|
|
"fields": [{
|
|
|
|
"key": "startDateTime",
|
|
|
|
"stringValue": "2012-12-12T00:00:00"
|
|
|
|
}, {
|
|
|
|
"key": "type",
|
|
|
|
"stringValue": "Schedule"
|
|
|
|
}, {
|
|
|
|
"key": "period",
|
|
|
|
"stringValue": "1 hour"
|
|
|
|
}, {
|
|
|
|
"key": "endDateTime",
|
|
|
|
"stringValue": "2012-12-21T18:00:00"
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": "SayHello",
|
|
|
|
"name": "SayHello",
|
|
|
|
"fields": [{
|
|
|
|
"key": "type",
|
|
|
|
"stringValue": "ShellCommandActivity"
|
|
|
|
}, {
|
|
|
|
"key": "command",
|
|
|
|
"stringValue": "echo hello"
|
|
|
|
}, {
|
|
|
|
"key": "parent",
|
|
|
|
"refValue": "Default"
|
|
|
|
}, {
|
|
|
|
"key": "schedule",
|
|
|
|
"refValue": "Schedule"
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_datapipeline_deprecated
|
2015-09-16 14:00:38 +00:00
|
|
|
def test_creating_pipeline_definition():
|
|
|
|
conn = boto.datapipeline.connect_to_region("us-west-2")
|
|
|
|
res = conn.create_pipeline("mypipeline", "some-unique-id")
|
|
|
|
pipeline_id = res["pipelineId"]
|
|
|
|
|
|
|
|
conn.put_pipeline_definition(PIPELINE_OBJECTS, pipeline_id)
|
|
|
|
|
|
|
|
pipeline_definition = conn.get_pipeline_definition(pipeline_id)
|
|
|
|
pipeline_definition['pipelineObjects'].should.have.length_of(3)
|
|
|
|
default_object = pipeline_definition['pipelineObjects'][0]
|
2015-09-16 22:13:44 +00:00
|
|
|
default_object['name'].should.equal("Default")
|
|
|
|
default_object['id'].should.equal("Default")
|
|
|
|
default_object['fields'].should.equal([{
|
2015-09-16 14:00:38 +00:00
|
|
|
"key": "workerGroup",
|
|
|
|
"stringValue": "workerGroup"
|
|
|
|
}])
|
|
|
|
|
|
|
|
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_datapipeline_deprecated
|
2015-09-16 14:00:38 +00:00
|
|
|
def test_describing_pipeline_objects():
|
|
|
|
conn = boto.datapipeline.connect_to_region("us-west-2")
|
|
|
|
res = conn.create_pipeline("mypipeline", "some-unique-id")
|
|
|
|
pipeline_id = res["pipelineId"]
|
|
|
|
|
|
|
|
conn.put_pipeline_definition(PIPELINE_OBJECTS, pipeline_id)
|
|
|
|
|
2017-02-24 02:37:43 +00:00
|
|
|
objects = conn.describe_objects(["Schedule", "Default"], pipeline_id)[
|
|
|
|
'pipelineObjects']
|
2015-09-16 14:00:38 +00:00
|
|
|
|
|
|
|
objects.should.have.length_of(2)
|
2015-09-16 22:13:44 +00:00
|
|
|
default_object = [x for x in objects if x['id'] == 'Default'][0]
|
|
|
|
default_object['name'].should.equal("Default")
|
|
|
|
default_object['fields'].should.equal([{
|
2015-09-16 14:00:38 +00:00
|
|
|
"key": "workerGroup",
|
|
|
|
"stringValue": "workerGroup"
|
|
|
|
}])
|
|
|
|
|
|
|
|
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_datapipeline_deprecated
|
2015-09-16 14:00:38 +00:00
|
|
|
def test_activate_pipeline():
|
|
|
|
conn = boto.datapipeline.connect_to_region("us-west-2")
|
|
|
|
|
|
|
|
res = conn.create_pipeline("mypipeline", "some-unique-id")
|
|
|
|
|
|
|
|
pipeline_id = res["pipelineId"]
|
|
|
|
conn.activate_pipeline(pipeline_id)
|
|
|
|
|
2017-02-24 02:37:43 +00:00
|
|
|
pipeline_descriptions = conn.describe_pipelines(
|
|
|
|
[pipeline_id])["pipelineDescriptionList"]
|
2015-09-16 15:22:52 +00:00
|
|
|
pipeline_descriptions.should.have.length_of(1)
|
|
|
|
pipeline_description = pipeline_descriptions[0]
|
2015-09-16 22:13:44 +00:00
|
|
|
fields = pipeline_description['fields']
|
2015-09-16 15:22:52 +00:00
|
|
|
|
|
|
|
get_value_from_fields('@pipelineState', fields).should.equal("SCHEDULED")
|
2015-09-16 19:49:15 +00:00
|
|
|
|
|
|
|
|
2017-04-21 18:24:52 +00:00
|
|
|
@mock_datapipeline_deprecated
|
|
|
|
def test_delete_pipeline():
|
|
|
|
conn = boto.datapipeline.connect_to_region("us-west-2")
|
|
|
|
res = conn.create_pipeline("mypipeline", "some-unique-id")
|
|
|
|
pipeline_id = res["pipelineId"]
|
|
|
|
|
|
|
|
conn.delete_pipeline(pipeline_id)
|
|
|
|
|
|
|
|
response = conn.list_pipelines()
|
|
|
|
|
|
|
|
response["pipelineIdList"].should.have.length_of(0)
|
|
|
|
|
|
|
|
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_datapipeline_deprecated
|
2015-09-16 19:49:15 +00:00
|
|
|
def test_listing_pipelines():
|
|
|
|
conn = boto.datapipeline.connect_to_region("us-west-2")
|
|
|
|
res1 = conn.create_pipeline("mypipeline1", "some-unique-id1")
|
|
|
|
res2 = conn.create_pipeline("mypipeline2", "some-unique-id2")
|
|
|
|
|
|
|
|
response = conn.list_pipelines()
|
|
|
|
|
2015-09-17 19:18:57 +00:00
|
|
|
response["hasMoreResults"].should.be(False)
|
|
|
|
response["marker"].should.be.none
|
|
|
|
response["pipelineIdList"].should.have.length_of(2)
|
|
|
|
response["pipelineIdList"].should.contain({
|
2015-09-16 22:13:44 +00:00
|
|
|
"id": res1["pipelineId"],
|
|
|
|
"name": "mypipeline1",
|
2015-09-16 21:49:13 +00:00
|
|
|
})
|
2015-09-17 19:18:57 +00:00
|
|
|
response["pipelineIdList"].should.contain({
|
2015-09-16 22:13:44 +00:00
|
|
|
"id": res2["pipelineId"],
|
|
|
|
"name": "mypipeline2"
|
2015-09-16 21:49:13 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
# testing a helper function
|
|
|
|
def test_remove_capitalization_of_dict_keys():
|
|
|
|
result = remove_capitalization_of_dict_keys(
|
2015-09-16 19:49:15 +00:00
|
|
|
{
|
2015-09-16 21:49:13 +00:00
|
|
|
"Id": "IdValue",
|
|
|
|
"Fields": [{
|
|
|
|
"Key": "KeyValue",
|
|
|
|
"StringValue": "StringValueValue"
|
|
|
|
}]
|
2015-09-16 19:49:15 +00:00
|
|
|
}
|
2015-09-16 21:49:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
result.should.equal({
|
|
|
|
"id": "IdValue",
|
|
|
|
"fields": [{
|
|
|
|
"key": "KeyValue",
|
|
|
|
"stringValue": "StringValueValue"
|
|
|
|
}],
|
|
|
|
})
|