def test_get_event_list_eid_success(self):
        ''' 根据 eid 查询结果成功 '''
        r = requests.get(self.base_url, params={'eid': 1})
        self.result = r.json()
        self.assertEqual(self.result['status'], 200)
        self.assertEqual(self.result['message'], 'success')
        # self.assertEqual(self.result['data']['name'],u'红米Pro发布会')
        # self.assertEqual(self.result['data']['address'],u'北京会展中心')

    def test_get_event_list_nam_result_null(self):
        ''' 关键字‘abc’查询 '''
        r = requests.get(self.base_url, params={'name': 'abc'})
        self.result = r.json()
        self.assertEqual(self.result['status'], 10022)
        self.assertEqual(self.result['message'], 'query result is empty')

    def test_get_event_list_name_find(self):
        ''' 关键字‘发布会’模糊查询 '''
        r = requests.get(self.base_url, params={'name': '发布会'})
        self.result = r.json()
        self.assertEqual(self.result['status'], 200)
        self.assertEqual(self.result['message'], 'success')
        # self.assertEqual(self.result['data'][0]['name'],u'红米Pro发布会')
        # self.assertEqual(self.result['data'][0]['address'],u'北京会展中心')


if __name__ == '__main__':
    test_data.init_data()  # 初始化接口测试数据
    unittest.main()
        self.assertEqual(self.result['message'], 'event id already exists')

    def test_add_event_name_exist(self):
        payload = {'eid': 13, 'name': '红米 Pro 发布会', 'limit': 2000,
                   'address': "北京水立方", 'start_time': '2017', 'csrfmiddlewaretoken': self.csrf_token}
        r = self.s.post(self.base_url, data=payload)
        self.result = r.json()
        self.assertEqual(self.result['status'], 10023)
        self.assertEqual(self.result['message'], 'event name already exists')

    def test_add_event_data_type_error(self):
        payload = {'eid': 12, 'name': '一加 5 手机发布会', 'limit': 1000,
                   'address': "北京土立方", 'start_time': '2018', 'csrfmiddlewaretoken': self.csrf_token}
        r = self.s.post(self.base_url, data=payload)
        self.result = r.json()
        self.assertEqual(self.result['status'], 10024)
        self.assertIn('start_time format error.', self.result['message'])

    def test_add_event_success(self):
        payload = {'eid': 14, 'name': '一加 6 手机发布会', 'limit': 2500,
                   'address': "北京风立方", 'start_time': '2018-01-10 12:00:00', 'csrfmiddlewaretoken': self.csrf_token}
        r = self.s.post(self.base_url, data=payload)
        self.result = r.json()
        self.assertEqual(self.result['status'], 200)
        self.assertEqual(self.result['message'], 'add event success')


if __name__ == '__main__':
    test_data.init_data()  # 初始化接口测试数据
    unittest.main()
示例#3
0
        data = {'eid':1,'phone':'123456'}
        r = requests.post(self.base_url,data=data)
        self.result = r.json()
        self.assertEqual(self.result['status'],10026)
        self.assertEqual(self.result['message'],'此手机号没有参加该发布会')


    # 用户已签到
    def test_user_sign_true(self):
        """用户已签到"""
        data = {'eid': 5, 'phone': '12345'}
        r = requests.post(self.base_url, data=data)
        self.result = r.json()
        self.assertEqual(self.result['status'], 10027)
        self.assertEqual(self.result['message'], '此手机号已经签到')


    def test_user_sign_sucess(self):
        """签到成功"""
        data = {'eid': 1, 'phone': '12345'}
        r = requests.post(self.base_url, data=data)
        self.result = r.json()
        self.assertEqual(self.result['status'], 200)
        self.assertEqual(self.result['message'], '签到成功')



if __name__=='__main__':
    init_data()#初始化接口测试数据
    print('没进去')
    unittest.main()
