Run black on moto & test directories.
This commit is contained in:
parent
c820395dbf
commit
96e5b1993d
507 changed files with 52541 additions and 47814 deletions
|
|
@ -2,6 +2,6 @@ from __future__ import unicode_literals
|
|||
from .models import datapipeline_backends
|
||||
from ..core.models import base_decorator, deprecated_base_decorator
|
||||
|
||||
datapipeline_backend = datapipeline_backends['us-east-1']
|
||||
datapipeline_backend = datapipeline_backends["us-east-1"]
|
||||
mock_datapipeline = base_decorator(datapipeline_backends)
|
||||
mock_datapipeline_deprecated = deprecated_base_decorator(datapipeline_backends)
|
||||
|
|
|
|||
|
|
@ -8,85 +8,65 @@ from .utils import get_random_pipeline_id, remove_capitalization_of_dict_keys
|
|||
|
||||
|
||||
class PipelineObject(BaseModel):
|
||||
|
||||
def __init__(self, object_id, name, fields):
|
||||
self.object_id = object_id
|
||||
self.name = name
|
||||
self.fields = fields
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
"fields": self.fields,
|
||||
"id": self.object_id,
|
||||
"name": self.name,
|
||||
}
|
||||
return {"fields": self.fields, "id": self.object_id, "name": self.name}
|
||||
|
||||
|
||||
class Pipeline(BaseModel):
|
||||
|
||||
def __init__(self, name, unique_id, **kwargs):
|
||||
self.name = name
|
||||
self.unique_id = unique_id
|
||||
self.description = kwargs.get('description', '')
|
||||
self.description = kwargs.get("description", "")
|
||||
self.pipeline_id = get_random_pipeline_id()
|
||||
self.creation_time = datetime.datetime.utcnow()
|
||||
self.objects = []
|
||||
self.status = "PENDING"
|
||||
self.tags = kwargs.get('tags', [])
|
||||
self.tags = kwargs.get("tags", [])
|
||||
|
||||
@property
|
||||
def physical_resource_id(self):
|
||||
return self.pipeline_id
|
||||
|
||||
def to_meta_json(self):
|
||||
return {
|
||||
"id": self.pipeline_id,
|
||||
"name": self.name,
|
||||
}
|
||||
return {"id": self.pipeline_id, "name": self.name}
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
"description": self.description,
|
||||
"fields": [{
|
||||
"key": "@pipelineState",
|
||||
"stringValue": self.status,
|
||||
}, {
|
||||
"key": "description",
|
||||
"stringValue": self.description
|
||||
}, {
|
||||
"key": "name",
|
||||
"stringValue": self.name
|
||||
}, {
|
||||
"key": "@creationTime",
|
||||
"stringValue": datetime.datetime.strftime(self.creation_time, '%Y-%m-%dT%H-%M-%S'),
|
||||
}, {
|
||||
"key": "@id",
|
||||
"stringValue": self.pipeline_id,
|
||||
}, {
|
||||
"key": "@sphere",
|
||||
"stringValue": "PIPELINE"
|
||||
}, {
|
||||
"key": "@version",
|
||||
"stringValue": "1"
|
||||
}, {
|
||||
"key": "@userId",
|
||||
"stringValue": "924374875933"
|
||||
}, {
|
||||
"key": "@accountId",
|
||||
"stringValue": "924374875933"
|
||||
}, {
|
||||
"key": "uniqueId",
|
||||
"stringValue": self.unique_id
|
||||
}],
|
||||
"fields": [
|
||||
{"key": "@pipelineState", "stringValue": self.status},
|
||||
{"key": "description", "stringValue": self.description},
|
||||
{"key": "name", "stringValue": self.name},
|
||||
{
|
||||
"key": "@creationTime",
|
||||
"stringValue": datetime.datetime.strftime(
|
||||
self.creation_time, "%Y-%m-%dT%H-%M-%S"
|
||||
),
|
||||
},
|
||||
{"key": "@id", "stringValue": self.pipeline_id},
|
||||
{"key": "@sphere", "stringValue": "PIPELINE"},
|
||||
{"key": "@version", "stringValue": "1"},
|
||||
{"key": "@userId", "stringValue": "924374875933"},
|
||||
{"key": "@accountId", "stringValue": "924374875933"},
|
||||
{"key": "uniqueId", "stringValue": self.unique_id},
|
||||
],
|
||||
"name": self.name,
|
||||
"pipelineId": self.pipeline_id,
|
||||
"tags": self.tags
|
||||
"tags": self.tags,
|
||||
}
|
||||
|
||||
def set_pipeline_objects(self, pipeline_objects):
|
||||
self.objects = [
|
||||
PipelineObject(pipeline_object['id'], pipeline_object[
|
||||
'name'], pipeline_object['fields'])
|
||||
PipelineObject(
|
||||
pipeline_object["id"],
|
||||
pipeline_object["name"],
|
||||
pipeline_object["fields"],
|
||||
)
|
||||
for pipeline_object in remove_capitalization_of_dict_keys(pipeline_objects)
|
||||
]
|
||||
|
||||
|
|
@ -94,15 +74,19 @@ class Pipeline(BaseModel):
|
|||
self.status = "SCHEDULED"
|
||||
|
||||
@classmethod
|
||||
def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):
|
||||
def create_from_cloudformation_json(
|
||||
cls, resource_name, cloudformation_json, region_name
|
||||
):
|
||||
datapipeline_backend = datapipeline_backends[region_name]
|
||||
properties = cloudformation_json["Properties"]
|
||||
|
||||
cloudformation_unique_id = "cf-" + properties["Name"]
|
||||
pipeline = datapipeline_backend.create_pipeline(
|
||||
properties["Name"], cloudformation_unique_id)
|
||||
properties["Name"], cloudformation_unique_id
|
||||
)
|
||||
datapipeline_backend.put_pipeline_definition(
|
||||
pipeline.pipeline_id, properties["PipelineObjects"])
|
||||
pipeline.pipeline_id, properties["PipelineObjects"]
|
||||
)
|
||||
|
||||
if properties["Activate"]:
|
||||
pipeline.activate()
|
||||
|
|
@ -110,7 +94,6 @@ class Pipeline(BaseModel):
|
|||
|
||||
|
||||
class DataPipelineBackend(BaseBackend):
|
||||
|
||||
def __init__(self):
|
||||
self.pipelines = OrderedDict()
|
||||
|
||||
|
|
@ -123,8 +106,11 @@ class DataPipelineBackend(BaseBackend):
|
|||
return self.pipelines.values()
|
||||
|
||||
def describe_pipelines(self, pipeline_ids):
|
||||
pipelines = [pipeline for pipeline in self.pipelines.values(
|
||||
) if pipeline.pipeline_id in pipeline_ids]
|
||||
pipelines = [
|
||||
pipeline
|
||||
for pipeline in self.pipelines.values()
|
||||
if pipeline.pipeline_id in pipeline_ids
|
||||
]
|
||||
return pipelines
|
||||
|
||||
def get_pipeline(self, pipeline_id):
|
||||
|
|
@ -144,7 +130,8 @@ class DataPipelineBackend(BaseBackend):
|
|||
def describe_objects(self, object_ids, pipeline_id):
|
||||
pipeline = self.get_pipeline(pipeline_id)
|
||||
pipeline_objects = [
|
||||
pipeline_object for pipeline_object in pipeline.objects
|
||||
pipeline_object
|
||||
for pipeline_object in pipeline.objects
|
||||
if pipeline_object.object_id in object_ids
|
||||
]
|
||||
return pipeline_objects
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ from .models import datapipeline_backends
|
|||
|
||||
|
||||
class DataPipelineResponse(BaseResponse):
|
||||
|
||||
@property
|
||||
def parameters(self):
|
||||
# TODO this should really be moved to core/responses.py
|
||||
|
|
@ -21,47 +20,47 @@ class DataPipelineResponse(BaseResponse):
|
|||
return datapipeline_backends[self.region]
|
||||
|
||||
def create_pipeline(self):
|
||||
name = self.parameters.get('name')
|
||||
unique_id = self.parameters.get('uniqueId')
|
||||
description = self.parameters.get('description', '')
|
||||
tags = self.parameters.get('tags', [])
|
||||
pipeline = self.datapipeline_backend.create_pipeline(name, unique_id, description=description, tags=tags)
|
||||
return json.dumps({
|
||||
"pipelineId": pipeline.pipeline_id,
|
||||
})
|
||||
name = self.parameters.get("name")
|
||||
unique_id = self.parameters.get("uniqueId")
|
||||
description = self.parameters.get("description", "")
|
||||
tags = self.parameters.get("tags", [])
|
||||
pipeline = self.datapipeline_backend.create_pipeline(
|
||||
name, unique_id, description=description, tags=tags
|
||||
)
|
||||
return json.dumps({"pipelineId": pipeline.pipeline_id})
|
||||
|
||||
def list_pipelines(self):
|
||||
pipelines = list(self.datapipeline_backend.list_pipelines())
|
||||
pipeline_ids = [pipeline.pipeline_id for pipeline in pipelines]
|
||||
max_pipelines = 50
|
||||
marker = self.parameters.get('marker')
|
||||
marker = self.parameters.get("marker")
|
||||
if marker:
|
||||
start = pipeline_ids.index(marker) + 1
|
||||
else:
|
||||
start = 0
|
||||
pipelines_resp = pipelines[start:start + max_pipelines]
|
||||
pipelines_resp = pipelines[start : start + max_pipelines]
|
||||
has_more_results = False
|
||||
marker = None
|
||||
if start + max_pipelines < len(pipeline_ids) - 1:
|
||||
has_more_results = True
|
||||
marker = pipelines_resp[-1].pipeline_id
|
||||
return json.dumps({
|
||||
"hasMoreResults": has_more_results,
|
||||
"marker": marker,
|
||||
"pipelineIdList": [
|
||||
pipeline.to_meta_json() for pipeline in pipelines_resp
|
||||
]
|
||||
})
|
||||
return json.dumps(
|
||||
{
|
||||
"hasMoreResults": has_more_results,
|
||||
"marker": marker,
|
||||
"pipelineIdList": [
|
||||
pipeline.to_meta_json() for pipeline in pipelines_resp
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
def describe_pipelines(self):
|
||||
pipeline_ids = self.parameters["pipelineIds"]
|
||||
pipelines = self.datapipeline_backend.describe_pipelines(pipeline_ids)
|
||||
|
||||
return json.dumps({
|
||||
"pipelineDescriptionList": [
|
||||
pipeline.to_json() for pipeline in pipelines
|
||||
]
|
||||
})
|
||||
return json.dumps(
|
||||
{"pipelineDescriptionList": [pipeline.to_json() for pipeline in pipelines]}
|
||||
)
|
||||
|
||||
def delete_pipeline(self):
|
||||
pipeline_id = self.parameters["pipelineId"]
|
||||
|
|
@ -72,31 +71,38 @@ class DataPipelineResponse(BaseResponse):
|
|||
pipeline_id = self.parameters["pipelineId"]
|
||||
pipeline_objects = self.parameters["pipelineObjects"]
|
||||
|
||||
self.datapipeline_backend.put_pipeline_definition(
|
||||
pipeline_id, pipeline_objects)
|
||||
self.datapipeline_backend.put_pipeline_definition(pipeline_id, pipeline_objects)
|
||||
return json.dumps({"errored": False})
|
||||
|
||||
def get_pipeline_definition(self):
|
||||
pipeline_id = self.parameters["pipelineId"]
|
||||
pipeline_definition = self.datapipeline_backend.get_pipeline_definition(
|
||||
pipeline_id)
|
||||
return json.dumps({
|
||||
"pipelineObjects": [pipeline_object.to_json() for pipeline_object in pipeline_definition]
|
||||
})
|
||||
pipeline_id
|
||||
)
|
||||
return json.dumps(
|
||||
{
|
||||
"pipelineObjects": [
|
||||
pipeline_object.to_json() for pipeline_object in pipeline_definition
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
def describe_objects(self):
|
||||
pipeline_id = self.parameters["pipelineId"]
|
||||
object_ids = self.parameters["objectIds"]
|
||||
|
||||
pipeline_objects = self.datapipeline_backend.describe_objects(
|
||||
object_ids, pipeline_id)
|
||||
return json.dumps({
|
||||
"hasMoreResults": False,
|
||||
"marker": None,
|
||||
"pipelineObjects": [
|
||||
pipeline_object.to_json() for pipeline_object in pipeline_objects
|
||||
]
|
||||
})
|
||||
object_ids, pipeline_id
|
||||
)
|
||||
return json.dumps(
|
||||
{
|
||||
"hasMoreResults": False,
|
||||
"marker": None,
|
||||
"pipelineObjects": [
|
||||
pipeline_object.to_json() for pipeline_object in pipeline_objects
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
def activate_pipeline(self):
|
||||
pipeline_id = self.parameters["pipelineId"]
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
from __future__ import unicode_literals
|
||||
from .responses import DataPipelineResponse
|
||||
|
||||
url_bases = [
|
||||
"https?://datapipeline.(.+).amazonaws.com",
|
||||
]
|
||||
url_bases = ["https?://datapipeline.(.+).amazonaws.com"]
|
||||
|
||||
url_paths = {
|
||||
'{0}/$': DataPipelineResponse.dispatch,
|
||||
}
|
||||
url_paths = {"{0}/$": DataPipelineResponse.dispatch}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,9 @@ def remove_capitalization_of_dict_keys(obj):
|
|||
normalized_key = key[:1].lower() + key[1:]
|
||||
result[normalized_key] = remove_capitalization_of_dict_keys(value)
|
||||
return result
|
||||
elif isinstance(obj, collections.Iterable) and not isinstance(obj, six.string_types):
|
||||
elif isinstance(obj, collections.Iterable) and not isinstance(
|
||||
obj, six.string_types
|
||||
):
|
||||
result = obj.__class__()
|
||||
for item in obj:
|
||||
result += (remove_capitalization_of_dict_keys(item),)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue