Ejemplo n.º 1
0
    def set_db_cfg(self, cfg_name='mydb', sec_name='mysql'):
        """
        set_db_cfg_type 设置类型

        .. doctest::
            mysql_o.set_db_cfg_type('debug')
            mysql_o.set_db_cfg()

        """
        # 获取数据库配置
        app_loc = cofFile.get_app_loc()

        if not self.db_cfg_type:
            cfg_obj = cofConf.MyCfg(app_loc + os.sep + 'cfgtype.ini')
            cfg_obj.set_section('cfg')
            cfg_type = cfg_obj.get('type')
        else:
            cfg_type = self.db_cfg_type

        db_cfg_obj = cofConf.MyCfg(os.sep + cfg_name + '.ini')
        db_cfg_obj.set_section(sec_name)

        self.host = db_cfg_obj.get('host')
        self.port = int(db_cfg_obj.get('port'))
        self.user = db_cfg_obj.get('user')
        self.passwd = db_cfg_obj.get('passwd')
        self.dbname = db_cfg_obj.get('db')

        self.db = MySQLdb.connect(host=self.host, port=self.port, user=self.user, passwd=self.passwd, db=self.dbname)
        self.cursor = self.db.cursor()

        pre_sql = "SET NAMES 'utf8'"
        self.exec_sql(pre_sql)
Ejemplo n.º 2
0
    def __init__(self, path='params.ini'):
        app_loc = cofFile.get_app_loc()
        path = app_loc + 'config' + os.sep + 'lc_params_cfg' + os.sep + path
        ex_path = cofFile.expand_links(path)
        if not os.path.exists(ex_path):
            print "config file is not exist (" + ex_path + ")"

            exit()
        self.path = ex_path
        self.sec = ""
        self.cfg_obj = ConfigParser.ConfigParser()
        self.cfg_obj.read(self.path)
Ejemplo n.º 3
0
    def __init__(self, path='params.ini'):
        app_loc = cofFile.get_app_loc()
        path = app_loc + 'config' + os.sep + 'lc_params_cfg' + os.sep + path
        ex_path = cofFile.expand_links(path)
        if not os.path.exists(ex_path):
            print "config file is not exist (" + ex_path + ")"

            exit()
        self.path = ex_path
        self.sec = ""
        self.cfg_obj = ConfigParser.ConfigParser()
        self.cfg_obj.read(self.path)
Ejemplo n.º 4
0
def judge_sensitive_word(words):
    app_loc = cofFile.get_app_loc()
    path = app_loc + 'api_call/sensitive_word/sensitiveWord.txt'
    ex_path = cofFile.expand_links(path)
    f = open(ex_path)
    s = f.read()
    s1 = re.split(' ', s)

    for i in s1:
        if i != "":
            if i in words:
                return False
    return True
Ejemplo n.º 5
0
    def set_db_cfg(self, cfg_name='mydb', sec_name='mysql'):
        """
        set_db_cfg_type 设置类型

        .. doctest::
            mysql_o.set_db_cfg_type('debug')
            mysql_o.set_db_cfg()

        """
        # 获取数据库配置
        app_loc = cofFile.get_app_loc()

        if not self.db_cfg_type:
            cfg_obj = cofConf.MyCfg(app_loc + os.sep + 'cfgtype.ini')
            cfg_obj.set_section('cfg')
            cfg_type = cfg_obj.get('type')
        else:
            cfg_type = self.db_cfg_type

        db_cfg_obj = cofConf.MyCfg(os.sep + cfg_name + '.ini')
        db_cfg_obj.set_section(sec_name)

        self.host = db_cfg_obj.get('host')
        self.port = int(db_cfg_obj.get('port'))
        self.user = db_cfg_obj.get('user')
        self.passwd = db_cfg_obj.get('passwd')
        self.dbname = db_cfg_obj.get('db')

        self.db = MySQLdb.connect(host=self.host,
                                  port=self.port,
                                  user=self.user,
                                  passwd=self.passwd,
                                  db=self.dbname)
        self.cursor = self.db.cursor()

        pre_sql = "SET NAMES 'utf8'"
        self.exec_sql(pre_sql)
Ejemplo n.º 6
0
from nose import suite
from nose import loader
from cof.conf import MyCfg

opt_parser = OptionParser()
opt_parser.add_option("-s",
                      "--suite",
                      dest="suite",
                      help=u"指定运行的测试套件",
                      metavar="SUITE")

(options, opt_args) = opt_parser.parse_args()

suite_opt = options.suite

app_loc = CoFileM.get_app_loc()
app_cfg = CoConfM.get_cfg_type()
app_gbl_cfg_file = CoConfM.get_cfg_type_path()

if not suite_opt:
    suite_config = "suites.json"
else:
    # 到指定的目录获取对应的测试集配置
    suite_config = app_loc + "config" + os.sep + app_cfg + os.sep + suite_opt + ".json"

# 获取当前时间
date = cofTime.get_date_ymd()  # 日期【20150213】
timestamp = str(cofTime.get_ts())  # 时间戳【1423813170】

# 当前路径
path = os.path.abspath(__file__)
Ejemplo n.º 7
0
import datetime
import StringIO
import sys
import unittest
from xml.sax import saxutils

import os
import re
import time
import cof.co_time as CoTimeM
import cof.file as CoFileM

import types    # by linsixiao

app_loc = CoFileM.get_app_loc()


# ------------------------------------------------------------------------
# The redirectors below are used to capture output during testing. Output
# sent to sys.stdout and sys.stderr are automatically captured. However
# in some cases sys.stdout is already cached before HTMLTestRunner is
# invoked (e.g. calling logging.basicConfig). In order to capture those
# output, use the redirectors for the cached stream.
#
# e.g.
#   >>> logging.basicConfig(stream=HTMLTestRunner.stdout_redirector)
#   >>>


class OutputRedirector(object):
Ejemplo n.º 8
0
def get_cfg_type_path():
    filepath = cofFile.get_app_loc() + 'cfgtype.ini'
    return filepath