def _mk_json_from_build_parameters(build_params, file_params=None): """ Build parameters must be submitted in a particular format Key-Value pairs would be far too simple, no no! Watch and read on and behold! """ if not isinstance(build_params, dict): raise ValueError("Build parameters must be a dict") build_p = [{"name": k, "value": to_string(v)} for k, v in sorted(build_params.items())] out = {"parameter": build_p} if file_params: file_p = [{"name": k, "file": k} for k in file_params.keys()] out["parameter"].extend(file_p) if len(out["parameter"]) == 1: out["parameter"] = out["parameter"][0] return out
def _mk_json_from_build_parameters(build_params, file_params=None): """ Build parameters must be submitted in a particular format Key-Value pairs would be far too simple, no no! Watch and read on and behold! """ if not isinstance(build_params, dict): raise ValueError('Build parameters must be a dict') build_p = [{'name': k, 'value': to_string(v)} for k, v in sorted(build_params.items())] out = {'parameter': build_p} if file_params: file_p = [{'name': k, 'file': k} for k in file_params.keys()] out['parameter'].extend(file_p) if len(out['parameter']) == 1: out['parameter'] = out['parameter'][0] return out
def test_to_string(): assert isinstance(to_string(5), str) assert isinstance(to_string('string'), str) assert isinstance(to_string(['list', 'of', 'strings']), str) assert isinstance(to_string(u'unicode'), str)