Make batch.utils.lowercase_first_key() recursive (#3124)
* Make batch.utils.lowercase_first_key() recursive * Reformat using black * Add test of recursive lowercase_first_key() * Fix typo in ttest_batch/test_cloud_formation.py
This commit is contained in:
parent
f31f8e08c1
commit
890c3b4954
@ -21,6 +21,14 @@ def lowercase_first_key(some_dict):
|
||||
new_dict = {}
|
||||
for key, value in some_dict.items():
|
||||
new_key = key[0].lower() + key[1:]
|
||||
new_dict[new_key] = value
|
||||
try:
|
||||
if isinstance(value, dict):
|
||||
new_dict[new_key] = lowercase_first_key(value)
|
||||
elif all([isinstance(v, dict) for v in value]):
|
||||
new_dict[new_key] = [lowercase_first_key(v) for v in value]
|
||||
else:
|
||||
new_dict[new_key] = value
|
||||
except TypeError:
|
||||
new_dict[new_key] = value
|
||||
|
||||
return new_dict
|
||||
|
@ -234,6 +234,7 @@ def test_create_job_def_cf():
|
||||
"Vcpus": 2,
|
||||
"Memory": 2000,
|
||||
"Command": ["echo", "Hello world"],
|
||||
"LinuxParameters": {"Devices": [{"HostPath": "test-path"}]},
|
||||
},
|
||||
"RetryStrategy": {"Attempts": 1},
|
||||
},
|
||||
@ -262,3 +263,17 @@ def test_create_job_def_cf():
|
||||
job_def_resource["PhysicalResourceId"].startswith("arn:aws:batch:")
|
||||
job_def_resource["PhysicalResourceId"].should.contain("test_stack-JobDef")
|
||||
job_def_resource["PhysicalResourceId"].should.contain("job-definition/")
|
||||
|
||||
# Test the linux parameter device host path
|
||||
# This ensures that batch is parsing the parameter dictionaries
|
||||
# correctly by recursively converting the first character of all
|
||||
# dict keys to lowercase.
|
||||
batch_conn = boto3.client("batch", DEFAULT_REGION)
|
||||
response = batch_conn.describe_job_definitions(
|
||||
jobDefinitions=[job_def_resource["PhysicalResourceId"]]
|
||||
)
|
||||
job_def_linux_device_host_path = response.get("jobDefinitions")[0][
|
||||
"containerProperties"
|
||||
]["linuxParameters"]["devices"][0]["hostPath"]
|
||||
|
||||
job_def_linux_device_host_path.should.equal("test-path")
|
||||
|
Loading…
Reference in New Issue
Block a user