How to use test_is_positive method in assertpy

Best Python code snippet using assertpy_python

mcTests.py

Source:mcTests.py Github

copy

Full Screen

1import xml.etree.ElementTree2import argparse3import os4import mc5import forrobot6from osc import ISC7import datastructUtils8from output import Output9import copy10from time import sleep11#############################################12## ISC Exception Classes13# class ISCException(Exception): pass14# class ISCDataError(ISCException): pass15# class ISCStatusError(ISCException): pass16# class ISCOperationalError(ISCException): pass17# class ISCTestError(ISCException): pass18from osc import ISCException19from osc import ISCDataError20from osc import ISCStatusError21from osc import ISCOperationalError22from osc import ISCTestError23##24#################################@###########25# ###########################################################26# ##27# ## Default Values28# ##29#30#31# ostack_rmq_info = {32# 'ishttps' : 'false',33# 'rabbitMQPort' : '5672',34# 'rabbitUser' : 'guest',35# 'rabbitMQPassword' : 'admin123'36# }37# 38# 39# ##ostack_info['keystoneurl'] = ( "http://" + ostack_info['keystoneip'] + ":5000/v2.0")40# ##ostack_info['keystoneurl'] = ( "http://%s:%s/%s" %( ostack_info['keystoneip'], ostack_info['keystoneport'], ostack_info['keystoneversion'] ))41# ostack_info['keystoneurl'] = ( "http://%s:%s/v%s" %( ostack_info['keystoneip'], ostack_info['keystoneport'], ostack_info['keystoneversion'] ))42# ostack_info['ostackurl'] = ostack_info['keystoneurl']43# 44# 45# 46# 47# policy_defaults = {48# 'smc_policy_template': 'Layer 2 Firewall Inspection Template',49# 'smc_policy': "smc_layer2_policy1"50# }51# 52# policy_info = {53# 'smc_policy_template': args['smc_policy_template'] or policy_defaults['smc_policy_template'],54# 'smc_policy': args['smc_policy'] or policy_defaults['smc_policy']55# }56# 57# 58# 59# ##60# ## Args: {'iscpassword': 'admin123', 'iscport': 8090, 'ostackip': '10.71.85.62', 'ostackversion': '2', 'keystoneip': '10.71.85.62', 'smc_policy': None, 'ostackprojectid': 'b38d21a9ac3b464492f1b8cb18d77a25', 'ostackuser': 'admin', 'vcname': 'vctest', 'keystoneuser': 'admin', 'smckey': None, 'keystonepassword': 'admin123', 'smc_policy_template': 'Layer 2 Firewall Inspection Template', 'smcversion': '5.10', 'smcproto': 'https', 'ostackpassword': 'admin123', 'smcport': None, 'iscuser': 'admin', 'ostackproject': 'admin', 'smcip': None, 'mcname': 'OSQAET-SMC', 'sgname': 'sgtest', 'iscip': '10.71.85.64'}61# ##62# ##63# ###########################################################64###########################################################65##66## ---------------- Begin Debug Code -----------------67##68#######################################################69#70# Regex Pattern Objects71#72# rgx = re.compile(r'\w+')73# print("\nLongevity - Line: 73 - RGX Type: %s RGX Obj: %s\n\n" %(type(rgx), rgx))74#75# RGX Type: (<class '_sre.SRE_Pattern'>)76# RGX Obj: re.compile('\\w+')77#78#######################################################79###########################################################################################################80###########################################################################################################81#---------------------------------------------------------------------82##83## ISC - MC Related Methods84##85# def createManagerConnector(self, mcname, smcip, smckey):86# def getManagerConnectorByID(self, mcid):87# def getDomainsofManagerConnector(self, mcid):88# def getManagerConnectors(self):89# def syncManagerConnector(self, name, mgrID, mgrIP):90# def updateManagerConnector(self, mcid, mcname, smcip, smckey):91# def deleteMC(self,mcid):92#93##94##95#---------------------------------------------------------------------96def createMC(osc, mc):97 osc.createMC(mc)98def updateMC(osc, mc, id):99 osc.updateMC(mc, id)100def deleteMC(osc, mcid):101 osc.deleteMC(mcid=mcid)102def getManagerConnectors(osc):103 return osc.getManagerConnectors()104def getMcID(osc, name):105 return osc.getManagerConnectorByName(name)106###107### _get_mgrconns(osc, mcname=None, mcid=None)108###109### Return existing Manager Connectors (MCs). If mcname is given, return only those MCs, if any, whose name110### matches mcname111###112###113def _get_mgrconns(osc, mcname=None, mcid=None, mcnames=None, mcids=None):114 if False:115 Log.prdbg("Enter _get_mgrconns - MCName: \"%s\" MCID: \"%s\"\n -- MC Names Arg: %s\n -- MC Ids Arg: %s" %(mcname, mcid, mcnames, mcids))116 pass117 all_nm_to_id = osc.getManagerConnectors()118 if not all_nm_to_id:119 all_nm_to_id = {}120 pass121 sel_nm_to_id = None122 if mcids:123 sel_nm_to_id = { nm:id for nm,id in all_nm_to_id.items() if id in mcids }124 elif mcnames:125 sel_nm_to_id = { nm:id for nm,id in all_nm_to_id.items() if nm in mcnames }126 else:127 sel_nm_to_id = all_nm_to_id128 pass129 if False:130 Log.prdbg("_get_mgrconns \n\n - All-MC-Name-To-ID-Index:\n%s\n\n - MCIDs: %s\n\n - MCNames: %s\n\n - Selected Name-To-Id: %s" %(Log.pformat(all_nm_to_id), mcids, mcnames, Log.pformat(sel_nm_to_id), mcname, mcid, Log.pformat(sel_nm_to_id)))131 pass132 rtn = sel_nm_to_id133 if False:134 Log.prdbg("Exit _get_mgrconns\n - MCName: \"%s\" MCID: \"%s\"\n - MC Names Arg: %s\n - MC Ids Arg: %s\n\n -- Returning:\n%s" %(mcname, mcid, mcnames, mcids, rtn))135 pass136 return(rtn)137pass138def _getManagerConnectorIdByName(osc, mcname):139 sleep(3)140 _get_mgrconns(osc, mcname=mcname)141 sleep(2)142 mc_name_to_id_dict = osc.getManagerConnectors()143 Log.log_debug("MC Name To Id Dict:\n%s" %(Log.pformat(mc_name_to_id_dict)))144 if mcname in mc_name_to_id_dict:145 return(mc_name_to_id_dict[mcname])146 else:147 Log.log_abort("_getManagerConnectorIdByName: No MC Found For MC Name: \"%s\"\n -- In Manager Connectors: %s" %(mcname, mc_name_to_id_dict))148 pass149pass150#151###152### def _update_mgrconn(osc, mcid, mcname, mgrip, mgrkey):153###154### Just a call to the corresponding ISC method. Errors are propoagated.155###156### # updateManagerConnector(self, mcid, mcname, mgrip, mgrkey)157###158def _update_mgrconn(osc, mcid, mcname, mgrip, mgrkey):159 ###_fcnargs = {'osc':osc, 'mcid':mcid, 'mcname':mcname, 'mgrip':mgrip, 'mgrkey':mgrkey}160 Log.prdbg("Enter _update_mgrconn - MC ID: %s MCName: %s mgr IP: %s mgr Key: %s" %(mcid, mcname, mgrip, mgrkey))161 sleep(1)162 osc.pdateManagerConnector(mcid, mcname, mgrip, mgrkey)163 sleep(1)164 Log.prdbg("Exit _update_mgrconn - MC ID: %s MCName: %s mgr IP: %s mgr Key: %s" %(mcid, mcname, mgrip, mgrkey))165 pass166pass167###168### def _sync_mgrconn(osc, mcname, mcid, mgrip):169###170### Just a call to the corresponding ISC method. Errors are propoagated.171###172### # syncManagerConnector(self, name, mgrID, mgrIP):173###174def _sync_mgrconn(osc, mcname, mcid, mgrip):175 ###_fcnargs = {'osc':osc, 'mcid':mcid}176 Log.prdbg("Enter _sync_mgrconn - MC ID: %s" %(mcid))177 sleep(1)178 osc.syncManagerConnector(mcname, mcid, mgrip)179 sleep(1)180 Log.prdbg("Exit _sync_mgrconn - MC ID \"%s\"" %(mcid))181 pass182pass183###184### _delete_single_mgrconn(osc, mcid):185###186### Just a call to the corresponding ISC method. Errors are propoagated.187###188### # osc.deleteMC(mcid)189###190def _delete_single_mgrconn(osc, mcid):191 ###_fcnargs = {'osc':osc, 'mcid':mcid}192 Log.prdbg("Enter _delete_single_mgrconn - MC ID: %s" %(mcid))193 sleep(1)194 osc.deleteMC(mcid)195 sleep(1)196 Log.prdbg("Exit _delete_single_mgrconn - MC ID \"%s\"" %(mcid))197 pass198pass199###200###201### do_pretest -- One of: True, False202### pretest_fail_actions -- One or more of: ['continue', 'return', 'warn', 'error', 'abort' ]203### pretest_continue_on_fail -- One of: True, False204###205### _safe_delete_mgrconns(osc, mcname=None, mcid=None, do_pretest=True, pretest_fail_action="abort"):206###207### Delete existing Manager Connectors (MCs). If mcname is given, delete only those208### MCs (if any) whose name matches mcname. Otherwise delete all MCs209###210def _safe_delete_mgrconns(osc, mcname=None, mcid=None, mcids_to_delete=None, mcnames_to_delete=None, mcids_to_keep=None, mcnames_to_keep=None):211 _fcnargs = {'osc':osc, 'mcname':mcname, 'mcid':mcid}212 if True:213 Log.prdbg("Enter _safe_delete_mgrconns - MC Name: \"%s\" MCId: \"%s\"\n\n - MC Names To Delete: %s\n\nMC IDs To Delete: %s\n\n - MC Names To Keep: %s\n\n - MC Ids To Keep: %s" %(mcname, mcid, mcnames_to_delete, mcids_to_delete, mcnames_to_keep, mcids_to_keep))214 #sleep(4)215 pass216 nm_to_id_before_deletion = _get_mgrconns(osc)217 ##mcids_before_deletion = [ x['id'] for x in nm_to_id_before_deletion ]218 mcids_before_deletion = [ id for id in nm_to_id_before_deletion.values() ]219 if True:220 Log.log_debug("_safe_delete_mgrconns -- MC IDs Before Deletion:\n%s" %(mcids_before_deletion))221 #sleep(5)222 pass223 if (mcid is None) and (mcname is None) and (mcids_to_delete is None) and (mcnames_to_delete is None):224 mcids_to_delete = mcids_before_deletion225 Log.log_debug("_safe_delete_mgrconns -- Will Delete All Exisiting MC IDs: %s" %(mcids_to_delete))226 pass227 mcnames_to_delete = (mcnames_to_delete or [])228 mcids_to_delete = (mcids_to_delete or [])229 mcnames_to_keep = (mcnames_to_keep or [])230 mcids_to_keep = (mcids_to_keep or [])231 mcid_to_keep_data = None232 mcid_to_delete_data = None233 if mcname:234 mcnames_to_delete = [ mcname ]235 elif mcid:236 mcids_to_delete = [ mcid ]237 pass238 if mcnames_to_keep:239 mcid_to_keep_data = _get_mgrconns(osc, mcnames=mcnames_to_keep)240 ## mcids_to_keep = [ x['id'] for x in mcid_to_keep_data ]241 mcids_to_keep += [ id for nm,id in nm_to_id_before_deletion.items() if nm in mcnames_to_keep ]242 pass243 if mcnames_to_delete:244 mcid_to_delete_data = _get_mgrconns(osc, mcnames=mcnames_to_delete)245 ## mcids_to_delete = [ x['id'] for x in mcid_to_delete_data ]246 mcids_to_delete += [ id for nm,id in nm_to_id_before_deletion.items() if nm in mcnames_to_delete ]247 pass248 raw_mcids_to_delete = copy.copy(mcids_to_delete)249 if mcids_to_keep:250 mcids_to_delete = [ x for x in mcids_to_delete if x not in mcids_to_keep ]251 pass252 extra_mcids = [ id for id in mcids_to_delete if id not in mcids_before_deletion ]253 if True:254 ##Log.prdbg("_safe_delete_mgrconns - Existing MCs To Delete for MC Name: \"%s\" MC ID: \"%s\"\n -- Before Deletion:\n%s" %(mcname, mcid, Log.pformat(mcid_to_delete))255 Log.prdbg("_safe_delete_mgrconns - Existing MCs To Delete for MC Name: \"%s\" MC ID: \"%s\"\n - MC Names To Delete: %s\n"256 " - Raw MC IDs To Delete: %s\n - IDs To Delete: %s\n - MC Names To Keep: %s\n - MC IDs To Keep: %s\n\n - Non-Existing MC Ids To Delete: %s"257 " -- Before Deletion -- \n\n - All MC IDs: %s" %(mcname, mcid, mcnames_to_delete, raw_mcids_to_delete, mcids_to_delete, mcnames_to_keep, mcids_to_keep, mcids_before_deletion, extra_mcids))258 pass259 if mcids_to_delete:260 for mcid in mcids_to_delete:261 if False:262 Log.log_debug("_safe_delete_mgrconns -- Deleting MC ID: \"%s\" ..." %(mcid))263 pass264 _delete_single_mgrconn(osc, mcid)265 if False:266 Log.log_debug("_safe_delete_mgrconns -- ... Finished Deleting MC ID: \"%s\"" %(mcid))267 pass268 pass269 else:270 Log.log_debug("Exit _safe_delete_mgrconns -- No MCs To Delete")271 return272 pass273 sleep(1)274 nm_to_id_after_deletion = _get_mgrconns(osc, mcname=mcname, mcid=mcid)275 ##mcids_after_deletion = [ x['id'] for x in nm_to_id_after_deletion ]276 mcids_after_deletion = [ id for nm,id in nm_to_id_after_deletion.items() ]277 mcids_failed_delete = [ x for x in mcids_to_delete if x in mcids_after_deletion ]278 if True:279 Log.log_debug("_safe_delete_mgrconns\n - MCs To Be Deleted: %s\n - MCs Remaining After Deletion %s\n - MC IDs Failed To Delete: %s" %(mcids_to_delete, mcids_after_deletion, mcids_failed_delete))280 sleep(8)281 pass282 if mcids_failed_delete:283 msg = "_safe_delete_mgrconns -- Failed to Delete MCs for mcname \"%s\" - %s" %(mcname, mcids_failed_delete)284 ##raise Exception(msg)285 Log.log_abort(msg)286 pass287 if True:288 Log.log_debug("Exit _safe_delete_mgrconns -- All Manager Connectors Deleted")289 #sleep(8)290 pass291pass292###293### _create_mgrconn(osc, mcname=None, mgrip=None, mgrkey=None, mgrtype='NSM'):294###295### Just a call to the corresponding ISC method. Errors are propoagated.296###297def _create_mgrconn(osc, mcname=None, mgrip=None, mgrkey=None, mgrtype='NSM', mgruser='admin', mgrpasswd='admin123'):298 _fcnargs = {'osc':osc, 'mcname':mcname, 'mgrip':mgrip, 'mgrkey':mgrkey}299 if True:300 Log.prdbg("Enter _create_mgrconn - mcname: \"%s\" mgrip: \"%s\" mgrkey: \"%s\""%(mcname, mgrip, mgrkey))301 #sleep(5)302 pass303 mcid = osc.createManagerConnector(mcname=mcname, mgrip=mgrip, mgrkey=mgrkey, mgrtype=mgrtype, mgruser=mgruser, mgrpasswd=mgrpasswd)304 if True:305 Log.prdbg("_create_mgrconn - Manager Connector Created - MC ID: %s - %s" %(mcid, mcid.__repr__()))306 #sleep(5)307 pass308 return(mcid)309pass310###311### _safe_create_mgrconn(osc, mcname=args['mcname'], mgrip=args['mgrip'], mgrkey=args['mgrkey'], mgrtype=None):312###313###314def _safe_create_mgrconn(osc, mgrtype='NSM', mcname=None, mgrip=None, mgrkey=None, mgruser=None, mgrpasswd=None):315 cfgdict = configDict.get(mgrtype, None)316 if cfgdict:317 if mgrip is None:318 mgrip = cfgdict['ip']319 if mgrpasswd is None:320 mgrpasswd = cfgdict['password']321 if mgruser is None:322 mgruser = cfgdict['user']323 pass324 pass325 ###_fcnargs = {'osc':osc, 'mcname':mcname, 'mgrip':mgrip, 'mgrkey':mgrkey}326 Log.log_debug("Enter _safe_create_mgrconn - mcname: \"%s\" mgrip: %s mgrkey: %s mgrtype: \"%s\"" %(mcname, mgrip, mgrkey, mgrtype))327 ##if mgrtype and isinstance(mgrtype, basestring):328 if mgrtype and isinstance(mgrtype, str):329 mgrtype = mgrtype.upper()330 pass331 if mgrtype not in ['NSM', 'SMC']:332 Log.log_abort("'mgrtype' must be one of 'nsm' or 'smc': \"%s\"" %(mgrtype))333 pass334 sleep(1)335 nm_to_id_before_creation = _get_mgrconns(osc, mcname=mcname)336 # nm_to_id_before_creation = [ x['id'] for x in mcid_before_creation_data ]337 ### mcids_to_preserve = [ v for v in nm_to_id_before_creation.values() ]338 mcids_to_delete = [ v for v in nm_to_id_before_creation.values() ]339 if True:340 ### Log.log_debug("_safe_create_mgrconn - Existing mgr Manager Connectors IDs for mcname: \"%s\"\n\n -- MC-Name-To-IDs Before Creation:\n%s\n\n%s\n\n -- MCIDs To Preserve:\n%s" %(mcname, nm_to_id_before_creation, mcids_to_preserve))341 Log.log_debug("_safe_create_mgrconn - Existing Manager Connectors IDs for MC Name: \"%s\"\n\n -- MC-Name-To-IDs Before Creation:\n%s\n\n -- MC Ids To Delete: %s" %(mcname, nm_to_id_before_creation, mcids_to_delete))342 #sleep(5)343 pass344 if nm_to_id_before_creation:345 Log.log_debug("_safe_create_mgrconn - Deleting Matching mgr MCs for MC Name: \"%s\"\n- %s" %(mcname, nm_to_id_before_creation))346 _safe_delete_mgrconns(osc, mcname=mcname)347 Log.log_debug("_safe_create_mgrconn - Finished Deleting Matching mgr MCs for MC Name: \"%s\"" %(mcname))348 else:349 Log.log_debug("_safe_create_mgrconn - No Existing mgr MCs for MC Name: \"%s\"" %(mcname))350 pass351 Log.log_debug("_safe_create_mgrconn - Creating Manager connector" %())352 mcid = _create_mgrconn(osc, mcname=mcname, mgrip=mgrip, mgrkey=mgrkey, mgrtype=mgrtype, mgruser=mgruser, mgrpasswd=mgrpasswd)353 ###mcid = osc.createManagerConnector(args['mcname'], args['mgrip'], args['mgrkey'])354 Log.log_debug("_safe_create_mgrconn - Manager connector created - MC ID: %s" %(mcid))355 ##all_mcid_dict = _get_mgrconns(osc, rtn_format='dict')356 #357 # mcid_after_creation_data = _get_mgrconns(osc, mcname=mcname)358 # mcids_after_creation = [ x['id'] for x in mcid_after_creation_data ]359 #360 nm_to_id_after_creation = _get_mgrconns(osc, mcname=mcname)361 mcids_after_creation = [ v for v in nm_to_id_after_creation.values() ]362 Log.log_debug("_safe_create_mgrconn - Matching MCs for MC Name \"%s\" After Creating New MC: - %s" %(mcname, mcids_after_creation))363 if not mcids_after_creation:364 msg = "_safe_create_mgrconn -- Failed to create new mgr MC for MC Name: \"%s\"" %(mcname)365 ##raise Exception(msg)366 Log.log_abort(msg)367 elif len(mcids_after_creation) != 1:368 msg = "_safe_create_mgrconn -- Expected Exactly 1 Matching MC for MC Name %s After Creating New MC - Got %d:\n%s" %(mcname, len(mcid_list), Log.pformat(mcids_after_creation))369 ##raise Exception(msg)370 Log.log_abort(msg)371 pass372 mcid = mcids_after_creation[0]373 Log.log_debug("Exit _safe_create_mgrconn - mcname: \"%s\" - Returning: MC ID \"%s\""%(mcname, mcid))374 ##sleep(3)375 return(mcid)376pass377###########################################################################################################378###########################################################################################################379def mctest_tab1_n1(osc=None, mcconfig=None):380 test_name = "Test#1 -- NSM MC Test Cases Tab#1 -- MC Name Syntax/Positive Tests"381 test_funcname = "mctest_tab1_n1"382 test_desc = "Verify Manager Connectors Can Be Created With Any Valid MC Name - test-snort, snort-mc, snort-123 etc. "383 test_is_positive = True384 test_step = 0385 test_err_count = 0386 Log.testBegin(test_name, test_funcname, test_desc, test_is_positive)387 nsmC = copy.deepcopy(nsmConnector)388 Log.log_debug("%s:Step %d\n -- Baseline NSM Definition -- nsmC2:\n%s" %(test_funcname, test_step, Log.objformat(nsmC)))389 for mcname in [ 'snort', 'snort-123', 'mc-snort', 'foo-bar' ]:390 nsmC2 = copy.deepcopy(nsmConnector)391 nsmC2.name = mcname392 Log.log_debug("%s:Step %d\n -- Will attempt to create NSM Connector with Valid-Syntax Name: \"%s\"" %(test_funcname, test_step, mcname))393 err_match_str = ""394 test_step, test_err_count, err_info = datastructUtils.wrap_test_plus_cleaning(positive=test_is_positive, start_clean=True, finish_clean=True, osc=osc, obj=nsmC2, calling_func=test_funcname, err_match_str=err_match_str, test_fcn=createMC, clean_fcn=deleteMC, verification_fcn=getManagerConnectors, test_step=test_step, test_err_count=test_err_count)395 pass396 if test_err_count:397 Log.log_error("Exit Test %s -- Found %d Errors -- Err Info\n%s" %(test_funcname, test_err_count, err_info))398 else:399 Log.log_debug("Exit Test %s -- All Tests Passed" %(test_funcname))400 pass401 Log.testEnd(test_name, test_funcname, test_desc, test_step, test_err_count)402pass403def mctest_tab1_n2(osc=None, mcconfig=None):404 test_name = "Test#2 -- NSM MC Test Cases Tab#1 -- MC-Name Syntax/Negative Tests"405 test_funcname = "mctest_tab1_n2"406 test_desc = "Verify that MC-Name Cannot be Blank (empty-string) for MC Creation on ISC"407 test_is_positive = False408 test_err_count = 0409 test_step = 0410 Log.testBegin(test_name, test_funcname, test_desc, test_is_positive)411 nsmC = copy.deepcopy(nsmConnector)412 Log.log_debug("%s:Step %d\n -- Baseline NSM Definition -- nsmC2:\n%s" %(test_funcname, test_step, Log.objformat(nsmC)))413 mcname = ""414 nsmC2 = copy.deepcopy(nsmConnector)415 nsmC2.name = mcname416 err_match_str = "Security Controller: Name should not have an empty value"417 test_step, test_err_count, err_info = datastructUtils.wrap_test_plus_cleaning(positive=test_is_positive, start_clean=True, finish_clean=True, osc=osc, obj=nsmC2, calling_func=test_funcname, err_match_str=err_match_str, test_fcn=createMC, clean_fcn=deleteMC, verification_fcn=getManagerConnectors, test_step=test_step, test_err_count=test_err_count)418 if test_err_count:419 Log.log_debug("Exit Test %s -- Found %d unexpected Errors" %(test_funcname, test_err_count))420 else:421 Log.log_debug("Exit Test %s -- All Tests Passed" %(test_funcname))422 pass423 Log.testEnd(test_name, test_funcname, test_desc, test_step, test_err_count)424pass425def mctest_tab1_n3(osc=None, mcconfig=None):426 test_name = "Test#3 -- NSM MC Test Cases Tab#1 ---MC Name with special characters - Positive Tests"427 test_funcname = "mctest_tab1_n3"428 test_desc = "Verify Manager Connectors Can use specical characters while Valid-Syntax MC Name - 'special with space', 'VerySpecial!!%%$', '*Strange name<>&', '$#valid still ?? % !!7 ??? yes it is!!' etc. "429 test_is_positive = True430 test_step = 0431 test_err_count = 0432 Log.testBegin(test_name, test_funcname, test_desc, test_is_positive)433 nsmC = copy.deepcopy(nsmConnector)434 Log.log_debug("%s:Step %d\n -- Baseline NSM Definition -- nsmC2:\n%s" %(test_funcname, test_step, Log.objformat(nsmC)))435 for mcname in [ 'special with space', 'VerySpecial!!%%$', '*Strange name<>&', '$#valid still ?? % !!7 ??? yes it is!!' ]:436 nsmC2 = copy.deepcopy(nsmConnector)437 nsmC2.name = datastructUtils.escape(mcname)438 Log.log_debug("%s:Step %d\n -- Will attempt to create Manager Connector with Valid-Syntax Name with special characters: \"%s\"" %(test_funcname, test_step, mcname))439 err_match_str = ""440 test_step, test_err_count, err_info = datastructUtils.wrap_test_plus_cleaning(positive=test_is_positive, start_clean=True, finish_clean=True, osc=osc, obj=nsmC2, calling_func=test_funcname, err_match_str=err_match_str, test_fcn=createMC, clean_fcn=deleteMC, verification_fcn=getManagerConnectors, test_step=test_step, test_err_count=test_err_count)441 pass442 if test_err_count:443 Log.log_error("Exit Test %s -- Found %d Errors" %(test_funcname, test_err_count))444 else:445 Log.log_debug("Exit Test %s -- All Tests Passed" %(test_funcname))446 pass447 Log.testEnd(test_name, test_funcname, test_desc, test_step, test_err_count)448pass449def mctest_tab1_n4_n5(osc=None, mcconfig=None):450 test_name = "Test#4 -- NSM MC Test Cases Tab#1 --- MC Name Syntax/Negative Tests - should not exceed more than 155 characters"451 test_funcname = "mctest_tab1_n4"452 test_desc = "Verify that Manager Connector Name Cannot be over 155 characters"453 test_is_positive = False454 test_step = 0455 test_err_count = 0456 Log.testBegin(test_name, test_funcname, test_desc, test_is_positive)457 mcname = "too-long-mc-name-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890"458 nsmC2 = copy.deepcopy(nsmConnector)459 nsmC2.name = datastructUtils.escape(mcname)460 Log.log_debug("%s:Step %d\n -- Negative Test: %s -- Expecting Failure" %(test_funcname, test_step, test_desc))461 err_match_str = "Name length should not exceed 155 characters. The provided field exceeds this limit by"462 test_step, test_err_count, err_info = datastructUtils.wrap_test_plus_cleaning(positive=test_is_positive, start_clean=True, finish_clean=True, osc=osc, obj=nsmC2, calling_func=test_funcname, err_match_str=err_match_str, test_fcn=createMC, clean_fcn=deleteMC, verification_fcn=getManagerConnectors, test_step=test_step, test_err_count=test_err_count)463 pass464 if test_err_count:465 Log.log_error("Exit Test %s -- Found %d Errors -- Err Info\n%s" %(test_funcname, test_err_count, err_info))466 else:467 Log.log_debug("Exit Test %s -- All Tests Passed" %(test_funcname))468 pass469 Log.testEnd(test_name, test_funcname, test_desc, test_step, test_err_count)470pass471def mctest_tab1_n6(osc=None, mcconfig=None):472 test_name = "Test#5 -- MC Test Cases Tab#1 'MC name Syntax/Positive Test"473 test_funcname = "mctest_tab1_n6"474 test_desc = "Verify Manager Connectors Can Be Created With an MC name of exactly 155 characters - like: VC!!-123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"475 test_is_positive = True476 test_step = 0477 test_err_count = 0478 Log.testBegin(test_name, test_funcname, test_desc, test_is_positive)479 for mcname in [ 'Test-123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890',480 'MC!!-123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890',481 'Real-123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890',482 'Fooo 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890' ]:483 nsmC2 = copy.deepcopy(nsmConnector)484 nsmC2.name = datastructUtils.escape(mcname)485 Log.log_debug("%s:Step %d\n -- Will attempt to create a Manager Connector with Valid-Syntax vc Name: \"%s\"" %(test_funcname, test_step, mcname))486 err_match_str = "com.vcafee.vmidc.rest.client.exception.RestClientException: Authentication problem. Please recheck credentials"487 test_step, test_err_count, err_info = datastructUtils.wrap_test_plus_cleaning(positive=test_is_positive, start_clean=True, finish_clean=True, osc=osc, obj=nsmC2, calling_func=test_funcname, err_match_str=err_match_str, test_fcn=createMC, clean_fcn=deleteMC, verification_fcn=getManagerConnectors, test_step=test_step, test_err_count=test_err_count)488 pass489 if test_err_count:490 Log.log_error("Exit Test %s -- Found %d Errors -- Err Info\n%s" %(test_funcname, test_err_count, err_info))491 else:492 Log.log_debug("Exit Test %s -- All Tests Passed" %(test_funcname))493 pass494 Log.testEnd(test_name, test_funcname, test_desc, test_step, test_err_count)495pass496def mctest_tab3_n1(osc=None, mcconfig=None):497 test_name = "MC Test Cases Tab#3 -- IP Address Tests -- Test#1 Blank IP Address -- Negative Test"498 test_funcname = "mctest_tab3_n1"499 test_desc = "Verify Manager Connectors Cannot Be Created With Blank/Empty IP Address"500 test_is_positive = False501 test_step = 0502 test_err_count = 0503 Log.testBegin(test_name, test_funcname, test_desc, test_is_positive)504 nsmC2 = copy.deepcopy(nsmConnector)505 nsmC2.ip = ""506 err_match_str = "Open Security Controller: IP Address should not have an empty value"507 Log.log_debug("%s:Step %d\n -- Will attempt to create NSM Connector with Blank IP Address -- Negative Test:" %(test_funcname, test_step))508 test_step, test_err_count, err_info = datastructUtils.wrap_test_plus_cleaning(positive=test_is_positive, start_clean=True, finish_clean=False, osc=osc, obj=nsmC2, calling_func=test_funcname, err_match_str=err_match_str, test_fcn=createMC, clean_fcn=deleteMC, verification_fcn=getManagerConnectors, test_step=test_step, test_err_count=test_err_count)509 if test_err_count:510 Log.log_error("Exit Test %s -- Found %d Errors -- Err Info\n%s" %(test_funcname, test_err_count, err_info))511 else:512 Log.log_debug("Exit Test %s -- All Tests Passed" %(test_funcname))513 pass514 Log.testEnd(test_name, test_funcname, test_desc, test_step, test_err_count)515pass516def mctest_tab3_n2(osc=None, mcconfig=None):517 test_name = "MC Test Cases Tab#3 -- IP Address Tests -- Test#2 Invalid IP Address -- Negative Test"518 test_funcname = "mctest_tab3_n2"519 test_desc = "Verify Manager Connectors IP Address Must Be Syntactically Correct -- E.g. 4 Octets, with values v: (1 <= v <= 255)"520 test_is_positive = False521 test_step = 0522 test_err_count = 0523 Log.testBegin(test_name, test_funcname, test_desc, test_is_positive)524 nsmC2 = copy.deepcopy(nsmConnector)525 nsmC2.ip = ""526 ##err_match_str = "Open Security Controller: IP Address .* has invalid format"527 err_match_str = "Open Security Controller: IP Address: .* has invalid format"528 for ipaddr in [ '10', '10.10', '10.10.10.', '.10.10.10', '.10.10.10.', '10..10.10', '...', '..10.10.10', '10..10.10.10',529 '10.10..10', '10.10.10..10', '10.10..10', '10.10.10..10', '10.10..10.10', '256.10.10.10', '10.256.10.10',530 '10.10.256.10', '10.10.10.256', '256.256.256.256' ]:531 nsmC2 = copy.deepcopy(nsmConnector)532 ##nsmC2.name = datastructUtils.escape(mcname)533 nsmC2.ip = ipaddr534 Log.log_debug("%s:Step %d\n -- Will attempt to create a Manager Connector with InValid-Syntax IP Address: \"%s\"" %(test_funcname, test_step, ipaddr))535 test_step, test_err_count, err_info = datastructUtils.wrap_test_plus_cleaning(positive=test_is_positive, start_clean=True, finish_clean=True, osc=osc, obj=nsmC2, calling_func=test_funcname, err_match_str=err_match_str, test_fcn=createMC, clean_fcn=deleteMC, verification_fcn=getManagerConnectors, test_step=test_step, test_err_count=test_err_count)536 pass537 if test_err_count:538 Log.log_error("Exit Test %s -- Found %d Errors -- Err Info\n%s" %(test_funcname, test_err_count, err_info))539 else:540 Log.log_debug("Exit Test %s -- All Tests Passed" %(test_funcname))541 pass542 Log.testEnd(test_name, test_funcname, test_desc, test_step, test_err_count)543pass544def mctest_tab3_n3(osc=None, mcconfig=None):545 test_name = "MC Test Cases Tab#3 -- IP Address Tests -- Test#3 Syntactically-Correct IP Address"546 test_funcname = "mctest_tab3_n3"547 test_desc = "Verify OSC Does Not Give Error When Incorrect But Syntactically Valid IP Address Given"548 test_is_positive = False549 test_step = 0550 test_err_count = 0551 Log.testBegin(test_name, test_funcname, test_desc, test_is_positive)552 nsmC2 = copy.deepcopy(nsmConnector)553 nsmC2.ip = ""554 ##err_match_str = "Open Security Controller: IP Address .* has invalid format"555 err_match_str = "com.mcafee.vmidc.rest.client.exception.RestClientException: Failed to GET resource"556 for ipaddr in [ '127.0.0.1', '127.0.0.2', '127.0.1.1', '127.0.1.2' ]:557 nsmC2 = copy.deepcopy(nsmConnector)558 ##nsmC2.name = datastructUtils.escape(mcname)559 nsmC2.ip = ipaddr560 Log.log_debug("%s:Step %d\n -- Will attempt to create a Manager Connector with Syntactically-Correct (But Non-NSM) IP Address -- IP Address: \"%s\"" %(test_funcname, test_step, ipaddr))561 test_step, test_err_count, err_info = datastructUtils.wrap_test_plus_cleaning(positive=test_is_positive, start_clean=True, finish_clean=True, osc=osc, obj=nsmC2, calling_func=test_funcname, err_match_str=err_match_str, test_fcn=createMC, clean_fcn=deleteMC, verification_fcn=getManagerConnectors, test_step=test_step, test_err_count=test_err_count)562 pass563 if test_err_count:564 Log.log_error("Exit Test %s -- Found %d Errors -- Err Info\n%s" %(test_funcname, test_err_count, err_info))565 else:566 Log.log_debug("Exit Test %s -- All Tests Passed" %(test_funcname))567 pass568 Log.testEnd(test_name, test_funcname, test_desc, test_step, test_err_count)569pass570def mctest_tab4_n1(osc=None, mcconfig=None):571 test_name = "MC Test Cases Tab#4 -- Username/Password Tests -- Test#1 Blank Username -- Negative Test"572 test_funcname = "mctest_tab4_n1"573 test_desc = "Verify Manager Connectors Cannot Be Created With Blank/Empty Username"574 test_is_positive = False575 test_step = 0576 test_err_count = 0577 Log.testBegin(test_name, test_funcname, test_desc, test_is_positive)578 nsmC = copy.deepcopy(nsmConnector)579 Log.log_debug("%s:Step %d\n -- Baseline NSM Definition -- nsmC2:\n%s" %(test_funcname, test_step, Log.objformat(nsmC)))580 nsmC2 = copy.deepcopy(nsmConnector)581 nsmC2.user = ""582 err_match_str = "Open Security Controller: User Name should not have an empty value"583 Log.log_debug("%s:Step %d\n -- Will attempt to create NSM Connector with Blank Username" %(test_funcname, test_step))584 test_step, test_err_count, err_info = datastructUtils.wrap_test_plus_cleaning(positive=test_is_positive, start_clean=True, finish_clean=False, osc=osc, obj=nsmC2, calling_func=test_funcname, err_match_str=err_match_str, test_fcn=createMC, clean_fcn=deleteMC, verification_fcn=getManagerConnectors, test_step=test_step, test_err_count=test_err_count)585 if test_err_count:586 Log.log_error("Exit Test %s -- Found %d Errors -- Err Info\n%s" %(test_funcname, test_err_count, err_info))587 else:588 Log.log_debug("Exit Test %s -- All Tests Passed" %(test_funcname))589 pass590 Log.testEnd(test_name, test_funcname, test_desc, test_step, test_err_count)591pass592def mctest_tab4_n2(osc=None, mcconfig=None):593 test_name = "MC Test Cases Tab#4 -- Username/Password Tests -- Test#2 Blank Password -- Negative Test"594 test_funcname = "mctest_tab4_n2"595 test_desc = "Verify Manager Connectors Cannot Be Created With Blank/Empty Password"596 test_is_positive = False597 test_step = 0598 test_err_count = 0599 Log.testBegin(test_name, test_funcname, test_desc, test_is_positive)600 nsmC = copy.deepcopy(nsmConnector)601 Log.log_debug("%s:Step %d\n -- Baseline NSM Definition -- nsmC2:\n%s" %(test_funcname, test_step, Log.objformat(nsmC)))602 nsmC2 = copy.deepcopy(nsmConnector)603 nsmC2.passwd = ""604 err_match_str = "Open Security Controller: Password should not have an empty value"605 Log.log_debug("%s:Step %d\n -- Will attempt to create NSM Connector with Blank Password" %(test_funcname, test_step))606 test_step, test_err_count, err_info = datastructUtils.wrap_test_plus_cleaning(positive=test_is_positive, start_clean=True, finish_clean=False, osc=osc, obj=nsmC2, calling_func=test_funcname, err_match_str=err_match_str, test_fcn=createMC, clean_fcn=deleteMC, verification_fcn=getManagerConnectors, test_step=test_step, test_err_count=test_err_count)607 if test_err_count:608 Log.log_error("Exit Test %s -- Found %d Errors -- Err Info\n%s" %(test_funcname, test_err_count, err_info))609 else:610 Log.log_debug("Exit Test %s -- All Tests Passed" %(test_funcname))611 pass612 Log.testEnd(test_name, test_funcname, test_desc, test_step, test_err_count)613pass614def mctest_tab4_n3(osc=None, mcconfig=None):615 test_name = "MC Test Cases Tab#4 -- Username/Password Tests -- Test#3 Valid Username (Valid Chars Up to Lenght 155) -- Positive Test"616 test_funcname = "mctest_tab4_n3"617 test_desc = "Verify Manager Connectors Can Be Created With Syntactically-Correct Username (Valid Chars, Len <= 155)"618 test_is_positive = False619 test_step = 0620 test_err_count = 0621 Log.testBegin(test_name, test_funcname, test_desc, test_is_positive)622 nsmC = copy.deepcopy(nsmConnector)623 Log.log_debug("%s:Step %d\n -- Baseline NSM Definition -- nsmC2:\n%s" %(test_funcname, test_step, Log.objformat(nsmC)))624 ##nsmC2.mcname = datastructUtils.escape(mcname)625 err_match_str = "com.mcafee.vmidc.rest.client.exception.RestClientException: Authentication problem. Please recheck credentials"626 Log.log_debug("%s:Step %d\n -- Will attempt to create NSM Connector with Blank Password" %(test_funcname, test_step))627 for user in [628 'Test-123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890',629 'MC!!-123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890',630 'Real-123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890',631 'Fooo 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890',632 'Bar__123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890',633 ]:634 nsmC2 = copy.deepcopy(nsmConnector)635 nsmC2.user = user636 Log.log_debug("%s:Step %d\n -- Will attempt to create a Manager Connector with Valid-Syntax Username (Length=155): \"%s\"" %(test_funcname, test_step, user))637 test_step, test_err_count, err_info = datastructUtils.wrap_test_plus_cleaning(positive=test_is_positive, start_clean=True, finish_clean=True, osc=osc, obj=nsmC2, calling_func=test_funcname, err_match_str=err_match_str, test_fcn=createMC, clean_fcn=deleteMC, verification_fcn=getManagerConnectors, test_step=test_step, test_err_count=test_err_count)638 pass639 if test_err_count:640 Log.log_error("Exit Test %s -- Found %d Errors -- Err Info\n%s" %(test_funcname, test_err_count, err_info))641 else:642 Log.log_debug("Exit Test %s -- All Tests Passed" %(test_funcname))643 pass644 Log.testEnd(test_name, test_funcname, test_desc, test_step, test_err_count)645pass646def mctest_tab4_n4(osc=None, mcconfig=None):647 test_name = "MC Test Cases Tab#4 -- Username/Password Tests -- Test#4 Valid Password (Valid Chars Up to Lenght 155) -- Positive Test"648 test_funcname = "mctest_tab4_n4"649 test_desc = "Verify Manager Connectors Can Be Created With Syntactically-Correct Password (Valid Chars, Len <= 155)"650 test_is_positive = False651 test_step = 0652 test_err_count = 0653 Log.testBegin(test_name, test_funcname, test_desc, test_is_positive)654 nsmC = copy.deepcopy(nsmConnector)655 Log.log_debug("%s:Step %d\n -- Baseline NSM Definition -- nsmC2:\n%s" %(test_funcname, test_step, Log.objformat(nsmC)))656 ##nsmC2.mcname = datastructUtils.escape(mcname)657 err_match_str = "com.mcafee.vmidc.rest.client.exception.RestClientException: Authentication problem. Please recheck credentials"658 Log.log_debug("%s:Step %d\n -- Will attempt to create NSM Connector with Blank Password" %(test_funcname, test_step))659 for passwd in [660 'Test-123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890',661 'MC!!-123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890',662 'Real-123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890',663 'Fooo 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890',664 'Bar__123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890',665 ]:666 nsmC2 = copy.deepcopy(nsmConnector)667 nsmC2.passwd = passwd668 Log.log_debug("%s:Step %d\n -- Will attempt to create a Manager Connector with Valid-Syntax Password (Length=155): \"%s\"" %(test_funcname, test_step, passwd))669 test_step, test_err_count, err_info = datastructUtils.wrap_test_plus_cleaning(positive=test_is_positive, start_clean=True, finish_clean=True, osc=osc, obj=nsmC2, calling_func=test_funcname, err_match_str=err_match_str, test_fcn=createMC, clean_fcn=deleteMC, verification_fcn=getManagerConnectors, test_step=test_step, test_err_count=test_err_count)670 pass671 if test_err_count:672 Log.log_error("Exit Test %s -- Found %d Errors -- Err Info\n%s" %(test_funcname, test_err_count, err_info))673 else:674 Log.log_debug("Exit Test %s -- All Tests Passed" %(test_funcname))675 pass676 Log.testEnd(test_name, test_funcname, test_desc, test_step, test_err_count)677pass678def mctest_tab5_n1(osc=None, mcconfig=None):679 test_name = "Test#1 -- NSM MC Test Cases Tab#5 -- Add/EditDelete/Sync"680 test_funcname = "mctest_tab5_n1"681 test_desc = "Verify Manager Connectors Can Be Created With All Valid Parameters"682 test_is_positive = True683 test_step = 0684 test_err_count = 0685 Log.testBegin(test_name, test_funcname, test_desc, test_is_positive)686 nsmC = copy.deepcopy(nsmConnector)687 Log.log_debug("%s:Step %d\n -- Baseline NSM Definition -- nsmC2:\n%s" %(test_funcname, test_step, Log.objformat(nsmC)))688 nsmC2 = copy.deepcopy(nsmConnector)689 Log.log_debug("%s:Step %d\n -- Will attempt to create NSM Connector with All Valid Input" %(test_funcname, test_step))690 err_match_str = ""691 test_step, test_err_count, err_info = datastructUtils.wrap_test_plus_cleaning(positive=test_is_positive, start_clean=True, finish_clean=False, osc=osc, obj=nsmC2, calling_func=test_funcname, err_match_str=err_match_str, test_fcn=createMC, clean_fcn=deleteMC, verification_fcn=getManagerConnectors, test_step=test_step, test_err_count=test_err_count)692 if test_err_count:693 Log.log_error("Exit Test %s -- Found %d Errors -- Err Info\n%s" %(test_funcname, test_err_count, err_info))694 else:695 Log.log_debug("Exit Test %s -- All Tests Passed" %(test_funcname))696 pass697 Log.testEnd(test_name, test_funcname, test_desc, test_step, test_err_count)698pass699def mctest_tab5_n2(osc=None, mcconfig=None):700 test_name = "NSM MC Test Cases Tab#5 -- Add/EditDelete/Sync Tests -- Test#2: Create Baseline Manager Connector & Update with Unchanged Params"701 test_funcname = "mctest_tab5_n2"702 test_desc = "Verify Manager Connectors Can Be Created With All Valid Parameters & Updated With Valid Parameters (None Changed)"703 test_is_positive = True704 test_step = 0705 test_err_count = 0706 Log.testBegin(test_name, test_funcname, test_desc, test_is_positive)707 nsmC = copy.deepcopy(nsmConnector)708 Log.log_debug("%s:Step %d\n -- Baseline NSM Definition -- nsmC2:\n%s" %(test_funcname, test_step, Log.objformat(nsmC)))709 orig_mcname = nsmC.name710 orig_mctype = nsmC.type711 orig_user = nsmC.user712 orig_passwd = nsmC.passwd713 Log.log_debug("%s:Step %d\n -- Will attempt to Create NSM Connector with All Valid Input -- Err Count: %d" %(test_funcname, test_step, test_err_count))714 err_match_str = ""715 test_step, test_err_count, err_info = datastructUtils.wrap_test_plus_cleaning(positive=test_is_positive, start_clean=True, finish_clean=False, osc=osc, obj=nsmC, calling_func=test_funcname, err_match_str=err_match_str, test_fcn=createMC, clean_fcn=deleteMC, verification_fcn=getManagerConnectors, test_step=test_step, test_err_count=test_err_count)716 update_mcid = _getManagerConnectorIdByName(osc, orig_mcname)717 Log.log_debug("MC Id For MC Name \"%s\": \"%s\"" %(orig_mcname, update_mcid))718 if not update_mcid:719 Log.log_abort("%s:Step %d\n -- Failed to Get MC Id of New Manager Connector \"%s\"" %(orig_mcname))720 pass721 nsmC.update_mcid = update_mcid722 ##nsmC.user = new_user723 Log.log_debug("%s:Step %d\n -- Will attempt to Perform 'Update NSM Connector' Operation With No Unchanged Data -- Update MC Id: \"%s\" -- Err Count: %d" %(test_funcname, test_step, update_mcid, test_err_count))724 err_match_str = ""725 test_step, test_err_count, err_info = datastructUtils.wrap_test_plus_cleaning(positive=test_is_positive, start_clean=False, finish_clean=True, osc=osc, obj=nsmC, calling_func=test_funcname, err_match_str=err_match_str, test_fcn=updateMC, clean_fcn=deleteMC, verification_fcn=getManagerConnectors, test_step=test_step, test_err_count=test_err_count)726 Log.log_debug("%s:Step %d\n -- Will attempt to Perform 'Update NSM Connector' Operation With No Unchanged Data -- Update MC Id: \"%s\" -- Err Count: %d" %(test_funcname, test_step, update_mcid, test_err_count))727 if test_err_count:728 Log.log_error("Exit Test %s -- Found %d Errors -- Err Info\n%s" %(test_funcname, test_err_count, err_info))729 else:730 Log.log_debug("Exit Test %s -- All Tests Passed" %(test_funcname))731 pass732 Log.testEnd(test_name, test_funcname, test_desc, test_step, test_err_count)733pass734def mctest_tab5_n3(osc=None, mcconfig=None):735 test_name = "NSM MC Test Cases Tab#5 -- Add/EditDelete/Sync Tests -- Test#3: Create Baseline Manager Connector & Update with Valid Username & Passwd"736 test_funcname = "mctest_tab5_n3"737 test_desc = "Verify Manager Connectors Can Be Created With All Valid Parameters & Updated With Valid 'Username' & 'Passwd'"738 test_is_positive = False739 test_step = 0740 test_err_count = 0741 Log.testBegin(test_name, test_funcname, test_desc, test_is_positive)742 nsmC = copy.deepcopy(nsmConnector)743 Log.log_debug("%s:Step %d\n -- Baseline NSM Definition -- nsmC2:\n%s" %(test_funcname, test_step, Log.objformat(nsmC)))744 orig_mcname = nsmC.name745 orig_mctype = nsmC.type746 orig_user = nsmC.user747 orig_passwd = nsmC.passwd748 new_user = (orig_user + "_UPDATE")749 new_passwd = (orig_passwd + "_UPDATE")750 Log.log_debug("%s:Step %d\n -- Will attempt to Create NSM Connector with All Valid Input -- Err Count: %d" %(test_funcname, test_step, test_err_count))751 err_match_str = ""752 test_step, test_err_count, err_info = datastructUtils.wrap_test_plus_cleaning(positive=True, start_clean=True, finish_clean=False, osc=osc, obj=nsmC, calling_func=test_funcname, err_match_str=err_match_str, test_fcn=createMC, clean_fcn=deleteMC, verification_fcn=getManagerConnectors, test_step=test_step, test_err_count=test_err_count)753 update_mcid = _getManagerConnectorIdByName(osc, orig_mcname)754 Log.log_debug("MC Id For MC Name \"%s\": \"%s\"" %(orig_mcname, update_mcid))755 if not update_mcid:756 Log.log_abort("%s:Step %d\n -- Failed to Get MC Id of New Manager Connector \"%s\"" %(orig_mcname))757 pass758 nsmC.update_mcid = update_mcid759 nsmC.user = new_user760 nsmC.passwd = new_passwd761 Log.log_debug("%s:Step %d\n -- Will attempt to Perform 'Update NSM Connector' Operation With New Syntactically-Valid 'Username' & 'Password' -- Update MC Id: \"%s\" -- Err Count: %d" %(test_funcname, test_step, update_mcid, test_err_count))762 ##err_match_str = None763 err_match_str = "com.mcafee.vmidc.rest.client.exception.RestClientException: Authentication problem. Please recheck credentials."764 test_step, test_err_count, err_info = datastructUtils.wrap_test_plus_cleaning(positive=test_is_positive, start_clean=False, finish_clean=True, osc=osc, obj=nsmC, calling_func=test_funcname, err_match_str=err_match_str, test_fcn=updateMC, clean_fcn=deleteMC, verification_fcn=getManagerConnectors, test_step=test_step, test_err_count=test_err_count)765 if test_err_count:766 Log.log_error("Exit Test %s -- Found %d Errors -- Err Info\n%s" %(test_funcname, test_err_count, err_info))767 else:768 Log.log_debug("Exit Test %s -- All Tests Passed" %(test_funcname))769 pass770 Log.testEnd(test_name, test_funcname, test_desc, test_step, test_err_count)771pass772def mctest_tab5_n4(osc=None, mcconfig=None):773 test_name = "NSM MC Test Cases Tab#5 -- Add/EditDelete/Sync Tests -- Test#4: Create Baseline Manager Connector & Update with Valid Username & Passwd"774 test_funcname = "mctest_tab5_n4"775 test_desc = "Verify Manager Connectors Can Be Created With All Valid Parameters & Updated With Valid 'Username' & 'Passwd'"776 test_is_positive = True777 test_step = 0778 test_err_count = 0779 Log.testBegin(test_name, test_funcname, test_desc, test_is_positive)780 nsmC = copy.deepcopy(nsmConnector)781 Log.log_debug("%s:Step %d\n -- Baseline NSM Definition -- nsmC2:\n%s" %(test_funcname, test_step, Log.objformat(nsmC)))782 orig_mcname = nsmC.name783 orig_mctype = nsmC.type784 orig_user = nsmC.user785 orig_passwd = nsmC.passwd786 new_mcname = (orig_mcname + "_UPDATE")787 Log.log_debug("%s:Step %d\n -- Will attempt to Create NSM Connector with All Valid Input -- Err Count: %d" %(test_funcname, test_step, test_err_count))788 err_match_str = ""789 test_step, test_err_count, err_info = datastructUtils.wrap_test_plus_cleaning(positive=True, start_clean=True, finish_clean=False, osc=osc, obj=nsmC, calling_func=test_funcname, err_match_str=err_match_str, test_fcn=createMC, clean_fcn=deleteMC, verification_fcn=getManagerConnectors, test_step=test_step, test_err_count=test_err_count)790 update_mcid = _getManagerConnectorIdByName(osc, orig_mcname)791 Log.log_debug("MC Id For MC Name \"%s\": \"%s\"" %(orig_mcname, update_mcid))792 if not update_mcid:793 Log.log_abort("%s:Step %d\n -- Failed to Get MC Id of New Manager Connector \"%s\"" %(orig_mcname))794 pass795 nsmC.update_mcid = update_mcid796 nsmC.name = new_mcname797 Log.log_debug("%s:Step %d\n -- Will attempt to Perform 'Update NSM Connector' Operation With New Syntactically-Valid 'MC Name' -- Update MC Id: \"%s\" -- Err Count: %d" %(test_funcname, test_step, update_mcid, test_err_count))798 ##err_match_str = None799 err_match_str = ""800 test_step, test_err_count, err_info = datastructUtils.wrap_test_plus_cleaning(positive=test_is_positive, start_clean=False, finish_clean=True, osc=osc, obj=nsmC, calling_func=test_funcname, err_match_str=err_match_str, test_fcn=updateMC, clean_fcn=deleteMC, verification_fcn=getManagerConnectors, test_step=test_step, test_err_count=test_err_count)801 if test_err_count:802 Log.log_error("Exit Test %s -- Found %d Errors -- Err Info\n%s" %(test_funcname, test_err_count, err_info))803 else:804 Log.log_debug("Exit Test %s -- All Tests Passed" %(test_funcname))805 pass806 Log.testEnd(test_name, test_funcname, test_desc, test_step, test_err_count)807pass808def mctest_tab5_n5(osc=None, mcconfig=None):809 test_name = "NSM MC Test Cases Tab#5 -- Add/EditDelete/Sync Tests -- Test#4: Create Baseline Manager Connector & Update with Valid Username & Passwd"810 test_funcname = "mctest_tab5_n5"811 test_desc = "Verify Manager Connectors Can Be Created With All Valid Parameters & Updated With New MC Name"812 test_is_positive = False813 test_step = 0814 test_err_count = 0815 Log.testBegin(test_name, test_funcname, test_desc, test_is_positive)816 nsmC = copy.deepcopy(nsmConnector)817 Log.log_debug("%s:Step %d\n -- Baseline NSM Definition -- nsmC2:\n%s" %(test_funcname, test_step, Log.objformat(nsmC)))818 orig_mcname = nsmC.name819 orig_mctype = nsmC.type820 orig_user = nsmC.user821 orig_passwd = nsmC.passwd822 new_mcip = "127.0.0.1"823 Log.log_debug("%s:Step %d\n -- Will attempt to Create NSM Connector with All Valid Input -- Err Count: %d" %(test_funcname, test_step, test_err_count))824 err_match_str = ""825 test_step, test_err_count, err_info = datastructUtils.wrap_test_plus_cleaning(positive=True, start_clean=True, finish_clean=False, osc=osc, obj=nsmC, calling_func=test_funcname, err_match_str=err_match_str, test_fcn=createMC, clean_fcn=deleteMC, verification_fcn=getManagerConnectors, test_step=test_step, test_err_count=test_err_count)826 update_mcid = _getManagerConnectorIdByName(osc, orig_mcname)827 Log.log_debug("MC Id For MC Name \"%s\": \"%s\"" %(orig_mcname, update_mcid))828 if not update_mcid:829 Log.log_abort("%s:Step %d\n -- Failed to Get MC Id of New Manager Connector \"%s\"" %(orig_mcname))830 pass831 nsmC.update_mcid = update_mcid832 nsmC.ip = new_mcip833 Log.log_debug("%s:Step %d\n -- Will attempt to Perform 'Update NSM Connector' Operation With New Syntactically-Valid 'IP Address' -- Update MC Id: \"%s\" -- Err Count: %d" %(test_funcname, test_step, update_mcid, test_err_count))834 ##err_match_str = None835 err_match_str = "com.mcafee.vmidc.rest.client.exception.RestClientException: Failed to GET resource:"836 test_step, test_err_count, err_info = datastructUtils.wrap_test_plus_cleaning(positive=test_is_positive, start_clean=False, finish_clean=True, osc=osc, obj=nsmC, calling_func=test_funcname, err_match_str=err_match_str, test_fcn=updateMC, clean_fcn=deleteMC, verification_fcn=getManagerConnectors, test_step=test_step, test_err_count=test_err_count)837 if test_err_count:838 Log.log_error("Exit Test %s -- Found %d Errors -- Err Info\n%s" %(test_funcname, test_err_count, err_info))839 else:840 Log.log_debug("Exit Test %s -- All Tests Passed" %(test_funcname))841 pass842 Log.testEnd(test_name, test_funcname, test_desc, test_step, test_err_count)843pass844def getText(tree, tag):845 element = tree.find(tag)846 if element == None:847 return None848 else:849 return element.text850def getElement(tree, tag):851 element = tree.find(tag)852 if element == None:853 return None854 else:855 return element856def getParams(xml_str):857 global nsmConnector, smcConnector858 global osc859 tree = xml.etree.ElementTree.fromstring(xml_str)860 if tree.tag == 'Params' :861 # third party executables862 py27 = getText(tree, "thirdParty/py27")863 ovfToolExe = getText(tree, "thirdParty/ovfToolExe")864 Log.log_debug("py27=%s, ovfToolExe=%s" % (py27, ovfToolExe))865 # osc credentials866 #iscVersion = getText(tree, "ISC/version")867 iscIp = getText(tree, "ISC/ip")868 iscPort = getText(tree, "ISC/port")869 iscUser = getText(tree, "ISC/user")870 iscPass = getText(tree, "ISC/pass")871 Log.log_debug("iscIp=%s, iscUser=%s, iscPass=%s" % (iscIp, iscUser, iscPass))872 # NSM Connector873 nsmElement = getElement(tree, "nsm")874 nsmConnectorXml = xml.etree.ElementTree.tostring(nsmElement, encoding='utf8', method='xml')875 nsmConnector = mc.mc(nsmConnectorXml)876 Log.log_debug("nsmConnectorXml=%s" % nsmConnectorXml)877 osc = ISC( iscIp, iscPort, iscUser, iscPass)878 pass879pass880def init_all():881 global Log882 Log = Output()883 parser = argparse.ArgumentParser( description="MC Tests For NSM -- ")884 parser.add_argument( '-c', '--configFile', default="McTestsParams.xml", help='Path to XML Param File')885 parser.add_argument('-v', '--verbose', required=False, help='Enable verbose output', dest='verbose', default=False, action='store_true')886 parser.add_argument('-d', '--delay', default='0', help='Delay between operation so we can see it in the OSC UI')887 args = vars(parser.parse_args())888 xml_test_path = args['configFile']889 Log.log_debug('xml_test_path %s' % xml_test_path)890 verbose = args['verbose']891 Log.set_module_name(os.path.basename(__file__))892 Log.set_debug(verbose=verbose)893 if verbose:894 Log.log_info('debug message will be displayed')895 else:896 Log.log_info("debug message won't be displayed")897 seconds = args['delay']898 try:899 f_sec = float(seconds)900 except:901 Log.log_abort('--delay should be a positive floating number')902 if f_sec < 0:903 Log.log_abort('--delay should be a POSITIVE floating number')904 else: # f_sec >= 0905 Log.set_delay(seconds=f_sec)906 Log.log_debug("Reading parameters from '%s'" % xml_test_path)907 xml_params_test_file = open(xml_test_path, "r")908 xml_params_test_str = xml_params_test_file.read()909 xml_params_test_file.close()910 getParams(xml_params_test_str)911def get_mc(mcType, mcName, mcIP, mcUser, mcPass, mcApiKey):912 mc = forrobot.mc(mcType, mcName, mcIP, mcUser, mcPass, mcApiKey)913 return mc914def get_mc_smc(mcType, mcName, mcIP, mcUser, mcPass, mcApiKey):915 mc = forrobot.mc(mcType, mcName, mcIP, mcUser, mcPass, mcApiKey)916 return mc917def positive_test_mc_name(start_clean, finish_clean, mcname, mc, osc, log):918 global Log919 vcid = None920 err_match_str = ""921 test_funcname = "positive_test_mc_name"922 test_is_positive = True923 test_desc = "Verify Manager Connectors Can Be Created With Any Valid name like: " + mcname924 test_mc = copy.deepcopy(mc)925 test_mc.name = mcname926 Log=log927 test_step, test_err_count, err_info = datastructUtils.wrap_test_plus_cleaning(positive=test_is_positive, start_clean=start_clean, finish_clean=finish_clean, osc=osc, obj=test_mc, calling_func=test_funcname, err_match_str=err_match_str, test_fcn=createMC, clean_fcn=deleteMC, verification_fcn=getManagerConnectors, test_step=0, test_err_count=0, fail_on_error=False)928 if test_err_count:929 Log.log_error("Exit Test %s -- Found %d Errors\n -- Err Info:\n%s" %(test_funcname, test_err_count, err_info))930 else:931 Log.log_debug("Exit Test %s -- All Tests Passed" %(test_funcname))932 pass933 Log.testEnd(test_funcname, test_funcname, test_desc, test_step, test_err_count)934 return test_err_count935def negative_test_mc_name(err_match_str, start_clean, finish_clean, mcname, mc, osc, log):936 global Log937 test_funcname = "negative_test_mc_name"938 test_is_positive = False939 test_desc = "Verify Manager Connectors Cannot be created with invalid name Be Created With Any Valid name like: '" + mcname + "'"940 test_mc = copy.deepcopy(mc)941 test_mc.name = mcname942 Log=log943 test_step, test_err_count, err_info = datastructUtils.wrap_test_plus_cleaning(positive=test_is_positive, start_clean=start_clean, finish_clean=finish_clean, osc=osc, obj=test_mc, calling_func=test_funcname, err_match_str=err_match_str, test_fcn=createMC, clean_fcn=deleteMC, verification_fcn=getManagerConnectors, test_step=0, test_err_count=0, fail_on_error=False)944 if test_err_count:945 Log.log_error("Exit Test %s -- Found %d Errors\n -- Err Info:\n%s" %(test_funcname, test_err_count, err_info))946 else:947 Log.log_debug("Exit Test %s -- All Tests Passed" %(test_funcname))948 pass949 Log.testEnd(test_funcname, test_funcname, test_desc, test_step, test_err_count)950 return test_err_count, err_info951def main():952 init_all()953 mctest_tab1_n1(osc=osc, mcconfig=None)954 mctest_tab1_n2(osc=osc, mcconfig=None)955 mctest_tab1_n3(osc=osc, mcconfig=None)956 mctest_tab1_n4_n5(osc=osc, mcconfig=None)957 mctest_tab1_n6(osc=osc, mcconfig=None)958 mctest_tab3_n1(osc=osc, mcconfig=None)959 mctest_tab3_n2(osc=osc, mcconfig=None)960 mctest_tab3_n3(osc=osc, mcconfig=None)961 mctest_tab4_n1(osc=osc, mcconfig=None)962 mctest_tab4_n2(osc=osc, mcconfig=None)963 mctest_tab4_n3(osc=osc, mcconfig=None)964 mctest_tab4_n4(osc=osc, mcconfig=None)965 mctest_tab5_n1(osc=osc, mcconfig=None)966 mctest_tab5_n2(osc=osc, mcconfig=None)967 mctest_tab5_n3(osc=osc, mcconfig=None)968 mctest_tab5_n4(osc=osc, mcconfig=None)969 mctest_tab5_n5(osc=osc, mcconfig=None)970 Log.summarize_module_tests()971pass972##973## End start()974##975if __name__ == "__main__":...

