Exemplo n.º 1
0
    def processsXml(self, xml):
        myCase=''
        objlist=XmlHandler().XmlStringToObj(xml, keyword='events')
        if objlist:
            obj=objlist[-1]
            myCase=eventParsingCase()
            myCase.eventType=obj.eventType
            for attr in obj.attributes:
                if not attr.name in myCase.params.keys() and not attr.name in ignore_attrs:
                    if attr.name in any_attrs:
                        myCase.params[attr.name]='any'
                        if attr.name=='rawEventMsg':
                            myCase.eventMsg=attr.value
                    elif attr.name in address_attrs:
                        if attr.value==self.localhost:
                            myCase.params[attr.name]='$localhost'
                        else:
                            myCase.params[attr.name]=attr.value
                    elif attr.name=='phCustId':
                            myCase.params[attr.name]='$sender'
                    else:
                            myCase.params[attr.name]=attr.value
                else:
                    if not attr.name in ignore_attrs and not attr.value==myCase.params[attr.name]:
                        if len(attr.value)>len(myCase.params[attr.name]):
                            myCase.params[attr.name]=attr.value
            if 'parser' in myCase.params.keys():
                myCase.module=myCase.params['parser']
            else:
                myCase.module=self.module_name
        else:
            print 'No case returned'

        return myCase
Exemplo n.º 2
0
 def __generateFiles(self, autoResult):
     if not os.path.exists(str(autoResult.testFolder)):
         if ':' in autoResult.testFolder:
             autoResult.testFolder=autoResult.testFolder.replace(':', '-')
         os.makedirs(str(autoResult.testFolder))
     for suite in autoResult.suiteList:
         for spec in SPECIAL_CHARS:
             if spec in suite.name:
                 suite.name=suite.name.replace(spec, '-')
         if '"' in suite.name:
             suite.name=suite.name.replace('"','')
         fileName=autoResult.testFolder+'/'+suite.name+'.xml'
         XmlHandler().XmlObjToFile(suite, fileName)
         setattr(suite, 'detailFile', fileName)
Exemplo n.º 3
0
    def __RoleSpecial(self, expData, actData):
        newData = {}
        for key in expData.keys():
            profileObj = expData[key].Config.profile
            impl = dom.getDOMImplementation()
            doc = impl.createDocument(None, None, None)
            myTitle = doc.toxml('UTF-8')
            myXml = XmlHandler().XmlObjToString(profileObj)
            setattr(expData[key], 'Config', myTitle + myXml)
            newObj = classTranslation.classTranslation().doTranslate(
                expData[key])
            newData[newObj.attribute['naturalId']] = newObj

        return newData, actData
Exemplo n.º 4
0
    def __getXMLData(self, type, myPath):
        if type in testConstant.populator_type_switch.keys():
            indexKey = testUtility.getKey(
                testConstant.populator_type_switch[type])
        else:
            indexKey = testUtility.getKey(type)
        fileList = os.listdir(myPath)
        newFiles = []
        for file in fileList:
            if '.xml' in file and file not in testConstant.populator_skip_files:
                newFiles.append(file)
        rawdata = {}
        for file in newFiles:
            name = file.split('.')[0]
            myFile = open(myPath + '/' + file, 'r')
            text = ''
            for line in myFile.readlines():
                text += line.replace('\n', '')
            myFile.close()
            rawdata[name] = text
        finalData = {}
        if type in testConstant.populator_path_change.keys():
            type = type.title()
        types = generalUtility.getPlural(type)
        myXmlHandler = XmlHandler()
        for subkey in rawdata.keys():
            myData = myXmlHandler.XmlStringToObj(rawdata[subkey],
                                                 keyword=types)
            for data in myData:
                if 'Attribute-' in indexKey:
                    key = data.attribute[indexKey.split('-')[-1]]
                else:
                    key = getattr(data, indexKey)
                finalData[key] = data

        return finalData
