Example #1
0
 def __init__(self):
         #读取并配置接口服务器IP,端口等信息
     self.http = ConfigHttp('../http_config.ini')
         #读取并配置数据库服务器IP,端口等信息
     self.db =GetDB('../db_config.ini', 'DATABASE')
         # 读取运行模式配置
     self.run_mode_config = ConfigRumMode('../run_case_config.ini')
Example #2
0
    def __init__(self):
        #读取并配置接口服务器ip,端口等信息
        self.http = ConfigHttp('./InterfaceAuto/src/config/http_config.ini')
        #        print self.http

        #读取并配置数据库服务器ip,端口等信息
        self.db = ConfigDB('./InterfaceAuto/src/config/db_config.ini',
                           'DATABASE1')

        #读取运行模式
        self.run_mode = ConfigRunMode(
            '/InterfaceAuto/src/config/case_config.ini')
Example #3
0
    def __init__(self):
        # 读取并配置接口服务器IP,端口等信息,生成self.http对象
        # 由ConfigHttp类实例化的http对象,都直接用类中的方法和属性
        # 方法get/post等,可扩展
        # 属性protocol/host/port/headers
        self.http = ConfigHttp('./config/config.ini')

        # 读取并配置数据库服务器IP,端口等信息,生成self.db对象
        # self.db的可用方法有get_conn,返回数据库连接句柄进行后续操作
        # DATABASE是db_config.ini里的section名,因为可能会涉及多个数据库配置section,这里必须外部手动传参
        self.db = GetDB('./config/config.ini', 'DATABASE')

        # 读取运行模式配置,生成self.run_mode_config对象
        # self.run_mode_config对象的可用方法有get_run_mode、get_case_list
        self.run_mode_config = ConfigRunMode('./config/config.ini')
Example #4
0
class TestInterfaceCase(unittest.TestCase):
    def setUp(self):
        self.config_http = ConfigHttp(base_http.get_host(), base_http.get_port())

    # 测试接口1
    def test_get_diffcheckcode(self):
        # 根据被测接口的实际情况,合理的添加HTTP头
        header = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                  'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; rv:29.0) Gecko/20100101 Firefox/29.0'
                  }
        self.config_http.set_header(header)

        response = self.config_http.get(test_data.url, test_data.params)
        json_response = json.loads(response)
        if {} == response:
            test_data.result = 'Error'
            html_report.error_num += 1
            return
        try:
            self.assertEqual(json_response['success'], test_data.Expectation, resMsg='ture')
            test_data.result = 'Pass'
            html_report.success_num += 1
        except AssertionError:
            test_data.result = 'Fail'
            html_report.fail_num += 1

    # 测试接口2
    def test_get_checkcode(self):
        header = {'Content-Type': 'application/json', 'charset': 'utf-8'}
        self.config_http.set_header(header)
        response = self.config_http.post(test_data.url, test_data.params)
        json_response = json.loads(response)

        if {} == response:
            test_data.result = 'Error'
            html_report.error_num += 1
            return
        try:

            self.assertEqual(json_response["success"],test_data.expected_result)
            test_data.result = 'Pass'
            html_report.success_num += 1
        except AssertionError:
            test_data.result = 'Fail'
            html_report.fail_num += 1

    def tearDown(self):
        pass
Example #5
0
 def setUp(self):
     self.config_http = ConfigHttp(base_http.get_host(), base_http.get_port())
Example #6
0
 def __init__(self):
     self.http = ConfigHttp()
     self.run_mode_config = ConfigRunMode()