moto/moto/batch/utils.py
Adam Richie-Halford 890c3b4954
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
2020-07-14 11:29:49 +01:00

35 lines
1.1 KiB
Python

from __future__ import unicode_literals
def make_arn_for_compute_env(account_id, name, region_name):
return "arn:aws:batch:{0}:{1}:compute-environment/{2}".format(
region_name, account_id, name
)
def make_arn_for_job_queue(account_id, name, region_name):
return "arn:aws:batch:{0}:{1}:job-queue/{2}".format(region_name, account_id, name)
def make_arn_for_task_def(account_id, name, revision, region_name):
return "arn:aws:batch:{0}:{1}:job-definition/{2}:{3}".format(
region_name, account_id, name, revision
)
def lowercase_first_key(some_dict):
new_dict = {}
for key, value in some_dict.items():
new_key = key[0].lower() + key[1:]
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