示例#4
0
            'limit': 200,
            'address': '中关村',
            'start_time': '2018'
        }
        r = requests.post(self.base_url, data=payload)
        self.result = r.json()
        self.assertEqual(self.result['status'], 10024)
        self.assertIn('start_time format error.', self.result['message'])

    def test_add_event_success(self):
        '''添加成功'''
        payload = {
            'eid': 6,
            'name': '红米100发布会',
            'limit': 200,
            'address': '中关村',
            'start_time': '2018-5-1 12:00:00'
        }
        r = requests.post(self.base_url, data=payload)
        self.result = r.json()
        self.assertEqual(self.result['status'], 2001)
        self.assertEqual(self.result['message'], 'add event success')

    def tearDown(self):
        print(self.result)


if __name__ == '__mian__':
    test_data.init_data()
    unittest.main()
def setUpModule():
    test_data.init_data()  # 初始化测试数据
示例#6
0
    def test_add_event_date_type_error(self):
        '''时间格式错误'''
        payload = {
            'eid': 1,
            'name': '华为P20发布会',
            'limit': '200',
            'address': '深圳宝体',
            'start_time': '2019'
        }
        r = requests.post(self.base_url, data=payload)
        self.result = r.json()
        self.assertEqual(self.result['status'], 10024)
        self.assertIn('start_time format error.', self.result['message'])

    def test_add_event_success(self):
        payload = {
            'eid': 5,
            'name': '华为P20发布会',
            'limit': '200',
            'address': '深圳宝体',
            'start_time': '2019-08-09 12:00:00'
        }
        r = requests.post(self.base_url, data=payload)
        self.result = r.json()
        self.assertEqual(self.result['status'], 200)
        self.assertEqual(self.result['message'], 'add event success')


if __name__ == '__main__':
    test_data.init_data()  #初始化数据
    unittest.main()
示例#7
0
# conding=utf-8
from HTMLTestRunner import HTMLTestRunner
import unittest, time, os
from db_fixture import test_data

# 指定测试用例为当前文件夹下的interface目录
dir = os.path.dirname(__file__)
test_dir = dir + "/interface"
discover = unittest.defaultTestLoader.discover(test_dir, pattern="*_test.py")

if __name__ == '__main__':
    test_data.init_data()  # 初始化接口数据

    now = time.strftime("%Y-%m-%d %H-%M-%S")
    filename = dir + "/report/" + now + "_result.html"
    fp = open(filename, 'wb')
    runner = HTMLTestRunner(stream=fp, title='我的测试报告', description='测试用例执行情况')
    runner.run(discover)
    fp.close()
示例#8
0
        '''name为空'''
        payload = {'eid': '1', 'name': ''}
        self.result = requests.get(self.url, params=payload)
        r = self.result.json()
        self.assertEqual(r['status'], 200)
        self.assertEqual(r['message'], 'success')

    def test_id_error(self):
        '''id不存在'''
        payload = {'eid': 1000, 'name': ''}
        self.result = requests.get(self.url, params=payload)
        r = self.result.json()
        self.assertEqual(r['status'], 10022)
        self.assertEqual(r['message'], 'query result is empty')

    def test_name_error(self):
        '''name不存在'''
        payload = {'eid': '', 'name': '!@#'}
        self.result = requests.get(self.url, params=payload)
        r = self.result.json()
        self.assertEqual(r['status'], 10022)
        self.assertEqual(r['message'], 'query result is empty')

    def tearDown(self):
        print(self.result)


if __name__ == '__main__':
    init_data()
    unittest.main()
示例#9
0
            'name': 'Requests常用API讲解',
            'limit': 200,
            'address': "会议室2",
            'start_time': '2017'
        }
        r = requests.post(self.base_url, data=payload)
        self.result = r.json()
        self.assertEqual(self.result['status'], 10024)
        self.assertIn('start_time format error.', self.result['message'])

    def test_add_event_success(self):
        """
        添加成功
        """
        payload = {
            'eid': 11,
            'name': 'Requests常用API讲解',
            'limit': 200,
            'address': "会议室2",
            'start_time': '2017-11-10 12:00:00'
        }
        r = requests.post(self.base_url, data=payload)
        self.result = r.json()
        self.assertEqual(self.result['status'], 200)
        self.assertEqual(self.result['message'], 'add event success')


if __name__ == '__main__':
    test_data.init_data()  # 初始化接口测试数据(test_data中的datas)
    unittest.main()