fix linting errors
This commit is contained in:
		
							parent
							
								
									a6aa0f6dbf
								
							
						
					
					
						commit
						ed8d5edb50
					
				@ -27,7 +27,7 @@ class InvalidStateTransitionException(IoTClientError):
 | 
			
		||||
        self.code = 409
 | 
			
		||||
        super(InvalidStateTransitionException, self).__init__(
 | 
			
		||||
            "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,
 | 
			
		||||
    InvalidRequestException,
 | 
			
		||||
    InvalidStateTransitionException,
 | 
			
		||||
    VersionConflictException
 | 
			
		||||
    VersionConflictException,
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -187,7 +187,7 @@ class FakePolicy(BaseModel):
 | 
			
		||||
            "policyName": self.name,
 | 
			
		||||
            "policyArn": self.arn,
 | 
			
		||||
            "policyDocument": self.document,
 | 
			
		||||
            "defaultVersionId": self.default_version_id
 | 
			
		||||
            "defaultVersionId": self.default_version_id,
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    def to_dict_at_creation(self):
 | 
			
		||||
@ -195,7 +195,7 @@ class FakePolicy(BaseModel):
 | 
			
		||||
            "policyName": self.name,
 | 
			
		||||
            "policyArn": self.arn,
 | 
			
		||||
            "policyDocument": self.document,
 | 
			
		||||
            "policyVersionId": self.default_version_id
 | 
			
		||||
            "policyVersionId": self.default_version_id,
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    def to_dict(self):
 | 
			
		||||
@ -203,12 +203,7 @@ class FakePolicy(BaseModel):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
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.arn = "arn:aws:iot:%s:1:policy/%s" % (region_name, policy_name)
 | 
			
		||||
        self.document = document or {}
 | 
			
		||||
@ -227,7 +222,7 @@ class FakePolicyVersion(object):
 | 
			
		||||
            "isDefaultVersion": self.is_default,
 | 
			
		||||
            "creationDate": self.create_datetime,
 | 
			
		||||
            "lastModifiedDate": self.last_modified_datetime,
 | 
			
		||||
            "generationId": self.version_id
 | 
			
		||||
            "generationId": self.version_id,
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    def to_dict_at_creation(self):
 | 
			
		||||
@ -235,7 +230,7 @@ class FakePolicyVersion(object):
 | 
			
		||||
            "policyArn": self.arn,
 | 
			
		||||
            "policyDocument": self.document,
 | 
			
		||||
            "policyVersionId": self.version_id,
 | 
			
		||||
            "isDefaultVersion": self.is_default
 | 
			
		||||
            "isDefaultVersion": self.is_default,
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    def to_dict(self):
 | 
			
		||||
@ -314,7 +309,7 @@ class FakeJob(BaseModel):
 | 
			
		||||
            "jobProcessDetails": self.job_process_details,
 | 
			
		||||
            "documentParameters": self.document_parameters,
 | 
			
		||||
            "document": self.document,
 | 
			
		||||
            "documentSource": self.document_source
 | 
			
		||||
            "documentSource": self.document_source,
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return obj
 | 
			
		||||
@ -326,8 +321,14 @@ class FakeJob(BaseModel):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class FakeJobExecution(BaseModel):
 | 
			
		||||
 | 
			
		||||
    def __init__(self, job_id, thing_arn, status="QUEUED", force_canceled=False, status_details_map={}):
 | 
			
		||||
    def __init__(
 | 
			
		||||
        self,
 | 
			
		||||
        job_id,
 | 
			
		||||
        thing_arn,
 | 
			
		||||
        status="QUEUED",
 | 
			
		||||
        force_canceled=False,
 | 
			
		||||
        status_details_map={},
 | 
			
		||||
    ):
 | 
			
		||||
        self.job_id = job_id
 | 
			
		||||
        self.status = status  # IN_PROGRESS | CANCELED | COMPLETED
 | 
			
		||||
        self.force_canceled = force_canceled
 | 
			
		||||
@ -352,7 +353,7 @@ class FakeJobExecution(BaseModel):
 | 
			
		||||
            "lastUpdatedAt": self.last_updated_at,
 | 
			
		||||
            "executionNumber": self.execution_number,
 | 
			
		||||
            "versionNumber": self.version_number,
 | 
			
		||||
            "approximateSecondsBeforeTimedOut": self.approximate_seconds_before_time_out
 | 
			
		||||
            "approximateSecondsBeforeTimedOut": self.approximate_seconds_before_time_out,
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return obj
 | 
			
		||||
@ -367,7 +368,7 @@ class FakeJobExecution(BaseModel):
 | 
			
		||||
                "startedAt": self.started_at,
 | 
			
		||||
                "lastUpdatedAt": self.last_updated_at,
 | 
			
		||||
                "executionNumber": self.execution_number,
 | 
			
		||||
            }
 | 
			
		||||
            },
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return obj
 | 
			
		||||
@ -684,7 +685,9 @@ class IoTBackend(BaseBackend):
 | 
			
		||||
        policy = self.get_policy(policy_name)
 | 
			
		||||
        if not policy:
 | 
			
		||||
            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)
 | 
			
		||||
        version.version_id = "{0}".format(len(policy.versions))
 | 
			
		||||
        if set_as_default:
 | 
			
		||||
@ -724,7 +727,8 @@ class IoTBackend(BaseBackend):
 | 
			
		||||
            raise ResourceNotFoundException()
 | 
			
		||||
        if version_id == policy.default_version_id:
 | 
			
		||||
            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):
 | 
			
		||||
            if v.version_id == version_id:
 | 
			
		||||
                del policy.versions[i]
 | 
			
		||||
@ -1017,7 +1021,15 @@ class IoTBackend(BaseBackend):
 | 
			
		||||
    def get_job_document(self, 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
 | 
			
		||||
        all_jobs = [_.to_dict() for _ in self.jobs.values()]
 | 
			
		||||
        filtered_jobs = all_jobs
 | 
			
		||||
@ -1028,7 +1040,11 @@ class IoTBackend(BaseBackend):
 | 
			
		||||
        else:
 | 
			
		||||
            token = int(token)
 | 
			
		||||
            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
 | 
			
		||||
 | 
			
		||||
@ -1038,19 +1054,25 @@ class IoTBackend(BaseBackend):
 | 
			
		||||
        except KeyError:
 | 
			
		||||
            raise ResourceNotFoundException()
 | 
			
		||||
 | 
			
		||||
        if job_execution is None or \
 | 
			
		||||
                (execution_number is not None and job_execution.execution_number != execution_number):
 | 
			
		||||
        if job_execution is None or (
 | 
			
		||||
            execution_number is not None
 | 
			
		||||
            and job_execution.execution_number != execution_number
 | 
			
		||||
        ):
 | 
			
		||||
            raise ResourceNotFoundException()
 | 
			
		||||
 | 
			
		||||
        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)]
 | 
			
		||||
 | 
			
		||||
        if job_execution is None:
 | 
			
		||||
            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)
 | 
			
		||||
 | 
			
		||||
        if job_execution.status == "IN_PROGRESS" and force:
 | 
			
		||||
