implemented get_job_document
for AWS IoT
This commit is contained in:
parent
88596518f5
commit
c49a8387bd
File diff suppressed because it is too large
Load Diff
@ -610,6 +610,9 @@ class IoTBackend(BaseBackend):
|
||||
def describe_job(self, job_id):
|
||||
return self.jobs[job_id]
|
||||
|
||||
def get_job_document(self, job_id):
|
||||
return self.jobs[job_id]
|
||||
|
||||
|
||||
available_regions = boto3.session.Session().get_available_regions("iot")
|
||||
iot_backends = {region: IoTBackend(region) for region in available_regions}
|
||||
|
@ -149,6 +149,16 @@ class IoTResponse(BaseResponse):
|
||||
targetSelection=job.target_selection
|
||||
)))
|
||||
|
||||
def get_job_document(self):
|
||||
job = self.iot_backend.get_job_document(job_id=self._get_param("jobId"))
|
||||
|
||||
if job.document is not None:
|
||||
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': ''})
|
||||
|
||||
def create_keys_and_certificate(self):
|
||||
set_as_active = self._get_bool_param("setAsActive")
|
||||
cert, key_pair = self.iot_backend.create_keys_and_certificate(
|
||||
|
@ -1,7 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import json
|
||||
import sure # noqa
|
||||
|
||||
import boto3
|
||||
|
||||
from moto import mock_iot
|
||||
@ -681,3 +681,65 @@ def test_describe_job_1():
|
||||
"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
|
||||
def test_get_job_document_with_document_source():
|
||||
client = boto3.client('iot', region_name='eu-west-1')
|
||||
name = "my-thing"
|
||||
job_id = "TestJob"
|
||||
# thing
|
||||
thing = client.create_thing(thingName=name)
|
||||
thing.should.have.key('thingName').which.should.equal(name)
|
||||
thing.should.have.key('thingArn')
|
||||
|
||||
job = client.create_job(
|
||||
jobId=job_id,
|
||||
targets=[thing["thingArn"]],
|
||||
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
|
||||
},
|
||||
targetSelection="CONTINUOUS",
|
||||
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('')
|
||||
|
||||
|
||||
@mock_iot
|
||||
def test_get_job_document_with_document():
|
||||
client = boto3.client('iot', region_name='eu-west-1')
|
||||
name = "my-thing"
|
||||
job_id = "TestJob1"
|
||||
# thing
|
||||
thing = client.create_thing(thingName=name)
|
||||
thing.should.have.key('thingName').which.should.equal(name)
|
||||
thing.should.have.key('thingArn')
|
||||
|
||||
job = client.create_job(
|
||||
jobId=job_id,
|
||||
targets=[thing["thingArn"]],
|
||||
document=json.dumps({'foo': 'bar'}),
|
||||
presignedUrlConfig={
|
||||
'roleArn': 'arn:aws:iam::1:role/service-role/iot_job_role',
|
||||
'expiresInSec': 123
|
||||
},
|
||||
targetSelection="CONTINUOUS",
|
||||
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('')
|
||||
|
Loading…
Reference in New Issue
Block a user