Exemplo n.º 5
0
    def testGeneralDefinition(self, type=False):
        if type:
            tests = [type]
        else:
            tests = TestConstant.general_tasks.keys()
        for test in tests:
            print '\nTest %s' % test
            myPath = self.__getPath(
                type) + '.' + TestConstant.general_tasks[type]
            if TestConstant.general_tasks[type] == 'xml':
                indexData = XmlHandler.getDatafromFile(myPath, type)
            elif TestConstant.general_tasks[type] == 'csv':
                indexData = CSVHandler.getDatafromFile(myPath, type=type)
            retData = self.configHandler.getData(test)

            self.verifyData(indexData, retData, testUtility.getListKey(type))
Exemplo n.º 6
0
import os
from Libs.XmlHandler import XmlHandler

path='../DataFiles/Incident'
files=os.listdir(path)
configpath='../TestData/Incident/incidentData.csv'
rawpath='../TestData/Incident/IncidentMsgs/'
eD='[eventMsg]'
cD='[clearEventMsg]'
dataList=[]

for file in files:
    if '.xml' in file:
        data=XmlHandler().XmlFileToObj(path+'/'+file)
        dataList.append(data)
outFile=open(configpath, 'w')
outFile.write('incidentType,name,reptDevIpAddr,createDevice,deviceName,deviceType,domainController,count,method')
outFile.write('\n')
for item in dataList:
    case=item.testcases[0]
    output=[]
    output.append(case.eventType)
    output.append(item.name)
    output.append(case.reporter)
    reporter=case.reporter
    if case.createDevice!=None:
        output.append(case.createDevice)
    else:
        output.append('')
    if case.deviceName!=None:
        output.append(case.deviceName)
Exemplo n.º 7
0
def getTestConfig(config, src=None):
    testConfig = XmlHandler().XmlFileToObj(config)
    if testConfig is None:
        print 'testConfig file has problem: %s' % config
        sys.exit()
    testConfig.localhost = getLocalhostIp()
    testConfig.runTime = getTimeNowFormat()
    server = ''
    if getattr(testConfig.testServer, 'allInOne'):
        if src:
            server = src
        else:
            server = testConfig.testServer.allInOne
        testConfig.testServer.dbServer = server
        testConfig.testServer.appServer = server
        testConfig.testServer.dataCollector = server
    else:
        server = testConfig.testServer.appServer + '-' + testConfig.testServer.dataCollector
    if hasattr(testConfig, 'noSend') and testConfig.noSend == 'true':
        testConfig.noSend = True
    else:
        testConfig.noSend = False
    if os.name == 'posix':
        myPass = False
        if hasattr(testConfig, 'rootCredential'):
            myPass = testConfig.rootCredential.password
        print 'pass %s' % myPass
        myCheck = checkTimer(testConfig.testServer.dataCollector, pwd=myPass)
        myCheck.compareTime()
        setattr(testConfig, 'posix', True)
    if hasattr(testConfig, 'credential'):
        my_user = testConfig.credential.user
        my_password = testConfig.credential.password
    else:
        my_user = '******'
        my_password = '******'
    setattr(testConfig, 'user', my_user)
    setattr(testConfig, 'password', my_password)
    systemInfo = restApiDataHandler(server.split('-')[0],
                                    user=my_user,
                                    password=my_password).getData(
                                        'health', module='cloudStatus')
    if systemInfo:
        try:
            buildDate = convertTime(int(systemInfo.buildDate))
        except ValueError:
            buildDate = systemInfo.buildDate
        testConfig.buildVersion = systemInfo.version + ' (build on ' + buildDate + ')'
        ver_num = int(int(systemInfo.version.replace('.', '')) / 10000)
        if ver_num >= 371:
            setattr(testConfig, 'ruleTestSupport', True)
        else:
            setattr(testConfig, 'ruleTestSupport', False)
    else:
        print 'Cannot get System Info. Exit'
        sys.exit()
    tasks = []
    for task in testConfig.testTask:
        tasks.append(task.taskName)
        if not task.taskFiles:
            task.taskFiles = 'all'
        if not task.taskOption:
            task.taskOption = config_constant.test_option_check
        if not task.waitTime:
            task.waitTime = 120
    testConfig.name = ''.join(tasks) + '-' + testConfig.runTime + '-' + server

    return testConfig