Full Screen

Full Screen

funcs_tests.py

Source:funcs_tests.py Github

copy

Full Screen

...27 assert found == expected28 found = funcs.f(3,3)29 expected = ((3*3**2) + (4*3))/ (2 * 3)30 assert found == expected31def test_is_positive():32 found = funcs.is_positive(-1)33 expected = False34 assert found == expected35 found = funcs.is_positive(1)36 expected = True37 assert found == expected38 found = funcs.is_positive(-2)39 expected = False40 assert found == expected41def test_both_positive():42 found = funcs.both_positive(2,2)43 expected = True44 assert found == expected45 found = funcs.both_positive(2, -2)46 expected = False47 assert found == expected48 found = funcs.both_positive(3,3)49 expected = True50 assert found == expected51def main():52 test_cube()53 test_hypotenuse()54 test_f()55 test_is_positive()56 test_both_positive()57if __name__ == '__main__':...

Full Screen

Full Screen

test_theorem.py

Source:test_theorem.py Github

copy

Full Screen

...9 combination(0, 3)10def test_binomiarl_theorem():11 assert binomial_theorem(16, 8, 2, -3) == 2161665792012 assert binomial_theorem(16, 13, 2, -3) == -714256704013def test_is_positive():14 assert is_positive("----") == True15 assert is_positive("+++++") == False16 assert is_positive("-+-+") == True17 assert is_positive("adlkfja") == False18def test_theorem():19 test_combination()20 test_comination_n_zero()21 test_binomiarl_theorem()22 test_is_positive()23if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run assertpy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful