fix linting errors
This commit is contained in:
parent
a6aa0f6dbf
commit
ed8d5edb50
@ -27,7 +27,7 @@ class InvalidStateTransitionException(IoTClientError):
|
|||||||
self.code = 409
|
self.code = 409
|
||||||
super(InvalidStateTransitionException, self).__init__(
|
super(InvalidStateTransitionException, self).__init__(
|
||||||
"InvalidStateTransitionException",
|
"InvalidStateTransitionException",
|
||||||
msg or "An attempt was made to change to an invalid state."
|
msg or "An attempt was made to change to an invalid state.",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ from .exceptions import (
|
|||||||
ResourceNotFoundException,
|
ResourceNotFoundException,
|
||||||
InvalidRequestException,
|
InvalidRequestException,
|
||||||
InvalidStateTransitionException,
|
InvalidStateTransitionException,
|
||||||
VersionConflictException
|
VersionConflictException,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -187,7 +187,7 @@ class FakePolicy(BaseModel):
|
|||||||
"policyName": self.name,
|
"policyName": self.name,
|
||||||
"policyArn": self.arn,
|
"policyArn": self.arn,
|
||||||
"policyDocument": self.document,
|
"policyDocument": self.document,
|
||||||
"defaultVersionId": self.default_version_id
|
"defaultVersionId": self.default_version_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
def to_dict_at_creation(self):
|
def to_dict_at_creation(self):
|
||||||
@ -195,7 +195,7 @@ class FakePolicy(BaseModel):
|
|||||||
"policyName": self.name,
|
"policyName": self.name,
|
||||||
"policyArn": self.arn,
|
"policyArn": self.arn,
|
||||||
"policyDocument": self.document,
|
"policyDocument": self.document,
|
||||||
"policyVersionId": self.default_version_id
|
"policyVersionId": self.default_version_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
@ -203,12 +203,7 @@ class FakePolicy(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class FakePolicyVersion(object):
|
class FakePolicyVersion(object):
|
||||||
|
def __init__(self, policy_name, document, is_default, region_name):
|
||||||
def __init__(self,
|
|
||||||
policy_name,
|
|
||||||
document,
|
|
||||||
is_default,
|
|
||||||
region_name):
|
|
||||||
self.name = policy_name
|
self.name = policy_name
|
||||||
self.arn = "arn:aws:iot:%s:1:policy/%s" % (region_name, policy_name)
|
self.arn = "arn:aws:iot:%s:1:policy/%s" % (region_name, policy_name)
|
||||||
self.document = document or {}
|
self.document = document or {}
|
||||||
@ -227,7 +222,7 @@ class FakePolicyVersion(object):
|
|||||||
"isDefaultVersion": self.is_default,
|
"isDefaultVersion": self.is_default,
|
||||||
"creationDate": self.create_datetime,
|
"creationDate": self.create_datetime,
|
||||||
"lastModifiedDate": self.last_modified_datetime,
|
"lastModifiedDate": self.last_modified_datetime,
|
||||||
"generationId": self.version_id
|
"generationId": self.version_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
def to_dict_at_creation(self):
|
def to_dict_at_creation(self):
|
||||||
@ -235,7 +230,7 @@ class FakePolicyVersion(object):
|
|||||||
"policyArn": self.arn,
|
"policyArn": self.arn,
|
||||||
"policyDocument": self.document,
|
"policyDocument": self.document,
|
||||||
"policyVersionId": self.version_id,
|
"policyVersionId": self.version_id,
|
||||||
"isDefaultVersion": self.is_default
|
"isDefaultVersion": self.is_default,
|
||||||
}
|
}
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
@ -314,7 +309,7 @@ class FakeJob(BaseModel):
|
|||||||
"jobProcessDetails": self.job_process_details,
|
"jobProcessDetails": self.job_process_details,
|
||||||
"documentParameters": self.document_parameters,
|
"documentParameters": self.document_parameters,
|
||||||
"document": self.document,
|
"document": self.document,
|
||||||
"documentSource": self.document_source
|
"documentSource": self.document_source,
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
@ -326,8 +321,14 @@ class FakeJob(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class FakeJobExecution(BaseModel):
|
class FakeJobExecution(BaseModel):
|
||||||
|
def __init__(
|
||||||
def __init__(self, job_id, thing_arn, status="QUEUED", force_canceled=False, status_details_map={}):
|
self,
|
||||||
|
job_id,
|
||||||
|
thing_arn,
|
||||||
|
status="QUEUED",
|
||||||
|
force_canceled=False,
|
||||||
|
status_details_map={},
|
||||||
|
):
|
||||||
self.job_id = job_id
|
self.job_id = job_id
|
||||||
self.status = status # IN_PROGRESS | CANCELED | COMPLETED
|
self.status = status # IN_PROGRESS | CANCELED | COMPLETED
|
||||||
self.force_canceled = force_canceled
|
self.force_canceled = force_canceled
|
||||||
@ -352,7 +353,7 @@ class FakeJobExecution(BaseModel):
|
|||||||
"lastUpdatedAt": self.last_updated_at,
|
"lastUpdatedAt": self.last_updated_at,
|
||||||
"executionNumber": self.execution_number,
|
"executionNumber": self.execution_number,
|
||||||
"versionNumber": self.version_number,
|
"versionNumber": self.version_number,
|
||||||
"approximateSecondsBeforeTimedOut": self.approximate_seconds_before_time_out
|
"approximateSecondsBeforeTimedOut": self.approximate_seconds_before_time_out,
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
@ -367,7 +368,7 @@ class FakeJobExecution(BaseModel):
|
|||||||
"startedAt": self.started_at,
|
"startedAt": self.started_at,
|
||||||
"lastUpdatedAt": self.last_updated_at,
|
"lastUpdatedAt": self.last_updated_at,
|
||||||
"executionNumber": self.execution_number,
|
"executionNumber": self.execution_number,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
@ -684,7 +685,9 @@ class IoTBackend(BaseBackend):
|
|||||||
policy = self.get_policy(policy_name)
|
policy = self.get_policy(policy_name)
|
||||||
if not policy:
|
if not policy:
|
||||||
raise ResourceNotFoundException()
|
raise ResourceNotFoundException()
|
||||||
version = FakePolicyVersion(policy_name, policy_document, set_as_default, self.region_name)
|
version = FakePolicyVersion(
|
||||||
|
policy_name, policy_document, set_as_default, self.region_name
|
||||||
|
)
|
||||||
policy.versions.append(version)
|
policy.versions.append(version)
|
||||||
version.version_id = "{0}".format(len(policy.versions))
|
version.version_id = "{0}".format(len(policy.versions))
|
||||||
if set_as_default:
|
if set_as_default:
|
||||||
@ -724,7 +727,8 @@ class IoTBackend(BaseBackend):
|
|||||||
raise ResourceNotFoundException()
|
raise ResourceNotFoundException()
|
||||||
if version_id == policy.default_version_id:
|
if version_id == policy.default_version_id:
|
||||||
raise InvalidRequestException(
|
raise InvalidRequestException(
|
||||||
"Cannot delete the default version of a policy")
|
"Cannot delete the default version of a policy"
|
||||||
|
)
|
||||||
for i, v in enumerate(policy.versions):
|
for i, v in enumerate(policy.versions):
|
||||||
if v.version_id == version_id:
|
if v.version_id == version_id:
|
||||||
del policy.versions[i]
|
del policy.versions[i]
|
||||||
@ -1017,7 +1021,15 @@ class IoTBackend(BaseBackend):
|
|||||||
def get_job_document(self, job_id):
|
def get_job_document(self, job_id):
|
||||||
return self.jobs[job_id]
|
return self.jobs[job_id]
|
||||||
|
|
||||||
def list_jobs(self, status, target_selection, max_results, token, thing_group_name, thing_group_id):
|
def list_jobs(
|
||||||
|
self,
|
||||||
|
status,
|
||||||
|
target_selection,
|
||||||
|
max_results,
|
||||||
|
token,
|
||||||
|
thing_group_name,
|
||||||
|
thing_group_id,
|
||||||
|
):
|
||||||
# TODO: implement filters
|
# TODO: implement filters
|
||||||
all_jobs = [_.to_dict() for _ in self.jobs.values()]
|
all_jobs = [_.to_dict() for _ in self.jobs.values()]
|
||||||
filtered_jobs = all_jobs
|
filtered_jobs = all_jobs
|
||||||
@ -1027,8 +1039,12 @@ class IoTBackend(BaseBackend):
|
|||||||
next_token = str(max_results) if len(filtered_jobs) > max_results else None
|
next_token = str(max_results) if len(filtered_jobs) > max_results else None
|
||||||
else:
|
else:
|
||||||
token = int(token)
|
token = int(token)
|
||||||
jobs = filtered_jobs[token:token + max_results]
|
jobs = filtered_jobs[token : token + max_results]
|
||||||
next_token = str(token + max_results) if len(filtered_jobs) > token + max_results else None
|
next_token = (
|
||||||
|
str(token + max_results)
|
||||||
|
if len(filtered_jobs) > token + max_results
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
|
||||||
return jobs, next_token
|
return jobs, next_token
|
||||||
|
|
||||||
@ -1038,19 +1054,25 @@ class IoTBackend(BaseBackend):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
raise ResourceNotFoundException()
|
raise ResourceNotFoundException()
|
||||||
|
|
||||||
if job_execution is None or \
|
if job_execution is None or (
|
||||||
(execution_number is not None and job_execution.execution_number != execution_number):
|
execution_number is not None
|
||||||
|
and job_execution.execution_number != execution_number
|
||||||
|
):
|
||||||
raise ResourceNotFoundException()
|
raise ResourceNotFoundException()
|
||||||
|
|
||||||
return job_execution
|
return job_execution
|
||||||
|
|
||||||
def cancel_job_execution(self, job_id, thing_name, force, expected_version, status_details):
|
def cancel_job_execution(
|
||||||
|
self, job_id, thing_name, force, expected_version, status_details
|
||||||
|
):
|
||||||
job_execution = self.job_executions[(job_id, thing_name)]
|
job_execution = self.job_executions[(job_id, thing_name)]
|
||||||
|
|
||||||
if job_execution is None:
|
if job_execution is None:
|
||||||
raise ResourceNotFoundException()
|
raise ResourceNotFoundException()
|
||||||
|
|
||||||
job_execution.force_canceled = force if force is not None else job_execution.force_canceled
|
job_execution.force_canceled = (
|
||||||
|
force if force is not None else job_execution.force_canceled
|
||||||
|
)
|
||||||
# TODO: implement expected_version and status_details (at most 10 can be specified)
|
# TODO: implement expected_version and status_details (at most 10 can be specified)
|
||||||
|
|
||||||
if job_execution.status == "IN_PROGRESS" and force:
|
if job_execution.status == "IN_PROGRESS" and force:
|
||||||
@ -1076,11 +1098,19 @@ class IoTBackend(BaseBackend):
|
|||||||
raise InvalidStateTransitionException()
|
raise InvalidStateTransitionException()
|
||||||
|
|
||||||
def list_job_executions_for_job(self, job_id, status, max_results, next_token):
|
def list_job_executions_for_job(self, job_id, status, max_results, next_token):
|
||||||
job_executions = [self.job_executions[je].to_dict() for je in self.job_executions if je[0] == job_id]
|
job_executions = [
|
||||||
|
self.job_executions[je].to_dict()
|
||||||
|
for je in self.job_executions
|
||||||
|
if je[0] == job_id
|
||||||
|
]
|
||||||
|
|
||||||
if status is not None:
|
if status is not None:
|
||||||
job_executions = list(filter(lambda elem:
|
job_executions = list(
|
||||||
status in elem["status"] and elem["status"] == status, job_executions))
|
filter(
|
||||||
|
lambda elem: status in elem["status"] and elem["status"] == status,
|
||||||
|
job_executions,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
token = next_token
|
token = next_token
|
||||||
if token is None:
|
if token is None:
|
||||||
@ -1088,17 +1118,31 @@ class IoTBackend(BaseBackend):
|
|||||||
next_token = str(max_results) if len(job_executions) > max_results else None
|
next_token = str(max_results) if len(job_executions) > max_results else None
|
||||||
else:
|
else:
|
||||||
token = int(token)
|
token = int(token)
|
||||||
job_executions = job_executions[token:token + max_results]
|
job_executions = job_executions[token : token + max_results]
|
||||||
next_token = str(token + max_results) if len(job_executions) > token + max_results else None
|
next_token = (
|
||||||
|
str(token + max_results)
|
||||||
|
if len(job_executions) > token + max_results
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
|
||||||
return job_executions, next_token
|
return job_executions, next_token
|
||||||
|
|
||||||
def list_job_executions_for_thing(self, thing_name, status, max_results, next_token):
|
def list_job_executions_for_thing(
|
||||||
job_executions = [self.job_executions[je].to_dict() for je in self.job_executions if je[1] == thing_name]
|
self, thing_name, status, max_results, next_token
|
||||||
|
):
|
||||||
|
job_executions = [
|
||||||
|
self.job_executions[je].to_dict()
|
||||||
|
for je in self.job_executions
|
||||||
|
if je[1] == thing_name
|
||||||
|
]
|
||||||
|
|
||||||
if status is not None:
|
if status is not None:
|
||||||
job_executions = list(filter(lambda elem:
|
job_executions = list(
|
||||||
status in elem["status"] and elem["status"] == status, job_executions))
|
filter(
|
||||||
|
lambda elem: status in elem["status"] and elem["status"] == status,
|
||||||
|
job_executions,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
token = next_token
|
token = next_token
|
||||||
if token is None:
|
if token is None:
|
||||||
@ -1106,8 +1150,12 @@ class IoTBackend(BaseBackend):
|
|||||||
next_token = str(max_results) if len(job_executions) > max_results else None
|
next_token = str(max_results) if len(job_executions) > max_results else None
|
||||||
else:
|
else:
|
||||||
token = int(token)
|
token = int(token)
|
||||||
job_executions = job_executions[token:token + max_results]
|
job_executions = job_executions[token : token + max_results]
|
||||||
next_token = str(token + max_results) if len(job_executions) > token + max_results else None
|
next_token = (
|
||||||
|
str(token + max_results)
|
||||||
|
if len(job_executions) > token + max_results
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
|
||||||
return job_executions, next_token
|
return job_executions, next_token
|
||||||
|
|
||||||
|
@ -133,33 +133,35 @@ class IoTResponse(BaseResponse):
|
|||||||
|
|
||||||
def describe_job(self):
|
def describe_job(self):
|
||||||
job = self.iot_backend.describe_job(job_id=self._get_param("jobId"))
|
job = self.iot_backend.describe_job(job_id=self._get_param("jobId"))
|
||||||
return json.dumps(dict(
|
return json.dumps(
|
||||||
documentSource=job.document_source,
|
dict(
|
||||||
job=dict(
|
documentSource=job.document_source,
|
||||||
comment=job.comment,
|
job=dict(
|
||||||
completedAt=job.completed_at,
|
comment=job.comment,
|
||||||
createdAt=job.created_at,
|
completedAt=job.completed_at,
|
||||||
description=job.description,
|
createdAt=job.created_at,
|
||||||
documentParameters=job.document_parameters,
|
description=job.description,
|
||||||
forceCanceled=job.force,
|
documentParameters=job.document_parameters,
|
||||||
reasonCode=job.reason_code,
|
forceCanceled=job.force,
|
||||||
jobArn=job.job_arn,
|
reasonCode=job.reason_code,
|
||||||
jobExecutionsRolloutConfig=job.job_executions_rollout_config,
|
jobArn=job.job_arn,
|
||||||
jobId=job.job_id,
|
jobExecutionsRolloutConfig=job.job_executions_rollout_config,
|
||||||
jobProcessDetails=job.job_process_details,
|
jobId=job.job_id,
|
||||||
lastUpdatedAt=job.last_updated_at,
|
jobProcessDetails=job.job_process_details,
|
||||||
presignedUrlConfig=job.presigned_url_config,
|
lastUpdatedAt=job.last_updated_at,
|
||||||
status=job.status,
|
presignedUrlConfig=job.presigned_url_config,
|
||||||
targets=job.targets,
|
status=job.status,
|
||||||
targetSelection=job.target_selection
|
targets=job.targets,
|
||||||
)))
|
targetSelection=job.target_selection,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def delete_job(self):
|
def delete_job(self):
|
||||||
job_id = self._get_param("jobId")
|
job_id = self._get_param("jobId")
|
||||||
force = self._get_bool_param("force")
|
force = self._get_bool_param("force")
|
||||||
|
|
||||||
self.iot_backend.delete_job(job_id=job_id,
|
self.iot_backend.delete_job(job_id=job_id, force=force)
|
||||||
force=force)
|
|
||||||
|
|
||||||
return json.dumps(dict())
|
return json.dumps(dict())
|
||||||
|
|
||||||
@ -169,10 +171,9 @@ class IoTResponse(BaseResponse):
|
|||||||
comment = self._get_param("comment")
|
comment = self._get_param("comment")
|
||||||
force = self._get_bool_param("force")
|
force = self._get_bool_param("force")
|
||||||
|
|
||||||
job = self.iot_backend.cancel_job(job_id=job_id,
|
job = self.iot_backend.cancel_job(
|
||||||
reason_code=reason_code,
|
job_id=job_id, reason_code=reason_code, comment=comment, force=force
|
||||||
comment=comment,
|
)
|
||||||
force=force)
|
|
||||||
|
|
||||||
return json.dumps(job.to_dict())
|
return json.dumps(job.to_dict())
|
||||||
|
|
||||||
@ -180,25 +181,29 @@ class IoTResponse(BaseResponse):
|
|||||||
job = self.iot_backend.get_job_document(job_id=self._get_param("jobId"))
|
job = self.iot_backend.get_job_document(job_id=self._get_param("jobId"))
|
||||||
|
|
||||||
if job.document is not None:
|
if job.document is not None:
|
||||||
return json.dumps({'document': job.document})
|
return json.dumps({"document": job.document})
|
||||||
else:
|
else:
|
||||||
# job.document_source is not None:
|
# job.document_source is not None:
|
||||||
# TODO: needs to be implemented to get document_source's content from S3
|
# TODO: needs to be implemented to get document_source's content from S3
|
||||||
return json.dumps({'document': ''})
|
return json.dumps({"document": ""})
|
||||||
|
|
||||||
def list_jobs(self):
|
def list_jobs(self):
|
||||||
status = self._get_param("status"),
|
status = (self._get_param("status"),)
|
||||||
target_selection = self._get_param("targetSelection"),
|
target_selection = (self._get_param("targetSelection"),)
|
||||||
max_results = self._get_int_param("maxResults", 50) # not the default, but makes testing easier
|
max_results = self._get_int_param(
|
||||||
|
"maxResults", 50
|
||||||
|
) # not the default, but makes testing easier
|
||||||
previous_next_token = self._get_param("nextToken")
|
previous_next_token = self._get_param("nextToken")
|
||||||
thing_group_name = self._get_param("thingGroupName"),
|
thing_group_name = (self._get_param("thingGroupName"),)
|
||||||
thing_group_id = self._get_param("thingGroupId")
|
thing_group_id = self._get_param("thingGroupId")
|
||||||
jobs, next_token = self.iot_backend.list_jobs(status=status,
|
jobs, next_token = self.iot_backend.list_jobs(
|
||||||
target_selection=target_selection,
|
status=status,
|
||||||
max_results=max_results,
|
target_selection=target_selection,
|
||||||
token=previous_next_token,
|
max_results=max_results,
|
||||||
thing_group_name=thing_group_name,
|
token=previous_next_token,
|
||||||
thing_group_id=thing_group_id)
|
thing_group_name=thing_group_name,
|
||||||
|
thing_group_id=thing_group_id,
|
||||||
|
)
|
||||||
|
|
||||||
return json.dumps(dict(jobs=jobs, nextToken=next_token))
|
return json.dumps(dict(jobs=jobs, nextToken=next_token))
|
||||||
|
|
||||||
@ -206,9 +211,9 @@ class IoTResponse(BaseResponse):
|
|||||||
job_id = self._get_param("jobId")
|
job_id = self._get_param("jobId")
|
||||||
thing_name = self._get_param("thingName")
|
thing_name = self._get_param("thingName")
|
||||||
execution_number = self._get_int_param("executionNumber")
|
execution_number = self._get_int_param("executionNumber")
|
||||||
job_execution = self.iot_backend.describe_job_execution(job_id=job_id,
|
job_execution = self.iot_backend.describe_job_execution(
|
||||||
thing_name=thing_name,
|
job_id=job_id, thing_name=thing_name, execution_number=execution_number
|
||||||
execution_number=execution_number)
|
)
|
||||||
|
|
||||||
return json.dumps(dict(execution=job_execution.to_get_dict()))
|
return json.dumps(dict(execution=job_execution.to_get_dict()))
|
||||||
|
|
||||||
@ -219,11 +224,13 @@ class IoTResponse(BaseResponse):
|
|||||||
expected_version = self._get_int_param("expectedVersion")
|
expected_version = self._get_int_param("expectedVersion")
|
||||||
status_details = self._get_param("statusDetails")
|
status_details = self._get_param("statusDetails")
|
||||||
|
|
||||||
self.iot_backend.cancel_job_execution(job_id=job_id,
|
self.iot_backend.cancel_job_execution(
|
||||||
thing_name=thing_name,
|
job_id=job_id,
|
||||||
force=force,
|
thing_name=thing_name,
|
||||||
expected_version=expected_version,
|
force=force,
|
||||||
status_details=status_details)
|
expected_version=expected_version,
|
||||||
|
status_details=status_details,
|
||||||
|
)
|
||||||
|
|
||||||
return json.dumps(dict())
|
return json.dumps(dict())
|
||||||
|
|
||||||
@ -233,34 +240,41 @@ class IoTResponse(BaseResponse):
|
|||||||
execution_number = self._get_int_param("executionNumber")
|
execution_number = self._get_int_param("executionNumber")
|
||||||
force = self._get_bool_param("force")
|
force = self._get_bool_param("force")
|
||||||
|
|
||||||
self.iot_backend.delete_job_execution(job_id=job_id,
|
self.iot_backend.delete_job_execution(
|
||||||
thing_name=thing_name,
|
job_id=job_id,
|
||||||
execution_number=execution_number,
|
thing_name=thing_name,
|
||||||
force=force)
|
execution_number=execution_number,
|
||||||
|
force=force,
|
||||||
|
)
|
||||||
|
|
||||||
return json.dumps(dict())
|
return json.dumps(dict())
|
||||||
|
|
||||||
def list_job_executions_for_job(self):
|
def list_job_executions_for_job(self):
|
||||||
job_id = self._get_param("jobId")
|
job_id = self._get_param("jobId")
|
||||||
status = self._get_param("status")
|
status = self._get_param("status")
|
||||||
max_results = self._get_int_param("maxResults", 50) # not the default, but makes testing easier
|
max_results = self._get_int_param(
|
||||||
|
"maxResults", 50
|
||||||
|
) # not the default, but makes testing easier
|
||||||
next_token = self._get_param("nextToken")
|
next_token = self._get_param("nextToken")
|
||||||
job_executions, next_token = self.iot_backend.list_job_executions_for_job(job_id=job_id,
|
job_executions, next_token = self.iot_backend.list_job_executions_for_job(
|
||||||
status=status,
|
job_id=job_id, status=status, max_results=max_results, next_token=next_token
|
||||||
max_results=max_results,
|
)
|
||||||
next_token=next_token)
|
|
||||||
|
|
||||||
return json.dumps(dict(executionSummaries=job_executions, nextToken=next_token))
|
return json.dumps(dict(executionSummaries=job_executions, nextToken=next_token))
|
||||||
|
|
||||||
def list_job_executions_for_thing(self):
|
def list_job_executions_for_thing(self):
|
||||||
thing_name = self._get_param("thingName")
|
thing_name = self._get_param("thingName")
|
||||||
status = self._get_param("status")
|
status = self._get_param("status")
|
||||||
max_results = self._get_int_param("maxResults", 50) # not the default, but makes testing easier
|
max_results = self._get_int_param(
|
||||||
|
"maxResults", 50
|
||||||
|
) # not the default, but makes testing easier
|
||||||
next_token = self._get_param("nextToken")
|
next_token = self._get_param("nextToken")
|
||||||
job_executions, next_token = self.iot_backend.list_job_executions_for_thing(thing_name=thing_name,
|
job_executions, next_token = self.iot_backend.list_job_executions_for_thing(
|
||||||
status=status,
|
thing_name=thing_name,
|
||||||
max_results=max_results,
|
status=status,
|
||||||
next_token=next_token)
|
max_results=max_results,
|
||||||
|
next_token=next_token,
|
||||||
|
)
|
||||||
|
|
||||||
return json.dumps(dict(executionSummaries=job_executions, nextToken=next_token))
|
return json.dumps(dict(executionSummaries=job_executions, nextToken=next_token))
|
||||||
|
|
||||||
@ -352,35 +366,39 @@ class IoTResponse(BaseResponse):
|
|||||||
return json.dumps(dict())
|
return json.dumps(dict())
|
||||||
|
|
||||||
def create_policy_version(self):
|
def create_policy_version(self):
|
||||||
policy_name = self._get_param('policyName')
|
policy_name = self._get_param("policyName")
|
||||||
policy_document = self._get_param('policyDocument')
|
policy_document = self._get_param("policyDocument")
|
||||||
set_as_default = self._get_bool_param('setAsDefault')
|
set_as_default = self._get_bool_param("setAsDefault")
|
||||||
policy_version = self.iot_backend.create_policy_version(policy_name, policy_document, set_as_default)
|
policy_version = self.iot_backend.create_policy_version(
|
||||||
|
policy_name, policy_document, set_as_default
|
||||||
|
)
|
||||||
|
|
||||||
return json.dumps(dict(policy_version.to_dict_at_creation()))
|
return json.dumps(dict(policy_version.to_dict_at_creation()))
|
||||||
|
|
||||||
def set_default_policy_version(self):
|
def set_default_policy_version(self):
|
||||||
policy_name = self._get_param('policyName')
|
policy_name = self._get_param("policyName")
|
||||||
version_id = self._get_param('policyVersionId')
|
version_id = self._get_param("policyVersionId")
|
||||||
self.iot_backend.set_default_policy_version(policy_name, version_id)
|
self.iot_backend.set_default_policy_version(policy_name, version_id)
|
||||||
|
|
||||||
return json.dumps(dict())
|
return json.dumps(dict())
|
||||||
|
|
||||||
def get_policy_version(self):
|
def get_policy_version(self):
|
||||||
policy_name = self._get_param('policyName')
|
policy_name = self._get_param("policyName")
|
||||||
version_id = self._get_param('policyVersionId')
|
version_id = self._get_param("policyVersionId")
|
||||||
policy_version = self.iot_backend.get_policy_version(policy_name, version_id)
|
policy_version = self.iot_backend.get_policy_version(policy_name, version_id)
|
||||||
return json.dumps(dict(policy_version.to_get_dict()))
|
return json.dumps(dict(policy_version.to_get_dict()))
|
||||||
|
|
||||||
def list_policy_versions(self):
|
def list_policy_versions(self):
|
||||||
policy_name = self._get_param('policyName')
|
policy_name = self._get_param("policyName")
|
||||||
policiy_versions = self.iot_backend.list_policy_versions(policy_name=policy_name)
|
policiy_versions = self.iot_backend.list_policy_versions(
|
||||||
|
policy_name=policy_name
|
||||||
|
)
|
||||||
|
|
||||||
return json.dumps(dict(policyVersions=[_.to_dict() for _ in policiy_versions]))
|
return json.dumps(dict(policyVersions=[_.to_dict() for _ in policiy_versions]))
|
||||||
|
|
||||||
def delete_policy_version(self):
|
def delete_policy_version(self):
|
||||||
policy_name = self._get_param('policyName')
|
policy_name = self._get_param("policyName")
|
||||||
version_id = self._get_param('policyVersionId')
|
version_id = self._get_param("policyVersionId")
|
||||||
self.iot_backend.delete_policy_version(policy_name, version_id)
|
self.iot_backend.delete_policy_version(policy_name, version_id)
|
||||||
|
|
||||||
return json.dumps(dict())
|
return json.dumps(dict())
|
||||||
@ -392,15 +410,15 @@ class IoTResponse(BaseResponse):
|
|||||||
return json.dumps(dict())
|
return json.dumps(dict())
|
||||||
|
|
||||||
def list_attached_policies(self):
|
def list_attached_policies(self):
|
||||||
principal = unquote(self._get_param('target'))
|
principal = unquote(self._get_param("target"))
|
||||||
# marker = self._get_param("marker")
|
# marker = self._get_param("marker")
|
||||||
# page_size = self._get_int_param("pageSize")
|
# page_size = self._get_int_param("pageSize")
|
||||||
policies = self.iot_backend.list_attached_policies(
|
policies = self.iot_backend.list_attached_policies(target=principal)
|
||||||
target=principal
|
|
||||||
)
|
|
||||||
# TODO: implement pagination in the future
|
# TODO: implement pagination in the future
|
||||||
next_marker = None
|
next_marker = None
|
||||||
return json.dumps(dict(policies=[_.to_dict() for _ in policies], nextMarker=next_marker))
|
return json.dumps(
|
||||||
|
dict(policies=[_.to_dict() for _ in policies], nextMarker=next_marker)
|
||||||
|
)
|
||||||
|
|
||||||
def attach_principal_policy(self):
|
def attach_principal_policy(self):
|
||||||
policy_name = self._get_param("policyName")
|
policy_name = self._get_param("policyName")
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import sure #noqa
|
import sure # noqa
|
||||||
import boto3
|
import boto3
|
||||||
|
|
||||||
from moto import mock_iot
|
from moto import mock_iot
|
||||||
from botocore.exceptions import ClientError
|
from botocore.exceptions import ClientError
|
||||||
from nose.tools import assert_raises
|
from nose.tools import assert_raises
|
||||||
|
|
||||||
|
|
||||||
@mock_iot
|
@mock_iot
|
||||||
def test_attach_policy():
|
def test_attach_policy():
|
||||||
client = boto3.client("iot", region_name="ap-northeast-1")
|
client = boto3.client("iot", region_name="ap-northeast-1")
|
||||||
@ -68,67 +69,111 @@ def test_policy_versions():
|
|||||||
policy.should.have.key("policyName").which.should.equal(policy_name)
|
policy.should.have.key("policyName").which.should.equal(policy_name)
|
||||||
policy.should.have.key("policyArn").which.should_not.be.none
|
policy.should.have.key("policyArn").which.should_not.be.none
|
||||||
policy.should.have.key("policyDocument").which.should.equal(json.dumps({}))
|
policy.should.have.key("policyDocument").which.should.equal(json.dumps({}))
|
||||||
policy.should.have.key("defaultVersionId").which.should.equal(policy["defaultVersionId"])
|
policy.should.have.key("defaultVersionId").which.should.equal(
|
||||||
|
policy["defaultVersionId"]
|
||||||
|
)
|
||||||
|
|
||||||
policy1 = client.create_policy_version(policyName=policy_name, policyDocument=json.dumps({"version": "version_1"}),
|
policy1 = client.create_policy_version(
|
||||||
setAsDefault=True)
|
policyName=policy_name,
|
||||||
|
policyDocument=json.dumps({"version": "version_1"}),
|
||||||
|
setAsDefault=True,
|
||||||
|
)
|
||||||
policy1.should.have.key("policyArn").which.should_not.be.none
|
policy1.should.have.key("policyArn").which.should_not.be.none
|
||||||
policy1.should.have.key("policyDocument").which.should.equal(json.dumps({"version": "version_1"}))
|
policy1.should.have.key("policyDocument").which.should.equal(
|
||||||
|
json.dumps({"version": "version_1"})
|
||||||
|
)
|
||||||
policy1.should.have.key("policyVersionId").which.should.equal("2")
|
policy1.should.have.key("policyVersionId").which.should.equal("2")
|
||||||
policy1.should.have.key("isDefaultVersion").which.should.equal(True)
|
policy1.should.have.key("isDefaultVersion").which.should.equal(True)
|
||||||
|
|
||||||
policy2 = client.create_policy_version(policyName=policy_name, policyDocument=json.dumps({"version": "version_2"}),
|
policy2 = client.create_policy_version(
|
||||||
setAsDefault=False)
|
policyName=policy_name,
|
||||||
|
policyDocument=json.dumps({"version": "version_2"}),
|
||||||
|
setAsDefault=False,
|
||||||
|
)
|
||||||
policy2.should.have.key("policyArn").which.should_not.be.none
|
policy2.should.have.key("policyArn").which.should_not.be.none
|
||||||
policy2.should.have.key("policyDocument").which.should.equal(json.dumps({"version": "version_2"}))
|
policy2.should.have.key("policyDocument").which.should.equal(
|
||||||
|
json.dumps({"version": "version_2"})
|
||||||
|
)
|
||||||
policy2.should.have.key("policyVersionId").which.should.equal("3")
|
policy2.should.have.key("policyVersionId").which.should.equal("3")
|
||||||
policy2.should.have.key("isDefaultVersion").which.should.equal(False)
|
policy2.should.have.key("isDefaultVersion").which.should.equal(False)
|
||||||
|
|
||||||
policy = client.get_policy(policyName=policy_name)
|
policy = client.get_policy(policyName=policy_name)
|
||||||
policy.should.have.key("policyName").which.should.equal(policy_name)
|
policy.should.have.key("policyName").which.should.equal(policy_name)
|
||||||
policy.should.have.key("policyArn").which.should_not.be.none
|
policy.should.have.key("policyArn").which.should_not.be.none
|
||||||
policy.should.have.key("policyDocument").which.should.equal(json.dumps({"version": "version_1"}))
|
policy.should.have.key("policyDocument").which.should.equal(
|
||||||
policy.should.have.key("defaultVersionId").which.should.equal(policy1["policyVersionId"])
|
json.dumps({"version": "version_1"})
|
||||||
|
)
|
||||||
|
policy.should.have.key("defaultVersionId").which.should.equal(
|
||||||
|
policy1["policyVersionId"]
|
||||||
|
)
|
||||||
|
|
||||||
policy_versions = client.list_policy_versions(policyName=policy_name)
|
policy_versions = client.list_policy_versions(policyName=policy_name)
|
||||||
policy_versions.should.have.key("policyVersions").which.should.have.length_of(3)
|
policy_versions.should.have.key("policyVersions").which.should.have.length_of(3)
|
||||||
list(map(lambda item: item["isDefaultVersion"], policy_versions["policyVersions"])).count(True).should.equal(1)
|
list(
|
||||||
default_policy = list(filter(lambda item: item["isDefaultVersion"], policy_versions["policyVersions"]))
|
map(lambda item: item["isDefaultVersion"], policy_versions["policyVersions"])
|
||||||
default_policy[0].should.have.key("versionId").should.equal(policy1["policyVersionId"])
|
).count(True).should.equal(1)
|
||||||
|
default_policy = list(
|
||||||
|
filter(lambda item: item["isDefaultVersion"], policy_versions["policyVersions"])
|
||||||
|
)
|
||||||
|
default_policy[0].should.have.key("versionId").should.equal(
|
||||||
|
policy1["policyVersionId"]
|
||||||
|
)
|
||||||
|
|
||||||
policy = client.get_policy(policyName=policy_name)
|
policy = client.get_policy(policyName=policy_name)
|
||||||
policy.should.have.key("policyName").which.should.equal(policy_name)
|
policy.should.have.key("policyName").which.should.equal(policy_name)
|
||||||
policy.should.have.key("policyArn").which.should_not.be.none
|
policy.should.have.key("policyArn").which.should_not.be.none
|
||||||
policy.should.have.key("policyDocument").which.should.equal(json.dumps({"version": "version_1"}))
|
policy.should.have.key("policyDocument").which.should.equal(
|
||||||
policy.should.have.key("defaultVersionId").which.should.equal(policy1["policyVersionId"])
|
json.dumps({"version": "version_1"})
|
||||||
|
)
|
||||||
|
policy.should.have.key("defaultVersionId").which.should.equal(
|
||||||
|
policy1["policyVersionId"]
|
||||||
|
)
|
||||||
|
|
||||||
client.set_default_policy_version(policyName=policy_name, policyVersionId=policy2["policyVersionId"])
|
client.set_default_policy_version(
|
||||||
|
policyName=policy_name, policyVersionId=policy2["policyVersionId"]
|
||||||
|
)
|
||||||
policy_versions = client.list_policy_versions(policyName=policy_name)
|
policy_versions = client.list_policy_versions(policyName=policy_name)
|
||||||
policy_versions.should.have.key("policyVersions").which.should.have.length_of(3)
|
policy_versions.should.have.key("policyVersions").which.should.have.length_of(3)
|
||||||
list(map(lambda item: item["isDefaultVersion"], policy_versions["policyVersions"])).count(True).should.equal(1)
|
list(
|
||||||
default_policy = list(filter(lambda item: item["isDefaultVersion"], policy_versions["policyVersions"]))
|
map(lambda item: item["isDefaultVersion"], policy_versions["policyVersions"])
|
||||||
default_policy[0].should.have.key("versionId").should.equal(policy2["policyVersionId"])
|
).count(True).should.equal(1)
|
||||||
|
default_policy = list(
|
||||||
|
filter(lambda item: item["isDefaultVersion"], policy_versions["policyVersions"])
|
||||||
|
)
|
||||||
|
default_policy[0].should.have.key("versionId").should.equal(
|
||||||
|
policy2["policyVersionId"]
|
||||||
|
)
|
||||||
|
|
||||||
policy = client.get_policy(policyName=policy_name)
|
policy = client.get_policy(policyName=policy_name)
|
||||||
policy.should.have.key("policyName").which.should.equal(policy_name)
|
policy.should.have.key("policyName").which.should.equal(policy_name)
|
||||||
policy.should.have.key("policyArn").which.should_not.be.none
|
policy.should.have.key("policyArn").which.should_not.be.none
|
||||||
policy.should.have.key("policyDocument").which.should.equal(json.dumps({"version": "version_2"}))
|
policy.should.have.key("policyDocument").which.should.equal(
|
||||||
policy.should.have.key("defaultVersionId").which.should.equal(policy2["policyVersionId"])
|
json.dumps({"version": "version_2"})
|
||||||
|
)
|
||||||
|
policy.should.have.key("defaultVersionId").which.should.equal(
|
||||||
|
policy2["policyVersionId"]
|
||||||
|
)
|
||||||
|
|
||||||
client.delete_policy_version(policyName=policy_name, policyVersionId="1")
|
client.delete_policy_version(policyName=policy_name, policyVersionId="1")
|
||||||
policy_versions = client.list_policy_versions(policyName=policy_name)
|
policy_versions = client.list_policy_versions(policyName=policy_name)
|
||||||
policy_versions.should.have.key("policyVersions").which.should.have.length_of(2)
|
policy_versions.should.have.key("policyVersions").which.should.have.length_of(2)
|
||||||
|
|
||||||
client.delete_policy_version(policyName=policy_name, policyVersionId=policy1["policyVersionId"])
|
client.delete_policy_version(
|
||||||
|
policyName=policy_name, policyVersionId=policy1["policyVersionId"]
|
||||||
|
)
|
||||||
policy_versions = client.list_policy_versions(policyName=policy_name)
|
policy_versions = client.list_policy_versions(policyName=policy_name)
|
||||||
policy_versions.should.have.key("policyVersions").which.should.have.length_of(1)
|
policy_versions.should.have.key("policyVersions").which.should.have.length_of(1)
|
||||||
|
|
||||||
# should fail as it"s the default policy. Should use delete_policy instead
|
# should fail as it"s the default policy. Should use delete_policy instead
|
||||||
try:
|
try:
|
||||||
client.delete_policy_version(policyName=policy_name, policyVersionId=policy2["policyVersionId"])
|
client.delete_policy_version(
|
||||||
|
policyName=policy_name, policyVersionId=policy2["policyVersionId"]
|
||||||
|
)
|
||||||
assert False, "Should have failed in previous call"
|
assert False, "Should have failed in previous call"
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
exception.response["Error"]["Message"].should.equal("Cannot delete the default version of a policy")
|
exception.response["Error"]["Message"].should.equal(
|
||||||
|
"Cannot delete the default version of a policy"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@mock_iot
|
@mock_iot
|
||||||
@ -1159,9 +1204,7 @@ def test_list_jobs():
|
|||||||
thing.should.have.key("thingArn")
|
thing.should.have.key("thingArn")
|
||||||
|
|
||||||
# job document
|
# job document
|
||||||
job_document = {
|
job_document = {"field": "value"}
|
||||||
"field": "value"
|
|
||||||
}
|
|
||||||
|
|
||||||
job1 = client.create_job(
|
job1 = client.create_job(
|
||||||
jobId=job_id,
|
jobId=job_id,
|
||||||
@ -1170,12 +1213,10 @@ def test_list_jobs():
|
|||||||
description="Description",
|
description="Description",
|
||||||
presignedUrlConfig={
|
presignedUrlConfig={
|
||||||
"roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
|
"roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
|
||||||
"expiresInSec": 123
|
"expiresInSec": 123,
|
||||||
},
|
},
|
||||||
targetSelection="CONTINUOUS",
|
targetSelection="CONTINUOUS",
|
||||||
jobExecutionsRolloutConfig={
|
jobExecutionsRolloutConfig={"maximumPerMinute": 10},
|
||||||
"maximumPerMinute": 10
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
job1.should.have.key("jobId").which.should.equal(job_id)
|
job1.should.have.key("jobId").which.should.equal(job_id)
|
||||||
@ -1183,21 +1224,19 @@ def test_list_jobs():
|
|||||||
job1.should.have.key("description")
|
job1.should.have.key("description")
|
||||||
|
|
||||||
job2 = client.create_job(
|
job2 = client.create_job(
|
||||||
jobId=job_id+"1",
|
jobId=job_id + "1",
|
||||||
targets=[thing["thingArn"]],
|
targets=[thing["thingArn"]],
|
||||||
document=json.dumps(job_document),
|
document=json.dumps(job_document),
|
||||||
description="Description",
|
description="Description",
|
||||||
presignedUrlConfig={
|
presignedUrlConfig={
|
||||||
"roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
|
"roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
|
||||||
"expiresInSec": 123
|
"expiresInSec": 123,
|
||||||
},
|
},
|
||||||
targetSelection="CONTINUOUS",
|
targetSelection="CONTINUOUS",
|
||||||
jobExecutionsRolloutConfig={
|
jobExecutionsRolloutConfig={"maximumPerMinute": 10},
|
||||||
"maximumPerMinute": 10
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
job2.should.have.key("jobId").which.should.equal(job_id+"1")
|
job2.should.have.key("jobId").which.should.equal(job_id + "1")
|
||||||
job2.should.have.key("jobArn")
|
job2.should.have.key("jobArn")
|
||||||
job2.should.have.key("description")
|
job2.should.have.key("description")
|
||||||
|
|
||||||
@ -1205,7 +1244,7 @@ def test_list_jobs():
|
|||||||
jobs.should.have.key("jobs")
|
jobs.should.have.key("jobs")
|
||||||
jobs.should_not.have.key("nextToken")
|
jobs.should_not.have.key("nextToken")
|
||||||
jobs["jobs"][0].should.have.key("jobId").which.should.equal(job_id)
|
jobs["jobs"][0].should.have.key("jobId").which.should.equal(job_id)
|
||||||
jobs["jobs"][1].should.have.key("jobId").which.should.equal(job_id+"1")
|
jobs["jobs"][1].should.have.key("jobId").which.should.equal(job_id + "1")
|
||||||
|
|
||||||
|
|
||||||
@mock_iot
|
@mock_iot
|
||||||
@ -1297,14 +1336,21 @@ def test_describe_job_1():
|
|||||||
job.should.have.key("job").which.should.have.key("lastUpdatedAt")
|
job.should.have.key("job").which.should.have.key("lastUpdatedAt")
|
||||||
job.should.have.key("job").which.should.have.key("createdAt")
|
job.should.have.key("job").which.should.have.key("createdAt")
|
||||||
job.should.have.key("job").which.should.have.key("jobExecutionsRolloutConfig")
|
job.should.have.key("job").which.should.have.key("jobExecutionsRolloutConfig")
|
||||||
job.should.have.key("job").which.should.have.key("targetSelection").which.should.equal("CONTINUOUS")
|
job.should.have.key("job").which.should.have.key(
|
||||||
|
"targetSelection"
|
||||||
|
).which.should.equal("CONTINUOUS")
|
||||||
job.should.have.key("job").which.should.have.key("presignedUrlConfig")
|
job.should.have.key("job").which.should.have.key("presignedUrlConfig")
|
||||||
job.should.have.key("job").which.should.have.key("presignedUrlConfig").which.should.have.key(
|
job.should.have.key("job").which.should.have.key(
|
||||||
"roleArn").which.should.equal("arn:aws:iam::1:role/service-role/iot_job_role")
|
"presignedUrlConfig"
|
||||||
job.should.have.key("job").which.should.have.key("presignedUrlConfig").which.should.have.key(
|
).which.should.have.key("roleArn").which.should.equal(
|
||||||
"expiresInSec").which.should.equal(123)
|
"arn:aws:iam::1:role/service-role/iot_job_role"
|
||||||
job.should.have.key("job").which.should.have.key("jobExecutionsRolloutConfig").which.should.have.key(
|
)
|
||||||
"maximumPerMinute").which.should.equal(10)
|
job.should.have.key("job").which.should.have.key(
|
||||||
|
"presignedUrlConfig"
|
||||||
|
).which.should.have.key("expiresInSec").which.should.equal(123)
|
||||||
|
job.should.have.key("job").which.should.have.key(
|
||||||
|
"jobExecutionsRolloutConfig"
|
||||||
|
).which.should.have.key("maximumPerMinute").which.should.equal(10)
|
||||||
|
|
||||||
|
|
||||||
@mock_iot
|
@mock_iot
|
||||||
@ -1323,12 +1369,10 @@ def test_delete_job():
|
|||||||
documentSource="https://s3-eu-west-1.amazonaws.com/bucket-name/job_document.json",
|
documentSource="https://s3-eu-west-1.amazonaws.com/bucket-name/job_document.json",
|
||||||
presignedUrlConfig={
|
presignedUrlConfig={
|
||||||
"roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
|
"roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
|
||||||
"expiresInSec": 123
|
"expiresInSec": 123,
|
||||||
},
|
},
|
||||||
targetSelection="CONTINUOUS",
|
targetSelection="CONTINUOUS",
|
||||||
jobExecutionsRolloutConfig={
|
jobExecutionsRolloutConfig={"maximumPerMinute": 10},
|
||||||
"maximumPerMinute": 10
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
job.should.have.key("jobId").which.should.equal(job_id)
|
job.should.have.key("jobId").which.should.equal(job_id)
|
||||||
@ -1359,12 +1403,10 @@ def test_cancel_job():
|
|||||||
documentSource="https://s3-eu-west-1.amazonaws.com/bucket-name/job_document.json",
|
documentSource="https://s3-eu-west-1.amazonaws.com/bucket-name/job_document.json",
|
||||||
presignedUrlConfig={
|
presignedUrlConfig={
|
||||||
"roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
|
"roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
|
||||||
"expiresInSec": 123
|
"expiresInSec": 123,
|
||||||
},
|
},
|
||||||
targetSelection="CONTINUOUS",
|
targetSelection="CONTINUOUS",
|
||||||
jobExecutionsRolloutConfig={
|
jobExecutionsRolloutConfig={"maximumPerMinute": 10},
|
||||||
"maximumPerMinute": 10
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
job.should.have.key("jobId").which.should.equal(job_id)
|
job.should.have.key("jobId").which.should.equal(job_id)
|
||||||
@ -1381,10 +1423,18 @@ def test_cancel_job():
|
|||||||
job = client.describe_job(jobId=job_id)
|
job = client.describe_job(jobId=job_id)
|
||||||
job.should.have.key("job")
|
job.should.have.key("job")
|
||||||
job.should.have.key("job").which.should.have.key("jobId").which.should.equal(job_id)
|
job.should.have.key("job").which.should.have.key("jobId").which.should.equal(job_id)
|
||||||
job.should.have.key("job").which.should.have.key("status").which.should.equal("CANCELED")
|
job.should.have.key("job").which.should.have.key("status").which.should.equal(
|
||||||
job.should.have.key("job").which.should.have.key("forceCanceled").which.should.equal(False)
|
"CANCELED"
|
||||||
job.should.have.key("job").which.should.have.key("reasonCode").which.should.equal("Because")
|
)
|
||||||
job.should.have.key("job").which.should.have.key("comment").which.should.equal("You are")
|
job.should.have.key("job").which.should.have.key(
|
||||||
|
"forceCanceled"
|
||||||
|
).which.should.equal(False)
|
||||||
|
job.should.have.key("job").which.should.have.key("reasonCode").which.should.equal(
|
||||||
|
"Because"
|
||||||
|
)
|
||||||
|
job.should.have.key("job").which.should.have.key("comment").which.should.equal(
|
||||||
|
"You are"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@mock_iot
|
@mock_iot
|
||||||
@ -1403,12 +1453,10 @@ def test_get_job_document_with_document_source():
|
|||||||
documentSource="https://s3-eu-west-1.amazonaws.com/bucket-name/job_document.json",
|
documentSource="https://s3-eu-west-1.amazonaws.com/bucket-name/job_document.json",
|
||||||
presignedUrlConfig={
|
presignedUrlConfig={
|
||||||
"roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
|
"roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
|
||||||
"expiresInSec": 123
|
"expiresInSec": 123,
|
||||||
},
|
},
|
||||||
targetSelection="CONTINUOUS",
|
targetSelection="CONTINUOUS",
|
||||||
jobExecutionsRolloutConfig={
|
jobExecutionsRolloutConfig={"maximumPerMinute": 10},
|
||||||
"maximumPerMinute": 10
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
job.should.have.key("jobId").which.should.equal(job_id)
|
job.should.have.key("jobId").which.should.equal(job_id)
|
||||||
@ -1429,9 +1477,7 @@ def test_get_job_document_with_document():
|
|||||||
thing.should.have.key("thingArn")
|
thing.should.have.key("thingArn")
|
||||||
|
|
||||||
# job document
|
# job document
|
||||||
job_document = {
|
job_document = {"field": "value"}
|
||||||
"field": "value"
|
|
||||||
}
|
|
||||||
|
|
||||||
job = client.create_job(
|
job = client.create_job(
|
||||||
jobId=job_id,
|
jobId=job_id,
|
||||||
@ -1439,19 +1485,17 @@ def test_get_job_document_with_document():
|
|||||||
document=json.dumps(job_document),
|
document=json.dumps(job_document),
|
||||||
presignedUrlConfig={
|
presignedUrlConfig={
|
||||||
"roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
|
"roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
|
||||||
"expiresInSec": 123
|
"expiresInSec": 123,
|
||||||
},
|
},
|
||||||
targetSelection="CONTINUOUS",
|
targetSelection="CONTINUOUS",
|
||||||
jobExecutionsRolloutConfig={
|
jobExecutionsRolloutConfig={"maximumPerMinute": 10},
|
||||||
"maximumPerMinute": 10
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
job.should.have.key("jobId").which.should.equal(job_id)
|
job.should.have.key("jobId").which.should.equal(job_id)
|
||||||
job.should.have.key("jobArn")
|
job.should.have.key("jobArn")
|
||||||
|
|
||||||
job_document = client.get_job_document(jobId=job_id)
|
job_document = client.get_job_document(jobId=job_id)
|
||||||
job_document.should.have.key("document").which.should.equal("{\"field\": \"value\"}")
|
job_document.should.have.key("document").which.should.equal('{"field": "value"}')
|
||||||
|
|
||||||
|
|
||||||
@mock_iot
|
@mock_iot
|
||||||
@ -1465,9 +1509,7 @@ def test_describe_job_execution():
|
|||||||
thing.should.have.key("thingArn")
|
thing.should.have.key("thingArn")
|
||||||
|
|
||||||
# job document
|
# job document
|
||||||
job_document = {
|
job_document = {"field": "value"}
|
||||||
"field": "value"
|
|
||||||
}
|
|
||||||
|
|
||||||
job = client.create_job(
|
job = client.create_job(
|
||||||
jobId=job_id,
|
jobId=job_id,
|
||||||
@ -1476,12 +1518,10 @@ def test_describe_job_execution():
|
|||||||
description="Description",
|
description="Description",
|
||||||
presignedUrlConfig={
|
presignedUrlConfig={
|
||||||
"roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
|
"roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
|
||||||
"expiresInSec": 123
|
"expiresInSec": 123,
|
||||||
},
|
},
|
||||||
targetSelection="CONTINUOUS",
|
targetSelection="CONTINUOUS",
|
||||||
jobExecutionsRolloutConfig={
|
jobExecutionsRolloutConfig={"maximumPerMinute": 10},
|
||||||
"maximumPerMinute": 10
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
job.should.have.key("jobId").which.should.equal(job_id)
|
job.should.have.key("jobId").which.should.equal(job_id)
|
||||||
@ -1492,29 +1532,51 @@ def test_describe_job_execution():
|
|||||||
job_execution.should.have.key("execution")
|
job_execution.should.have.key("execution")
|
||||||
job_execution["execution"].should.have.key("jobId").which.should.equal(job_id)
|
job_execution["execution"].should.have.key("jobId").which.should.equal(job_id)
|
||||||
job_execution["execution"].should.have.key("status").which.should.equal("QUEUED")
|
job_execution["execution"].should.have.key("status").which.should.equal("QUEUED")
|
||||||
job_execution["execution"].should.have.key("forceCanceled").which.should.equal(False)
|
job_execution["execution"].should.have.key("forceCanceled").which.should.equal(
|
||||||
job_execution["execution"].should.have.key("statusDetails").which.should.equal({"detailsMap": {}})
|
False
|
||||||
job_execution["execution"].should.have.key("thingArn").which.should.equal(thing["thingArn"])
|
)
|
||||||
|
job_execution["execution"].should.have.key("statusDetails").which.should.equal(
|
||||||
|
{"detailsMap": {}}
|
||||||
|
)
|
||||||
|
job_execution["execution"].should.have.key("thingArn").which.should.equal(
|
||||||
|
thing["thingArn"]
|
||||||
|
)
|
||||||
job_execution["execution"].should.have.key("queuedAt")
|
job_execution["execution"].should.have.key("queuedAt")
|
||||||
job_execution["execution"].should.have.key("startedAt")
|
job_execution["execution"].should.have.key("startedAt")
|
||||||
job_execution["execution"].should.have.key("lastUpdatedAt")
|
job_execution["execution"].should.have.key("lastUpdatedAt")
|
||||||
job_execution["execution"].should.have.key("executionNumber").which.should.equal(123)
|
job_execution["execution"].should.have.key("executionNumber").which.should.equal(
|
||||||
|
123
|
||||||
|
)
|
||||||
job_execution["execution"].should.have.key("versionNumber").which.should.equal(123)
|
job_execution["execution"].should.have.key("versionNumber").which.should.equal(123)
|
||||||
job_execution["execution"].should.have.key("approximateSecondsBeforeTimedOut").which.should.equal(123)
|
job_execution["execution"].should.have.key(
|
||||||
|
"approximateSecondsBeforeTimedOut"
|
||||||
|
).which.should.equal(123)
|
||||||
|
|
||||||
job_execution = client.describe_job_execution(jobId=job_id, thingName=name, executionNumber=123)
|
job_execution = client.describe_job_execution(
|
||||||
|
jobId=job_id, thingName=name, executionNumber=123
|
||||||
|
)
|
||||||
job_execution.should.have.key("execution")
|
job_execution.should.have.key("execution")
|
||||||
job_execution["execution"].should.have.key("jobId").which.should.equal(job_id)
|
job_execution["execution"].should.have.key("jobId").which.should.equal(job_id)
|
||||||
job_execution["execution"].should.have.key("status").which.should.equal("QUEUED")
|
job_execution["execution"].should.have.key("status").which.should.equal("QUEUED")
|
||||||
job_execution["execution"].should.have.key("forceCanceled").which.should.equal(False)
|
job_execution["execution"].should.have.key("forceCanceled").which.should.equal(
|
||||||
job_execution["execution"].should.have.key("statusDetails").which.should.equal({"detailsMap": {}})
|
False
|
||||||
job_execution["execution"].should.have.key("thingArn").which.should.equal(thing["thingArn"])
|
)
|
||||||
|
job_execution["execution"].should.have.key("statusDetails").which.should.equal(
|
||||||
|
{"detailsMap": {}}
|
||||||
|
)
|
||||||
|
job_execution["execution"].should.have.key("thingArn").which.should.equal(
|
||||||
|
thing["thingArn"]
|
||||||
|
)
|
||||||
job_execution["execution"].should.have.key("queuedAt")
|
job_execution["execution"].should.have.key("queuedAt")
|
||||||
job_execution["execution"].should.have.key("startedAt")
|
job_execution["execution"].should.have.key("startedAt")
|
||||||
job_execution["execution"].should.have.key("lastUpdatedAt")
|
job_execution["execution"].should.have.key("lastUpdatedAt")
|
||||||
job_execution["execution"].should.have.key("executionNumber").which.should.equal(123)
|
job_execution["execution"].should.have.key("executionNumber").which.should.equal(
|
||||||
|
123
|
||||||
|
)
|
||||||
job_execution["execution"].should.have.key("versionNumber").which.should.equal(123)
|
job_execution["execution"].should.have.key("versionNumber").which.should.equal(123)
|
||||||
job_execution["execution"].should.have.key("approximateSecondsBeforeTimedOut").which.should.equal(123)
|
job_execution["execution"].should.have.key(
|
||||||
|
"approximateSecondsBeforeTimedOut"
|
||||||
|
).which.should.equal(123)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
client.describe_job_execution(jobId=job_id, thingName=name, executionNumber=456)
|
client.describe_job_execution(jobId=job_id, thingName=name, executionNumber=456)
|
||||||
@ -1536,9 +1598,7 @@ def test_cancel_job_execution():
|
|||||||
thing.should.have.key("thingArn")
|
thing.should.have.key("thingArn")
|
||||||
|
|
||||||
# job document
|
# job document
|
||||||
job_document = {
|
job_document = {"field": "value"}
|
||||||
"field": "value"
|
|
||||||
}
|
|
||||||
|
|
||||||
job = client.create_job(
|
job = client.create_job(
|
||||||
jobId=job_id,
|
jobId=job_id,
|
||||||
@ -1547,12 +1607,10 @@ def test_cancel_job_execution():
|
|||||||
description="Description",
|
description="Description",
|
||||||
presignedUrlConfig={
|
presignedUrlConfig={
|
||||||
"roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
|
"roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
|
||||||
"expiresInSec": 123
|
"expiresInSec": 123,
|
||||||
},
|
},
|
||||||
targetSelection="CONTINUOUS",
|
targetSelection="CONTINUOUS",
|
||||||
jobExecutionsRolloutConfig={
|
jobExecutionsRolloutConfig={"maximumPerMinute": 10},
|
||||||
"maximumPerMinute": 10
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
job.should.have.key("jobId").which.should.equal(job_id)
|
job.should.have.key("jobId").which.should.equal(job_id)
|
||||||
@ -1576,9 +1634,7 @@ def test_delete_job_execution():
|
|||||||
thing.should.have.key("thingArn")
|
thing.should.have.key("thingArn")
|
||||||
|
|
||||||
# job document
|
# job document
|
||||||
job_document = {
|
job_document = {"field": "value"}
|
||||||
"field": "value"
|
|
||||||
}
|
|
||||||
|
|
||||||
job = client.create_job(
|
job = client.create_job(
|
||||||
jobId=job_id,
|
jobId=job_id,
|
||||||
@ -1587,12 +1643,10 @@ def test_delete_job_execution():
|
|||||||
description="Description",
|
description="Description",
|
||||||
presignedUrlConfig={
|
presignedUrlConfig={
|
||||||
"roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
|
"roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
|
||||||
"expiresInSec": 123
|
"expiresInSec": 123,
|
||||||
},
|
},
|
||||||
targetSelection="CONTINUOUS",
|
targetSelection="CONTINUOUS",
|
||||||
jobExecutionsRolloutConfig={
|
jobExecutionsRolloutConfig={"maximumPerMinute": 10},
|
||||||
"maximumPerMinute": 10
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
job.should.have.key("jobId").which.should.equal(job_id)
|
job.should.have.key("jobId").which.should.equal(job_id)
|
||||||
@ -1620,9 +1674,7 @@ def test_list_job_executions_for_job():
|
|||||||
thing.should.have.key("thingArn")
|
thing.should.have.key("thingArn")
|
||||||
|
|
||||||
# job document
|
# job document
|
||||||
job_document = {
|
job_document = {"field": "value"}
|
||||||
"field": "value"
|
|
||||||
}
|
|
||||||
|
|
||||||
job = client.create_job(
|
job = client.create_job(
|
||||||
jobId=job_id,
|
jobId=job_id,
|
||||||
@ -1631,12 +1683,10 @@ def test_list_job_executions_for_job():
|
|||||||
description="Description",
|
description="Description",
|
||||||
presignedUrlConfig={
|
presignedUrlConfig={
|
||||||
"roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
|
"roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
|
||||||
"expiresInSec": 123
|
"expiresInSec": 123,
|
||||||
},
|
},
|
||||||
targetSelection="CONTINUOUS",
|
targetSelection="CONTINUOUS",
|
||||||
jobExecutionsRolloutConfig={
|
jobExecutionsRolloutConfig={"maximumPerMinute": 10},
|
||||||
"maximumPerMinute": 10
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
job.should.have.key("jobId").which.should.equal(job_id)
|
job.should.have.key("jobId").which.should.equal(job_id)
|
||||||
@ -1645,7 +1695,9 @@ def test_list_job_executions_for_job():
|
|||||||
|
|
||||||
job_execution = client.list_job_executions_for_job(jobId=job_id)
|
job_execution = client.list_job_executions_for_job(jobId=job_id)
|
||||||
job_execution.should.have.key("executionSummaries")
|
job_execution.should.have.key("executionSummaries")
|
||||||
job_execution["executionSummaries"][0].should.have.key("thingArn").which.should.equal(thing["thingArn"])
|
job_execution["executionSummaries"][0].should.have.key(
|
||||||
|
"thingArn"
|
||||||
|
).which.should.equal(thing["thingArn"])
|
||||||
|
|
||||||
|
|
||||||
@mock_iot
|
@mock_iot
|
||||||
@ -1659,9 +1711,7 @@ def test_list_job_executions_for_thing():
|
|||||||
thing.should.have.key("thingArn")
|
thing.should.have.key("thingArn")
|
||||||
|
|
||||||
# job document
|
# job document
|
||||||
job_document = {
|
job_document = {"field": "value"}
|
||||||
"field": "value"
|
|
||||||
}
|
|
||||||
|
|
||||||
job = client.create_job(
|
job = client.create_job(
|
||||||
jobId=job_id,
|
jobId=job_id,
|
||||||
@ -1670,12 +1720,10 @@ def test_list_job_executions_for_thing():
|
|||||||
description="Description",
|
description="Description",
|
||||||
presignedUrlConfig={
|
presignedUrlConfig={
|
||||||
"roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
|
"roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
|
||||||
"expiresInSec": 123
|
"expiresInSec": 123,
|
||||||
},
|
},
|
||||||
targetSelection="CONTINUOUS",
|
targetSelection="CONTINUOUS",
|
||||||
jobExecutionsRolloutConfig={
|
jobExecutionsRolloutConfig={"maximumPerMinute": 10},
|
||||||
"maximumPerMinute": 10
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
job.should.have.key("jobId").which.should.equal(job_id)
|
job.should.have.key("jobId").which.should.equal(job_id)
|
||||||
@ -1684,5 +1732,6 @@ def test_list_job_executions_for_thing():
|
|||||||
|
|
||||||
job_execution = client.list_job_executions_for_thing(thingName=name)
|
job_execution = client.list_job_executions_for_thing(thingName=name)
|
||||||
job_execution.should.have.key("executionSummaries")
|
job_execution.should.have.key("executionSummaries")
|
||||||
job_execution["executionSummaries"][0].should.have.key("jobId").which.should.equal(job_id)
|
job_execution["executionSummaries"][0].should.have.key("jobId").which.should.equal(
|
||||||
|
job_id
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user