def from_json_data(cls, json_data): agent = nested_object_from_json_data( json_data, 'agent', Agent.from_json_data) build_agent = nested_object_from_json_data( json_data, 'buildAgent', Agent.from_json_data) build_retention = nested_object_from_json_data( json_data, 'buildRetention', BuildRetention.from_json_data) builder = BuildInfo.Builder( version=json_data['version'], name=json_data['name'], number=json_data['number'], type=json_data['type'], started=json_data['started'], duration_millis=json_data['durationMillis'], artifactory_principal=json_data['artifactoryPrincipal'], agent=agent, build_agent=build_agent, build_retention=build_retention ) modules = [Module.from_json_data(x) for x in json_data['modules']] for module in modules: builder.add_module(module) return builder.build()
def null_vs_empty_dependencies_test(): """ Missing artifacts or dependencies should be None not an empty collection. """ module_builder = module_test_helper.create_module_builder( treat_none_as_empty=False) module = module_builder.build() eq_(module.artifacts, None, "artifacts start as None") eq_(module.dependencies, None, "dependencies start as None") #Take the domain object down to wire-level format json_string = json.dumps(module.as_json_data, sort_keys=True, indent=4) #Read the wire-level data back into a domain object json_data_2 = json.loads(json_string) re_hydrated_module = Module.from_json_data(json_data_2) eq_(re_hydrated_module.artifacts, None, "artifacts of None survives round-trip on the wire") eq_(re_hydrated_module.dependencies, None, "artifacts of None survives round-trip on the wire")
def merge_module_info_files(build_info_files, env_info): if env_info.build_agent_name and env_info.build_agent_version: build_agent = Agent( name=env_info.build_agent_name, version=env_info.build_agent_version) else: build_agent = None bi_builder = BuildInfo.Builder( version=env_info.build_version, name=env_info.build_name, number=env_info.build_number, type='GENERIC', started=ISOTime.now().as_str, build_agent=build_agent, artifactory_principal="admin", agent=Agent(name="defend_against_fruit", version="5.2"), build_retention=BuildRetention( count=-1, delete_build_artifacts=False)) if build_info_files: for build_info_file in build_info_files: with open(build_info_file, 'r') as f: bi_builder.add_module(Module.from_json_data( json.loads(f.read()))) return bi_builder.build()
def _read_module_file(module_file): with open(module_file, 'r') as f: module_as_json = f.read() json_data = json.loads(module_as_json) module = Module.from_json_data(json_data) return module