Ниже приведен список, который я получаю от источника.
[("!!cm.mymodel.ucm.model.uCConf.UCConf\nrequests:\n- &id001\n dMD:\n cA: {}\n descMap: {en: R Des}\n dispNm: {en: Rq Nm}\n sysAt: {}\n id: R_I_001\n para:\n mt: gSoCamgSoCam\n cT: 1\n cttSceId: ['2']\n aMarB: fl\n maxR: 2\n pR: null\n reqCon: {reqTy: GET}\nuCs:\n- dMD:\n cA: {}\n descMap: {}\n dispNm: {en: gm_tt_SedCa}\n sysAt:\n undefined: {enabled: fl}\n reqCktl:\n - dMD:\n cA: {}\n descMap: {}\n dispNm: {en: Default}\n sysAt: {}\n id: gm_tt_SedCa_0\n reqL:\n - *id001\n slpara: {spPeMin: 1, spPerMx: 100}\n stUCad: GM_19_02-01-2019_236166987\n uCaId: gm_tt_SedCa\nversion: '1.0'\n",), ("!!cm.mymodel.ucm.model.uCConf.UCConf\nrequests:\n- &id001\n dMD:\n cA: {}\n descMap: {en: R Des}\n dispNm: {en: Rq Nm}\n sysAt: {}\n id: R_I_001\n para:\n mt: GTEdRec\n cT: 1\n cttSceId: ['2']\n aMarB: fl\n pR: null\n reqCon: {reqTy: GET}\nuCs:\n- dMD:\n cA: {}\n descMap: {}\n dispNm: {en: ult Picks}\n sysAt: {}\n reqCktl:\n - dMD:\n cA: {}\n descMap: {}\n dispNm: {en: Default}\n sysAt: {}\n id: ult/ult_pi_var_0\n reqL:\n - *id001\n slpara: {spPeMin: 1, spPerMx: 100}\n stUCad: ult/ult_Picks_11-01-2019_1003834703\n uCaId: ult/gm_tt_SedCa\nversion: '1.0'\n",), ("!!cm.mymodel.ucm.model.uCConf.UCConf\nrequests:\n- &id001\n dMD:\n cA: {}\n descMap: {en: R Des}\n dispNm: {en: Rq Nm}\n sysAt: {}\n id: R_I_001\n para:\n mt: GTEdRec\n cT: 1\n cttSceId: ['2']\n aMarB: fl\n campaignIds: gm_tt_SedCa_2018\n maxR: 3\n pR: null\n reqCon: {reqTy: GET}\nuCs:\n- dMD:\n cA: {}\n descMap: {}\n dispNm: {en: Vik Sea 2017}\n sysAt:\n taUsecaseDateRange: {enabled: fl}\n reqCktl:\n - dMD:\n cA: {Cat: Ed}\n descMap: {}\n dispNm: {en: Default}\n sysAt: {}\n id: ult/gm_tt_SedCa8-copy_variant_0\n reqL:\n - *id001\n slpara: {spPeMin: 1, spPerMx: 100}\n stUCad: ult/gm_tt_SedCa_2018-Copy_11-01-2017_1003834668\n uCaId: ult/gm_tt_SedCa-Copy\nversion: '1.0'\n",)]
Мне нужно использовать этот список для создания URL-адресов REST, таких как
URL: http://<url>/<use value in-front of uCaId>
Method:<use value available for reqTy>
Req Body: {
"rParam": {
"cItId":["[<use cttSceId>]<random id>"]
"aMarB":<use value for aMarB>
}
}
Так что он должен пройти и даст мне 3 URL в этом случае. (что позже я планирую перейти к утверждениям PyTest)
Не уверен, как этого добиться с Python. кто-нибудь может помочь?
PS: из комментариев я уже пробовал
import yaml
descriptors1 = [
[(
"!!cm.mymodel.ucm.model.uCConf.UCConf\nrequests:\n- &id001\n dMD:\n cA: {}\n descMap: {en: R Des}\n dispNm: {en: Rq Nm}\n sysAt: {}\n id: R_I_001\n para:\n mt: gSoCamgSoCam\n cT: 1\n cttSceId: ['2']\n aMarB: fl\n maxR: 2\n pR: null\n reqCon: {reqTy: GET}\nuCs:\n- dMD:\n cA: {}\n descMap: {}\n dispNm: {en: gm_tt_SedCa}\n sysAt:\n undefined: {enabled: fl}\n reqCktl:\n - dMD:\n cA: {}\n descMap: {}\n dispNm: {en: Default}\n sysAt: {}\n id: gm_tt_SedCa_0\n reqL:\n - *id001\n slpara: {spPeMin: 1, spPerMx: 100}\n stUCad: GM_19_02-01-2019_236166987\n uCaId: gm_tt_SedCa\nversion: '1.0'\n",),
(
"!!cm.mymodel.ucm.model.uCConf.UCConf\nrequests:\n- &id001\n dMD:\n cA: {}\n descMap: {en: R Des}\n dispNm: {en: Rq Nm}\n sysAt: {}\n id: R_I_001\n para:\n mt: GTEdRec\n cT: 1\n cttSceId: ['2']\n aMarB: fl\n pR: null\n reqCon: {reqTy: GET}\nuCs:\n- dMD:\n cA: {}\n descMap: {}\n dispNm: {en: ult Picks}\n sysAt: {}\n reqCktl:\n - dMD:\n cA: {}\n descMap: {}\n dispNm: {en: Default}\n sysAt: {}\n id: ult/ult_pi_var_0\n reqL:\n - *id001\n slpara: {spPeMin: 1, spPerMx: 100}\n stUCad: ult/ult_Picks_11-01-2019_1003834703\n uCaId: ult/gm_tt_SedCa\nversion: '1.0'\n",),
(
"!!cm.mymodel.ucm.model.uCConf.UCConf\nrequests:\n- &id001\n dMD:\n cA: {}\n descMap: {en: R Des}\n dispNm: {en: Rq Nm}\n sysAt: {}\n id: R_I_001\n para:\n mt: GTEdRec\n cT: 1\n cttSceId: ['2']\n aMarB: fl\n campaignIds: gm_tt_SedCa_2018\n maxR: 3\n pR: null\n reqCon: {reqTy: GET}\nuCs:\n- dMD:\n cA: {}\n descMap: {}\n dispNm: {en: Vik Sea 2017}\n sysAt:\n taUsecaseDateRange: {enabled: fl}\n reqCktl:\n - dMD:\n cA: {Cat: Ed}\n descMap: {}\n dispNm: {en: Default}\n sysAt: {}\n id: ult/gm_tt_SedCa8-copy_variant_0\n reqL:\n - *id001\n slpara: {spPeMin: 1, spPerMx: 100}\n stUCad: ult/gm_tt_SedCa_2018-Copy_11-01-2017_1003834668\n uCaId: ult/gm_tt_SedCa-Copy\nversion: '1.0'\n",)]
]
a = yaml.dump(descriptors1,explicit_start=True, default_flow_style=False) ## a is type 'str' and giving o
#a = yaml.safe_dump(descriptors1,explicit_start=True, default_flow_style=False)
class PSLoader(yaml.SafeLoader):
def construct_python_tuple(self, node):
return tuple(self.construct_sequence(node))
PSLoader.add_constructor(
u'tag:yaml.org,2002:python/tuple',
PSLoader.construct_python_tuple)
yamlholder = yaml.load(a, Loader=PSLoader)
print(yamlholder)
, теперь yamlholderis типа 'list'
, а op похож на op is
[("!!cm.mymodel.ucm.model.uCConf.UCConf\nrequests:\n- &id001\n dMD:\n cA: {}\n descMap: {en: Rq Nm}\n dispNm: {en: Rq Nm}\n sysAt: {}\n id: REQ_ID_001\n para:\n mT: getSortedCampaigns\n cT: 1\n cttSceId: ['2']\n aMarB: false\n maxR: 2\n pR: null\n reqCon: {reqTy: GET}\nuCs:\n- dMD:\n cA: {}\n descMap: {}\n dispNm: {en: gm_tt_SedCa}\n sysAt:\n undefined: {enabled: fl}\n reqCktl:\n - dMD:\n cA: {}\n descMap: {}\n dispNm: {en: Default}\n sysAt: {}\n id: gm_tt_SedCa_0\n reqL:\n - *id001\n slpara: {spPeMin: 1, spPerMx: 100}\n stUCad: GM_19_02-01-2019_236166987\n uCaId: m_tt_SedCa\nversion: '1.0'\n",), ...........)]