Exemple #1
0
 def __init__(self,module, env):
     conf = ConfigReader.read_conf(module)
     logging.info("===============开始执行end:=================")
     self.db_oracle_username = conf.get(env,"db_oracle_username")
     self.db_oracle_password = conf.get(env,"db_oracle_password")
     self.db_oracle_host = conf.get(env,"db_oracle_host")
     self.oracle_connecton = DatabaseOperation(self.db_oracle_username, self.db_oracle_password, self.db_oracle_host)
Exemple #2
0
 def set_up_case(self, module, env):
     from RestfulCaseManager.Model import Context
     from RestfulCaseManager.util import ConfigReader
     context = Context.Context()
     config_parser = ConfigReader.read_conf(module=module)
     context.domain = config_parser.get(env, "domain")
     context.login_domain = config_parser.get(env, "logindomain")
     context.password_postfix = config_parser.get(env, "passwordpostfix")
     return context
Exemple #3
0
 def setting(module, env):
     conf = ConfigReader.read_conf(module=module)
     Env.domain = conf.get(env, "domain")
     Env.logindomain = conf.get(env, "logindomain")
     Env.passwordpostfix = conf.get(env, "passwordpostfix")
     Env.user = conf.get(env, "user")
     Env.db_oracle_username = conf.get(env, "db_oracle_username")
     Env.db_oracle_password = conf.get(env, "db_oracle_password")
     Env.db_oracle_host = conf.get(env, "db_oracle_host")
     Env.mongodb = conf.get(env, "mongodb")
     if module == 'Assess':
         Env.login_domain_answer = conf.get(env, 'login_domain_answer')
Exemple #4
0
def initUsers(env):
    config = ConfigReader.read_conf()
    section = "users"
    roles = config.options(section)

    # 密码后缀
    try:
        passwordPostfix = config.get("passwordpostfix", env)
        if passwordPostfix == "empty":
            passwordPostfix = ""
    except:
        passwordPostfix = ""

    # 初始化用户密码列表
    for role in roles:
        userNamesDict[role] = config.get(section, role)
        userPasswordsDict[role] = config.get(section, role) + passwordPostfix
 def setInitInfo(self,module, env):
     self.conf = ConfigReader.read_conf(module)
     self.domain = self.conf.get(env, "domain")
     self.user = self.conf.get(env, "user")
     self.loginDomain = self.conf.get(env, "logindomain")
     self.passwordpostfix = self.conf.get(env, "passwordpostfix")
Exemple #6
0
    def run(self, module='test', env='8030', caseId=""):
        logging.info("module :'" + module + "', env : '" + env +
                     "', caseId : '" + caseId + "'")

        self.conf = ConfigReader.read_conf(module)
        #   得到测试用例列表
        if caseId == "":
            caseObjectList = self.getCaseObject(module)
        else:
            caseObjectList = self.getCaseObject(caseId=caseId)

        self.domain = self.conf.get(env, "domain")

        # 执行测试用例
        response = ""
        from bson.objectid import ObjectId
        batch_id = ObjectId()

        # item is instance of TestcaeBase
        for item in caseObjectList:
            RunningLogString.logString = ''
            runStartTime = datetime.datetime.now()
            RunningLogString.logString = RunningLogString.logString + '=============开始执行:'
            RunningLogString.logString = RunningLogString.logString + runStartTime.strftime(
                '%c') + '<br/>'
            RunningLogString.logString = RunningLogString.logString + '测试用例名称:'
            RunningLogString.logString = RunningLogString.logString + item.name + '<br>'
            logging.info(u'=============开始执行用例:' + str(item.caseId))
            logging.info(u'测试用例名称:' + item.name)
            logging.info(u'测试用例URL:' + item.url)

            try:
                item.run_case(module=module, env=env)  # TestcaseBase.run_case
                if not item.response:
                    item.actualResult = ''
                    item.response = None
                    item.result = 'Fail'
                    item.responseStatus = '0000'
                    item.runningTime = ''
                    item.loggingString = RunningLogString.logString
                    self.saveResultToDB(item, batch_id)
                    logging.info("response is nones")
                    RunningLogString.logString = RunningLogString.logString + "运行结果:None<br/>"
                    continue
                # TODO UTF-8转码
                logging.info(
                    item.response.content.decode('raw_unicode_escape'))
                RunningLogString.logString = RunningLogString.logString + "运行结果:" + item.response.content.decode(
                    'raw_unicode_escape') + '<br/>'

                # item.response.text type unicode
                # item.response.content type str
                item.responseStatus = item.response.status_code
                item.responseContent = item.response.content

                if item.responseContent != "":
                    try:
                        item.responseContent_json = json.loads(
                            item.responseContent)
                        item.code = item.responseContent_json["code"]
                    except:
                        item.code = ""
            except Exception as ex:
                RunningLogString.logString = RunningLogString.logString + "运行异常"
                logging.exception("出现异常:")
            logging.info('得到结果')
            verifyModeClass = ResultVerifyModeFactory.VerifyModeFactory.factory(
                item)
            verifyModeClass.setActualResult()
            # FIXME 同时判断返回码和内容,则需要再处理
            if type(item.actualResult) is int:
                if str(item.actualResult) == str(item.expectedResult):
                    item.result = "Pass"
            elif str(item.actualResult.encode("utf-8")) == str(
                    item.expectedResult):
                item.result = "Pass"
            else:
                item.result = "Fail"

            logging.info("运行结束")

            runRndTime = datetime.datetime.now()
            runTime = runRndTime - runStartTime
            runTimeMicroseconds = runTime.microseconds
            runTimeSeconds = runTimeMicroseconds / 1000.0
            item.runningTime = runTimeSeconds

            RunningLogString.logString = RunningLogString.logString + "============运行结束:"
            RunningLogString.logString = RunningLogString.logString + runRndTime.strftime(
                '%c') + '<br/>'

            item.loggingString = RunningLogString.logString

            # 保存运行结果
            self.saveResultToDB(item, batch_id)

        return {"caseObjectList": caseObjectList, "batch_id": batch_id}