@ -1076,11 +1098,19 @@ class IoTBackend(BaseBackend):
 | 
			
		||||
            raise InvalidStateTransitionException()
 | 
			
		||||
 | 
			
		||||
    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:
 | 
			
		||||
            job_executions = list(filter(lambda elem:
 | 
			
		||||
                                         status in elem["status"] and elem["status"] == status, job_executions))
 | 
			
		||||
            job_executions = list(
 | 
			
		||||
                filter(
 | 
			
		||||
                    lambda elem: status in elem["status"] and elem["status"] == status,
 | 
			
		||||
                    job_executions,
 | 
			
		||||
                )
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
        token = next_token
 | 
			
		||||
        if token is None:
 | 
			
		||||
@ -1089,16 +1119,30 @@ class IoTBackend(BaseBackend):
 | 
			
		||||
        else:
 | 
			
		||||
            token = int(token)
 | 
			
		||||
            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
 | 
			
		||||
 | 
			
		||||
    def list_job_executions_for_thing(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]
 | 
			
		||||
    def list_job_executions_for_thing(
 | 
			
		||||
        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:
 | 
			
		||||
            job_executions = list(filter(lambda elem:
 | 
			
		||||
                                         status in elem["status"] and elem["status"] == status, job_executions))
 | 
			
		||||
            job_executions = list(
 | 
			
		||||
                filter(
 | 
			
		||||
                    lambda elem: status in elem["status"] and elem["status"] == status,
 | 
			
		||||
                    job_executions,
 | 
			
		||||
                )
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
        token = next_token
 | 
			
		||||
        if token is None:
 | 
			
		||||
@ -1107,7 +1151,11 @@ class IoTBackend(BaseBackend):
 | 
			
		||||
        else:
 | 
			
		||||
            token = int(token)
 | 
			
		||||
            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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -133,7 +133,8 @@ class IoTResponse(BaseResponse):
 | 
			
		||||
 | 
			
		||||
    def describe_job(self):
 | 
			
		||||
        job = self.iot_backend.describe_job(job_id=self._get_param("jobId"))
 | 
			
		||||
        return json.dumps(dict(
 | 
			
		||||
        return json.dumps(
 | 
			
		||||
            dict(
 | 
			
		||||
                documentSource=job.document_source,
 | 
			
		||||
                job=dict(
 | 
			
		||||
                    comment=job.comment,
 | 
			
		||||
@ -151,15 +152,16 @@ class IoTResponse(BaseResponse):
 | 
			
		||||
                    presignedUrlConfig=job.presigned_url_config,
 | 
			
		||||
                    status=job.status,
 | 
			
		||||
                    targets=job.targets,
 | 
			
		||||
                targetSelection=job.target_selection
 | 
			
		||||
            )))
 | 
			
		||||
                    targetSelection=job.target_selection,
 | 
			
		||||
                ),
 | 
			
		||||
            )
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def delete_job(self):
 | 
			
		||||
        job_id = self._get_param("jobId")
 | 
			
		||||
        force = self._get_bool_param("force")
 | 
			
		||||
 | 
			
		||||
        self.iot_backend.delete_job(job_id=job_id,
 | 
			
		||||
                                    force=force)
 | 
			
		||||
        self.iot_backend.delete_job(job_id=job_id, force=force)
 | 
			
		||||
 | 
			
		||||
        return json.dumps(dict())
 | 
			
		||||
 | 
			
		||||
@ -169,10 +171,9 @@ class IoTResponse(BaseResponse):
 | 
			
		||||
        comment = self._get_param("comment")
 | 
			
		||||
        force = self._get_bool_param("force")
 | 
			
		||||
 | 
			
		||||
        job = self.iot_backend.cancel_job(job_id=job_id,
 | 
			
		||||
                                          reason_code=reason_code,
 | 
			
		||||
                                          comment=comment,
 | 
			
		||||
                                          force=force)
 | 
			
		||||
        job = self.iot_backend.cancel_job(
 | 
			
		||||
            job_id=job_id, reason_code=reason_code, comment=comment, force=force
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        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"))
 | 
			
		||||
 | 
			
		||||
        if job.document is not None:
 | 
			
		||||
            return json.dumps({'document': job.document})
 | 
			
		||||
            return json.dumps({"document": job.document})
 | 
			
		||||
        else:
 | 
			
		||||
            # job.document_source is not None:
 | 
			
		||||
            # 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):
 | 
			
		||||
        status = self._get_param("status"),
 | 
			
		||||
        target_selection = self._get_param("targetSelection"),
 | 
			
		||||
        max_results = self._get_int_param("maxResults", 50)  # not the default, but makes testing easier
 | 
			
		||||
        status = (self._get_param("status"),)
 | 
			
		||||
        target_selection = (self._get_param("targetSelection"),)
 | 
			
		||||
        max_results = self._get_int_param(
 | 
			
		||||
            "maxResults", 50
 | 
			
		||||
        )  # not the default, but makes testing easier
 | 
			
		||||
        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")
 | 
			
		||||
        jobs, next_token = self.iot_backend.list_jobs(status=status,
 | 
			
		||||
        jobs, next_token = self.iot_backend.list_jobs(
 | 
			
		||||
            status=status,
 | 
			
		||||
            target_selection=target_selection,
 | 
			
		||||
            max_results=max_results,
 | 
			
		||||
            token=previous_next_token,
 | 
			
		||||
            thing_group_name=thing_group_name,
 | 
			
		||||
                                                      thing_group_id=thing_group_id)
 | 
			
		||||
            thing_group_id=thing_group_id,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        return json.dumps(dict(jobs=jobs, nextToken=next_token))
 | 
			
		||||
 | 
			
		||||
@ -206,9 +211,9 @@ class IoTResponse(BaseResponse):
 | 
			
		||||
        job_id = self._get_param("jobId")
 | 
			
		||||
        thing_name = self._get_param("thingName")
 | 
			
		||||
        execution_number = self._get_int_param("executionNumber")
 | 
			
		||||
        job_execution = self.iot_backend.describe_job_execution(job_id=job_id,
 | 
			
		||||
                                                                thing_name=thing_name,
 | 
			
		||||
                                                                execution_number=execution_number)
 | 
			
		||||
        job_execution = self.iot_backend.describe_job_execution(
 | 
			
		||||
            job_id=job_id, thing_name=thing_name, execution_number=execution_number
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        return json.dumps(dict(execution=job_execution.to_get_dict()))
 | 
			
		||||
 | 
			
		||||
@ -219,11 +224,13 @@ class IoTResponse(BaseResponse):
 | 
			
		||||
        expected_version = self._get_int_param("expectedVersion")
 | 
			
		||||
        status_details = self._get_param("statusDetails")
 | 
			
		||||
 | 
			
		||||
        self.iot_backend.cancel_job_execution(job_id=job_id,
 | 
			
		||||
        self.iot_backend.cancel_job_execution(
 | 
			
		||||
            job_id=job_id,
 | 
			
		||||
            thing_name=thing_name,
 | 
			
		||||
            force=force,
 | 
			
		||||
            expected_version=expected_version,
 | 
			
		||||
                                              status_details=status_details)
 | 
			
		||||
            status_details=status_details,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        return json.dumps(dict())
 | 
			
		||||
 | 
			
		||||
@ -233,34 +240,41 @@ class IoTResponse(BaseResponse):
 | 
			
		||||
        execution_number = self._get_int_param("executionNumber")
 | 
			
		||||
        force = self._get_bool_param("force")
 | 
			
		||||
 | 
			
		||||
        self.iot_backend.delete_job_execution(job_id=job_id,
 | 
			
		||||
        self.iot_backend.delete_job_execution(
 | 
			
		||||
            job_id=job_id,
 | 
			
		||||
            thing_name=thing_name,
 | 
			
		||||
            execution_number=execution_number,
 | 
			
		||||
                                              force=force)
 | 
			
		||||
            force=force,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        return json.dumps(dict())
 | 
			
		||||
 | 
			
		||||
    def list_job_executions_for_job(self):
 | 
			
		||||
        job_id = self._get_param("jobId")
 | 
			
		||||
        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")
 | 
			
		||||
        job_executions, next_token = self.iot_backend.list_job_executions_for_job(job_id=job_id,
 | 
			
		||||
                                                                                  status=status,
 | 
			
		||||
                                                                                  max_results=max_results,
 | 
			
		||||
                                                                                  next_token=next_token)
 | 
			
		||||
        job_executions, next_token = self.iot_backend.list_job_executions_for_job(
 | 
			
		||||
            job_id=job_id, status=status, max_results=max_results, next_token=next_token
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        return json.dumps(dict(executionSummaries=job_executions, nextToken=next_token))
 | 
			
		||||
 | 
			
		||||
    def list_job_executions_for_thing(self):
 | 
			
		||||
        thing_name = self._get_param("thingName")
 | 
			
		||||
        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")
 | 
			
		||||
        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(
 | 
			
		||||
            thing_name=thing_name,
 | 
			
		||||
            status=status,
 | 
			
		||||
            max_results=max_results,
 | 
			
		||||
                                                                                    next_token=next_token)
 | 
			
		||||
            next_token=next_token,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        return json.dumps(dict(executionSummaries=job_executions, nextToken=next_token))
 | 
			
		||||
 | 
			
		||||
@ -352,35 +366,39 @@ class IoTResponse(BaseResponse):
 | 
			
		||||
        return json.dumps(dict())
 | 
			
		||||
 | 
			
		||||
    def create_policy_version(self):
 | 
			
		||||
        policy_name = self._get_param('policyName')
 | 
			
		||||
        policy_document = self._get_param('policyDocument')
 | 
			
		||||
        set_as_default = self._get_bool_param('setAsDefault')
 | 
			
		||||
        policy_version = self.iot_backend.create_policy_version(policy_name, policy_document, set_as_default)
 | 
			
		||||
        policy_name = self._get_param("policyName")
 | 
			
		||||
        policy_document = self._get_param("policyDocument")
 | 
			
		||||
        set_as_default = self._get_bool_param("setAsDefault")
 | 
			
		||||
        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()))
 | 
			
		||||
 | 
			
		||||
    def set_default_policy_version(self):
 | 
			
		||||
        policy_name = self._get_param('policyName')
 | 
			
		||||
        version_id = self._get_param('policyVersionId')
 | 
			
		||||
        policy_name = self._get_param("policyName")
 | 
			
		||||
        version_id = self._get_param("policyVersionId")
 | 
			
		||||
        self.iot_backend.set_default_policy_version(policy_name, version_id)
 | 
			
		||||
 | 
			
		||||
        return json.dumps(dict())
 | 
			
		||||
 | 
			
		||||
    def get_policy_version(self):
 | 
			
		||||
        policy_name = self._get_param('policyName')
 | 
			
		||||
        version_id = self._get_param('policyVersionId')
 | 
			
		||||
        policy_name = self._get_param("policyName")
 | 
			
		||||
        version_id = self._get_param("policyVersionId")
 | 
			
		||||
        policy_version = self.iot_backend.get_policy_version(policy_name, version_id)
 | 
			
		||||
        return json.dumps(dict(policy_version.to_get_dict()))
 | 
			
		||||
 | 
			
		||||
    def list_policy_versions(self):
 | 
			
		||||
        policy_name = self._get_param('policyName')
 | 
			
		||||
        policiy_versions = self.iot_backend.list_policy_versions(policy_name=policy_name)
 | 
			
		||||
        policy_name = self._get_param("policyName")
 | 
			
		||||
        policiy_versions = self.iot_backend.list_policy_versions(
 | 
			
		||||
            policy_name=policy_name
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        return json.dumps(dict(policyVersions=[_.to_dict() for _ in policiy_versions]))
 | 
			
		||||
 | 
			
		||||
    def delete_policy_version(self):
 | 
			
		||||
        policy_name = self._get_param('policyName')
 | 
			
		||||
        version_id = self._get_param('policyVersionId')
 | 
			
		||||
        policy_name = self._get_param("policyName")
 | 
			
		||||
        version_id = self._get_param("policyVersionId")
 | 
			
		||||
        self.iot_backend.delete_policy_version(policy_name, version_id)
 | 
			
		||||
 | 
			
		||||
        return json.dumps(dict())
 | 
			
		||||
@ -392,15 +410,15 @@ class IoTResponse(BaseResponse):
 | 
			
		||||
        return json.dumps(dict())
 | 
			
		||||
 | 
			
		||||
    def list_attached_policies(self):
 | 
			
		||||
        principal = unquote(self._get_param('target'))
 | 
			
		||||
        principal = unquote(self._get_param("target"))
 | 
			
		||||
        # marker = self._get_param("marker")
 | 
			
		||||
        # page_size = self._get_int_param("pageSize")
 | 
			
		||||
        policies = self.iot_backend.list_attached_policies(
 | 
			
		||||
            target=principal
 | 
			
		||||
        )
 | 
			
		||||
        policies = self.iot_backend.list_attached_policies(target=principal)
 | 
			
		||||
        # TODO: implement pagination in the future
 | 
			
		||||
        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):
 | 
			
		||||
        policy_name = self._get_param("policyName")
 | 
			
		||||
 | 
			
		||||
@ -8,6 +8,7 @@ from moto import mock_iot
 | 
			
		||||
from botocore.exceptions import ClientError
 | 
			
		||||
from nose.tools import assert_raises
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@mock_iot
 | 
			
		||||
def test_attach_policy():
 | 
			
		||||
    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("policyArn").which.should_not.be.none
 | 
			
		||||
    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"}),
 | 
			
		||||
                                           setAsDefault=True)
 | 
			
		||||
    policy1 = client.create_policy_version(
 | 
			
		||||
        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("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("isDefaultVersion").which.should.equal(True)
 | 
			
		||||
 | 
			
		||||
    policy2 = client.create_policy_version(policyName=policy_name, policyDocument=json.dumps({"version": "version_2"}),
 | 
			
		||||
                                           setAsDefault=False)
 | 
			
		||||
    policy2 = client.create_policy_version(
 | 
			
		||||
        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("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("isDefaultVersion").which.should.equal(False)
 | 
			
		||||
 | 
			
		||||
    policy = client.get_policy(policyName=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("policyDocument").which.should.equal(json.dumps({"version": "version_1"}))
 | 
			
		||||
    policy.should.have.key("defaultVersionId").which.should.equal(policy1["policyVersionId"])
 | 
			
		||||
    policy.should.have.key("policyDocument").which.should.equal(
 | 
			
		||||
        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.should.have.key("policyVersions").which.should.have.length_of(3)
 | 
			
		||||
    list(map(lambda item: item["isDefaultVersion"], policy_versions["policyVersions"])).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"])
 | 
			
		||||
    list(
 | 
			
		||||
        map(lambda item: item["isDefaultVersion"], policy_versions["policyVersions"])
 | 
			
		||||
    ).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.should.have.key("policyName").which.should.equal(policy_name)
 | 
			
		||||
    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("defaultVersionId").which.should.equal(policy1["policyVersionId"])
 | 
			
		||||
    policy.should.have.key("policyDocument").which.should.equal(
 | 
			
		||||
        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.should.have.key("policyVersions").which.should.have.length_of(3)
 | 
			
		||||
    list(map(lambda item: item["isDefaultVersion"], policy_versions["policyVersions"])).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"])
 | 
			
		||||
    list(
 | 
			
		||||
        map(lambda item: item["isDefaultVersion"], policy_versions["policyVersions"])
 | 
			
		||||
    ).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.should.have.key("policyName").which.should.equal(policy_name)
 | 
			
		||||
    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("defaultVersionId").which.should.equal(policy2["policyVersionId"])
 | 
			
		||||
    policy.should.have.key("policyDocument").which.should.equal(
 | 
			
		||||
        json.dumps({"version": "version_2"})
 | 
			
		||||
    )
 | 
			
		||||
    policy.should.have.key("defaultVersionId").which.should.equal(
 | 
			
		||||
        policy2["policyVersionId"]
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    client.delete_policy_version(policyName=policy_name, policyVersionId="1")
 | 
			
		||||
    policy_versions = client.list_policy_versions(policyName=policy_name)
 | 
			
		||||
    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.should.have.key("policyVersions").which.should.have.length_of(1)
 | 
			
		||||
 | 
			
		||||
    # should fail as it"s the default policy. Should use delete_policy instead
 | 
			
		||||
    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"
 | 
			
		||||
    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
 | 
			
		||||
@ -1159,9 +1204,7 @@ def test_list_jobs():
 | 
			
		||||
    thing.should.have.key("thingArn")
 | 
			
		||||
 | 
			
		||||
    # job document
 | 
			
		||||
    job_document = {
 | 
			
		||||
        "field": "value"
 | 
			
		||||
    }
 | 
			
		||||
    job_document = {"field": "value"}
 | 
			
		||||
 | 
			
		||||
    job1 = client.create_job(
 | 
			
		||||
        jobId=job_id,
 | 
			
		||||
@ -1170,12 +1213,10 @@ def test_list_jobs():
 | 
			
		||||
        description="Description",
 | 
			
		||||
        presignedUrlConfig={
 | 
			
		||||
            "roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
 | 
			
		||||
            "expiresInSec": 123
 | 
			
		||||
            "expiresInSec": 123,
 | 
			
		||||
        },
 | 
			
		||||
        targetSelection="CONTINUOUS",
 | 
			
		||||
        jobExecutionsRolloutConfig={
 | 
			
		||||
            "maximumPerMinute": 10
 | 
			
		||||
        }
 | 
			
		||||
        jobExecutionsRolloutConfig={"maximumPerMinute": 10},
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    job1.should.have.key("jobId").which.should.equal(job_id)
 | 
			
		||||
@ -1189,12 +1230,10 @@ def test_list_jobs():
 | 
			
		||||
        description="Description",
 | 
			
		||||
        presignedUrlConfig={
 | 
			
		||||
            "roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
 | 
			
		||||
            "expiresInSec": 123
 | 
			
		||||
            "expiresInSec": 123,
 | 
			
		||||
        },
 | 
			
		||||
        targetSelection="CONTINUOUS",
 | 
			
		||||
        jobExecutionsRolloutConfig={
 | 
			
		||||
            "maximumPerMinute": 10
 | 
			
		||||
        }
 | 
			
		||||
        jobExecutionsRolloutConfig={"maximumPerMinute": 10},
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    job2.should.have.key("jobId").which.should.equal(job_id + "1")
 | 
			
		||||
@ -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("createdAt")
 | 
			
		||||
    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").which.should.have.key(
 | 
			
		||||
        "roleArn").which.should.equal("arn:aws:iam::1:role/service-role/iot_job_role")
 | 
			
		||||
    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)
 | 
			
		||||
    job.should.have.key("job").which.should.have.key(
 | 
			
		||||
        "presignedUrlConfig"
 | 
			
		||||
    ).which.should.have.key("roleArn").which.should.equal(
 | 
			
		||||
        "arn:aws:iam::1:role/service-role/iot_job_role"
 | 
			
		||||
    )
 | 
			
		||||
    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
 | 
			
		||||
@ -1323,12 +1369,10 @@ def test_delete_job():
 | 
			
		||||
        documentSource="https://s3-eu-west-1.amazonaws.com/bucket-name/job_document.json",
 | 
			
		||||
        presignedUrlConfig={
 | 
			
		||||
            "roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
 | 
			
		||||
            "expiresInSec": 123
 | 
			
		||||
            "expiresInSec": 123,
 | 
			
		||||
        },
 | 
			
		||||
        targetSelection="CONTINUOUS",
 | 
			
		||||
        jobExecutionsRolloutConfig={
 | 
			
		||||
            "maximumPerMinute": 10
 | 
			
		||||
        }
 | 
			
		||||
        jobExecutionsRolloutConfig={"maximumPerMinute": 10},
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    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",
 | 
			
		||||
        presignedUrlConfig={
 | 
			
		||||
            "roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
 | 
			
		||||
            "expiresInSec": 123
 | 
			
		||||
            "expiresInSec": 123,
 | 
			
		||||
        },
 | 
			
		||||
        targetSelection="CONTINUOUS",
 | 
			
		||||
        jobExecutionsRolloutConfig={
 | 
			
		||||
            "maximumPerMinute": 10
 | 
			
		||||
        }
 | 
			
		||||
        jobExecutionsRolloutConfig={"maximumPerMinute": 10},
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    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.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("status").which.should.equal("CANCELED")
 | 
			
		||||
    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")
 | 
			
		||||
    job.should.have.key("job").which.should.have.key("status").which.should.equal(
 | 
			
		||||
        "CANCELED"
 | 
			
		||||
    )
 | 
			
		||||
    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
 | 
			
		||||
@ -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",
 | 
			
		||||
        presignedUrlConfig={
 | 
			
		||||
            "roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
 | 
			
		||||
            "expiresInSec": 123
 | 
			
		||||
            "expiresInSec": 123,
 | 
			
		||||
        },
 | 
			
		||||
        targetSelection="CONTINUOUS",
 | 
			
		||||
        jobExecutionsRolloutConfig={
 | 
			
		||||
            "maximumPerMinute": 10
 | 
			
		||||
        }
 | 
			
		||||
        jobExecutionsRolloutConfig={"maximumPerMinute": 10},
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    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")
 | 
			
		||||
 | 
			
		||||
    # job document
 | 
			
		||||
    job_document = {
 | 
			
		||||
        "field": "value"
 | 
			
		||||
    }
 | 
			
		||||
    job_document = {"field": "value"}
 | 
			
		||||
 | 
			
		||||
    job = client.create_job(
 | 
			
		||||
        jobId=job_id,
 | 
			
		||||
@ -1439,19 +1485,17 @@ def test_get_job_document_with_document():
 | 
			
		||||
        document=json.dumps(job_document),
 | 
			
		||||
        presignedUrlConfig={
 | 
			
		||||
            "roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
 | 
			
		||||
            "expiresInSec": 123
 | 
			
		||||
            "expiresInSec": 123,
 | 
			
		||||
        },
 | 
			
		||||
        targetSelection="CONTINUOUS",
 | 
			
		||||
        jobExecutionsRolloutConfig={
 | 
			
		||||
            "maximumPerMinute": 10
 | 
			
		||||
        }
 | 
			
		||||
        jobExecutionsRolloutConfig={"maximumPerMinute": 10},
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    job.should.have.key("jobId").which.should.equal(job_id)
 | 
			
		||||
    job.should.have.key("jobArn")
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
@ -1465,9 +1509,7 @@ def test_describe_job_execution():
 | 
			
		||||
    thing.should.have.key("thingArn")
 | 
			
		||||
 | 
			
		||||
    # job document
 | 
			
		||||
    job_document = {
 | 
			
		||||
        "field": "value"
 | 
			
		||||
    }
 | 
			
		||||
    job_document = {"field": "value"}
 | 
			
		||||
 | 
			
		||||
    job = client.create_job(
 | 
			
		||||
        jobId=job_id,
 | 
			
		||||
@ -1476,12 +1518,10 @@ def test_describe_job_execution():
 | 
			
		||||
        description="Description",
 | 
			
		||||
        presignedUrlConfig={
 | 
			
		||||
            "roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
 | 
			
		||||
            "expiresInSec": 123
 | 
			
		||||
            "expiresInSec": 123,
 | 
			
		||||
        },
 | 
			
		||||
        targetSelection="CONTINUOUS",
 | 
			
		||||
        jobExecutionsRolloutConfig={
 | 
			
		||||
            "maximumPerMinute": 10
 | 
			
		||||
        }
 | 
			
		||||
        jobExecutionsRolloutConfig={"maximumPerMinute": 10},
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    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["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("forceCanceled").which.should.equal(False)
 | 
			
		||||
    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("forceCanceled").which.should.equal(
 | 
			
		||||
        False
 | 
			
		||||
    )
 | 
			
		||||
    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("startedAt")
 | 
			
		||||
    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("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["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("forceCanceled").which.should.equal(False)
 | 
			
		||||
    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("forceCanceled").which.should.equal(
 | 
			
		||||
        False
 | 
			
		||||
    )
 | 
			
		||||
    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("startedAt")
 | 
			
		||||
    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("approximateSecondsBeforeTimedOut").which.should.equal(123)
 | 
			
		||||
    job_execution["execution"].should.have.key(
 | 
			
		||||
        "approximateSecondsBeforeTimedOut"
 | 
			
		||||
    ).which.should.equal(123)
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
        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")
 | 
			
		||||
 | 
			
		||||
    # job document
 | 
			
		||||
    job_document = {
 | 
			
		||||
        "field": "value"
 | 
			
		||||
    }
 | 
			
		||||
    job_document = {"field": "value"}
 | 
			
		||||
 | 
			
		||||
    job = client.create_job(
 | 
			
		||||
        jobId=job_id,
 | 
			
		||||
@ -1547,12 +1607,10 @@ def test_cancel_job_execution():
 | 
			
		||||
        description="Description",
 | 
			
		||||
        presignedUrlConfig={
 | 
			
		||||
            "roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
 | 
			
		||||
            "expiresInSec": 123
 | 
			
		||||
            "expiresInSec": 123,
 | 
			
		||||
        },
 | 
			
		||||
        targetSelection="CONTINUOUS",
 | 
			
		||||
        jobExecutionsRolloutConfig={
 | 
			
		||||
            "maximumPerMinute": 10
 | 
			
		||||
        }
 | 
			
		||||
        jobExecutionsRolloutConfig={"maximumPerMinute": 10},
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    job.should.have.key("jobId").which.should.equal(job_id)
 | 
			
		||||
@ -1576,9 +1634,7 @@ def test_delete_job_execution():
 | 
			
		||||
    thing.should.have.key("thingArn")
 | 
			
		||||
 | 
			
		||||
    # job document
 | 
			
		||||
    job_document = {
 | 
			
		||||
        "field": "value"
 | 
			
		||||
    }
 | 
			
		||||
    job_document = {"field": "value"}
 | 
			
		||||
 | 
			
		||||
    job = client.create_job(
 | 
			
		||||
        jobId=job_id,
 | 
			
		||||
@ -1587,12 +1643,10 @@ def test_delete_job_execution():
 | 
			
		||||
        description="Description",
 | 
			
		||||
        presignedUrlConfig={
 | 
			
		||||
            "roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
 | 
			
		||||
            "expiresInSec": 123
 | 
			
		||||
            "expiresInSec": 123,
 | 
			
		||||
        },
 | 
			
		||||
        targetSelection="CONTINUOUS",
 | 
			
		||||
        jobExecutionsRolloutConfig={
 | 
			
		||||
            "maximumPerMinute": 10
 | 
			
		||||
        }
 | 
			
		||||
        jobExecutionsRolloutConfig={"maximumPerMinute": 10},
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    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")
 | 
			
		||||
 | 
			
		||||
    # job document
 | 
			
		||||
    job_document = {
 | 
			
		||||
        "field": "value"
 | 
			
		||||
    }
 | 
			
		||||
    job_document = {"field": "value"}
 | 
			
		||||
 | 
			
		||||
    job = client.create_job(
 | 
			
		||||
        jobId=job_id,
 | 
			
		||||
@ -1631,12 +1683,10 @@ def test_list_job_executions_for_job():
 | 
			
		||||
        description="Description",
 | 
			
		||||
        presignedUrlConfig={
 | 
			
		||||
            "roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
 | 
			
		||||
            "expiresInSec": 123
 | 
			
		||||
            "expiresInSec": 123,
 | 
			
		||||
        },
 | 
			
		||||
        targetSelection="CONTINUOUS",
 | 
			
		||||
        jobExecutionsRolloutConfig={
 | 
			
		||||
            "maximumPerMinute": 10
 | 
			
		||||
        }
 | 
			
		||||
        jobExecutionsRolloutConfig={"maximumPerMinute": 10},
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    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.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
 | 
			
		||||
@ -1659,9 +1711,7 @@ def test_list_job_executions_for_thing():
 | 
			
		||||
    thing.should.have.key("thingArn")
 | 
			
		||||
 | 
			
		||||
    # job document
 | 
			
		||||
    job_document = {
 | 
			
		||||
        "field": "value"
 | 
			
		||||
    }
 | 
			
		||||
    job_document = {"field": "value"}
 | 
			
		||||
 | 
			
		||||
    job = client.create_job(
 | 
			
		||||
        jobId=job_id,
 | 
			
		||||
@ -1670,12 +1720,10 @@ def test_list_job_executions_for_thing():
 | 
			
		||||
        description="Description",
 | 
			
		||||
        presignedUrlConfig={
 | 
			
		||||
            "roleArn": "arn:aws:iam::1:role/service-role/iot_job_role",
 | 
			
		||||
            "expiresInSec": 123
 | 
			
		||||
            "expiresInSec": 123,
 | 
			
		||||
        },
 | 
			
		||||
        targetSelection="CONTINUOUS",
 | 
			
		||||
        jobExecutionsRolloutConfig={
 | 
			
		||||
            "maximumPerMinute": 10
 | 
			
		||||
        }
 | 
			
		||||
        jobExecutionsRolloutConfig={"maximumPerMinute": 10},
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    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.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…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user