class ITC0902_GetProfileInfo(BaseTestCase): """ @summary: ITC-06配置集管理-02获取指定配置集信息 """ def setUp(self): """ @summary: 测试用例执行前的环境初始化(前提) """ self.dm = super(self.__class__, self).setUp() self.nwapi = NetworkAPIs() # 首先新建一个网络并获取其id LogPrint().info("Pre-Test-1: Create a network %s for TC." % self.dm.nw_name) self.nw_id = self.nwapi.createNetwork(self.dm.nw_info)["result"]["network"]["@id"] self.proapi = ProfilesAPIs() LogPrint().info("Pre-Test-2: Create a profile %s for this network." % self.dm.profile_name) self.proapi.createProfiles(self.dm.profile_info, self.nw_id) def test_GetProfileInfo_byname(self): """ @summary: 根据配置集名称获取其信息 @note: 操作成功,验证返回状态码,验证接口返回信息 """ self.flag = True r = self.proapi.getProfileInfo(profile_name=self.dm.profile_name, nw_id=self.nw_id) LogPrint().info("Test-1: Get profile %s by NAME." % self.dm.profile_name) if r["status_code"] == self.dm.expected_status_code: dict_actual = r["result"] dict_expected = xmltodict.parse((self.dm.profile_info % self.nw_id)) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info("PASS: Get Profile info SUCCESS.") else: LogPrint().error("FAIL:Returned Profile info INCORRECT.") self.flag = False else: LogPrint().error( "FAIL: Returned status code is %s not %s. " % (r["status_code"], self.dm.expected_status_code) ) self.flag = False self.assertTrue(self.flag) def test_GetProfileInfo_id(self): """ @summary: 根据配置集id获取信息 @note: 操作成功,验证返回状态码,验证接口返回信息 """ # 测试1:根据网络id获取网络信息 self.flag = True LogPrint().info("Test-2: Get profile %s by ID." % self.dm.profile_name) profile_id = self.proapi.getProfileIdByName(self.dm.profile_name, self.nw_id) r = self.proapi.getProfileInfo(profile_id=profile_id) if r["status_code"] == self.dm.expected_status_code: dict_actual = r["result"] dict_expected = xmltodict.parse((self.dm.profile_info % self.nw_id)) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info("PASS: Get Profile info SUCCESS.") else: LogPrint().error("FAIL:Returned Profile info INCORRECT.") self.flag = False else: LogPrint().error( "FAIL: Returned status code is %s not %s. " % (r["status_code"], self.dm.expected_status_code) ) self.flag = False self.assertTrue(self.flag) def tearDown(self): """ @summary: 测试结束后的资源清理(恢复初始环境) """ LogPrint().info("Post-Test: Delete the network %s." % self.dm.nw_name) self.nwapi.delNetwork(self.dm.nw_name, self.dm.dc_name)
class ITC0902_GetProfileInfo(BaseTestCase): ''' @summary: ITC-06配置集管理-02获取指定配置集信息 ''' def setUp(self): ''' @summary: 测试用例执行前的环境初始化(前提) ''' self.dm = super(self.__class__, self).setUp() self.nwapi = NetworkAPIs() #首先新建一个网络并获取其id LogPrint().info("Pre-Test-1: Create a network %s for TC."%self.dm.nw_name) self.nw_id = self.nwapi.createNetwork(self.dm.nw_info)['result']['network']['@id'] self.proapi = ProfilesAPIs() LogPrint().info("Pre-Test-2: Create a profile %s for this network."%self.dm.profile_name) self.proapi.createProfiles(self.dm.profile_info,self.nw_id) def test_GetProfileInfo_byname(self): ''' @summary: 根据配置集名称获取其信息 @note: 操作成功,验证返回状态码,验证接口返回信息 ''' self.flag = True r = self.proapi.getProfileInfo(profile_name=self.dm.profile_name, nw_id=self.nw_id) LogPrint().info("Test-1: Get profile %s by NAME."%self.dm.profile_name) if r['status_code'] == self.dm.expected_status_code: dict_actual = r['result'] dict_expected = xmltodict.parse((self.dm.profile_info %self.nw_id)) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info("PASS: Get Profile info SUCCESS." ) else: LogPrint().error("FAIL:Returned Profile info INCORRECT.") self.flag = False else: LogPrint().error("FAIL: Returned status code is %s not %s. "% (r['status_code'], self.dm.expected_status_code) ) self.flag = False self.assertTrue(self.flag) def test_GetProfileInfo_id(self): ''' @summary: 根据配置集id获取信息 @note: 操作成功,验证返回状态码,验证接口返回信息 ''' # 测试1:根据网络id获取网络信息 self.flag = True LogPrint().info("Test-2: Get profile %s by ID."%self.dm.profile_name) profile_id = self.proapi.getProfileIdByName(self.dm.profile_name, self.nw_id) r = self.proapi.getProfileInfo(profile_id=profile_id) if r['status_code'] == self.dm.expected_status_code: dict_actual = r['result'] dict_expected = xmltodict.parse((self.dm.profile_info %self.nw_id)) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info("PASS: Get Profile info SUCCESS.") else: LogPrint().error("FAIL:Returned Profile info INCORRECT.") self.flag = False else: LogPrint().error("FAIL: Returned status code is %s not %s. "% (r['status_code'], self.dm.expected_status_code)) self.flag = False self.assertTrue(self.flag) def tearDown(self): ''' @summary: 测试结束后的资源清理(恢复初始环境) ''' LogPrint().info("Post-Test: Delete the network %s."%self.dm.nw_name) self.nwapi.delNetwork(self.dm.nw_name, self.dm.dc_name)