class TestMethod(unittest.TestCase):
    def setUp(self):
        self.run = RunMain()

    def test_01(self):
        url = 'https://coding.imooc.com/api/prelearn'
        data = {
            'token': '0e1f9768a6de44ad3f62f3f809241c36',
            'timestamp': '1551773496894',
            'uid': '1914562',
            'cid': '309',
            'secrect': '906108abe9d6dda2bf2a515f0301a017',
            'apiname': 'prelearn'
        }
        res = self.run.run_main(url, 'GET', data).json()
        res = self.assertEqual(res['errorCode'], 1007, '测试失败')
        print(res)
        print('这是第一个case')

    def test_02(self):
        url = 'https://coding.imooc.com/api/prelearn'
        data = {
            'token': '0e1f9768a6de44ad3f62f3f809241c36',
            'timestamp': '1551773496894',
            'uid': '1914561',
            'cid': '309',
            'secrect': '906108abe9d6dda2bf2a515f0301a017',
            'apiname': 'prelearn'
        }
        res = self.run.run_main(url, 'POST', data).json()
        res = self.assertEqual(res['errorCode'], 1007, '测试失败')
        print(res)
        print('这是第二个case')
示例#2
0
class TestMethod(unittest.TestCase):
    def setUp(self):
        self.rm = RunMain()

    #获取雇员列表
    def test_01(self):
        url = 'https://stargate.ar.elenet.me/delimont.saas_tnt/employee/list'
        data = "{\"index\": 1,\"limit\": 10,\"total\": 10,\"pageName\": 3}\n"
        res = self.rm.run_main(url, 'POST', data)
        print json.dumps(res).decode('unicode-escape')
        self.assertEqual(res['code'].encode('utf8'), '200', '测试失败')

    #添加初始雇员
    def test_02(self):
        url = 'https://stargate.ar.elenet.me/delimont.saas_tnt/employee/addInitEmployee'
        data = "{\"employee\": {\"tenantId\": 100,\"name\": \"黄就品\",\"account\": \"[email protected]\",\"gender\": -1,\"email\": \"[email protected]\",\"phone\": \"18765639876\"}}\n"
        res = self.rm.run_main(url, 'POST', data)
        print json.dumps(res).decode('unicode-escape')
        self.assertEqual(res['code'].encode('utf8'), '200')

    #获取雇员信息根据雇员id
    def test_03(self):
        url = 'https://stargate.ar.elenet.me/delimont.saas_tnt/employee/get'
        data = "{\"employeeId\": 571}"
        res = self.rm.run_main(url, 'POST', data)
        print json.dumps(res).decode('unicode-escape')
        self.assertEqual(res['code'], '200')
class TestMethod(unittest.TestCase):
    def setUp(self):
        self.run = RunMain()

    def test_01(self):
        url = 'http://learnta.cn/auth/user/loginOrgStudent'
        headers = {
            'Content-Type': 'application/json',
            'Authorization': 'Bearer 51cbd981-f540-3e05-aeaf-2c232c1950c4'
        }
        data = {
            "username": "******",
            "password": "******",
            "systemId": 4,
            "orgId": 1
        }
        res = self.run.run_main(url, headers, 'POST', data)
        self.assertEqual(res['code'], '0', "测试失败")

    #@unittest.skip('test_02')  # 跳过case2
    def test_02(self):
        url = 'http://learnta.cn/auth/user/loginOrgStudent'
        headers = {
            'Content-Type': 'application/json',
            'Authorization': 'Bearer 51cbd981-f540-3e05-aeaf-2c232c1950c4'
        }
        data = {
            "username": "******",
            "password": "******",
            "systemId": 4,
            "orgId": 1
        }
        res = self.run.run_main(url, headers, 'POST', data)
        self.assertEqual(res['code'], '0', "测试失败")
示例#4
0
class TestMethod(unittest.TestCase):
    def setUp(self):
        self.run = RunMain()
        # self.userid = self.test_01()

    def test_03(self):
        data = {
            'timestamp': '1507034803124',
            'uid': '5249191',
            'uuid': '5ae7d1a22c82fb89c78f603420870ad7',
            'secrect': '078474b41dd37ddd5efeb04aa591ec12',
            'token': '7d6f14f21ec96d755de41e6c076758dd',
            'cid': '0',
            'errorCode': 1001,
        }
        # mock_data = mock.Mock(return_value=data)
        # self.run.run_main = mock_data
        url = 'http://coding.imooc.com/api/cate'
        res = mock_test(self.run.run_main, data, url, 'POST', data)

        # res = self.run.run_main(url,'POST',data)
        print(res)
        print('这是第一个case')

        self.assertEqual(res['errorCode'], 1001, '测试失败')

    # @unittest.skip('test_02')
    def test_02(self):

        data = {
            'timestamp': '1507034803124',
            'uid': '5249192',
            'uuid': '5ae7d1a22c82fb89c78f603420870ad7',
            'secrect': '078474b41dd37ddd5efeb04aa591ec12',
            'token': '7d6f14f21ec96d755de41e6c076758dd',
            'cid': '0',
            'errorCode': '1001',
        }
        url = 'http://coding.imooc.com/api/cate'
        res = self.run.run_main(url, 'POST', data)
        self.assertEqual(res['errorCode'], 1003, '测试失败')
        print('这是第二个case')

    def test_01(self):
        data = {
            'timestamp': '1507034803124',
            'uid': '5249192',
            'uuid': '5ae7d1a22c82fb89c78f603420870ad7',
            'secrect': '078474b41dd37ddd5efeb04aa591ec12',
            'token': '7d6f14f21ec96d755de41e6c076758dd',
            'cid': '0',
            'errorCode': '1001',
        }
        url = 'http://coding.imooc.com/api/cate'
        res = self.run.run_main(url, 'POST', data)
        self.assertEqual(res['errorCode'], 1003, '测试失败')
        print('这是第二个case')
示例#5
0
class Testmethod(unittest.TestCase):
	@classmethod
	def setUpClass(cls):
		print('setUpClass')
	@classmethod
	def tearDownClass(cls):
		print('tearDownClass')

	def setUp(self):
		self.run = RunMain()

	def tearDown(self):
		print('tearDown')

	def test_01(self):
		url1 = 'https://m.imooc.com/wap/api/course/loadCourseList?marking=all&course_type=0&easy_type=&order=2&pageIndex=1&flag=&ex_learned=0'
		data1 = {'marking':'all',
				'course_type':0,
				'easy_type':'',	
				'order':2,
				'pageIndex':1,
				'flag':'',	
				'ex_learned':0,}

		res=self.run.run_main(url1,'POST',data1)
		
		self.assertEqual(res['code'],200,'测试成功')
		globals()['user_id']='1203818'

	#@unittest.skip('test_02')  #跳过该案例
	def test_02(self):
		print(user_id)
		url2 = 'https://m.imooc.com/api/search/searchword'
		res=self.run.run_main(url2,'GET')
		
		self.assertEqual(res['errorCode'],1000,'测试成功')
		#self.assertNotEqual(res['errorCode'],1001,'测试成功')

	#mock方法
	def test_03(self):
		url1 = 'https://m.imooc.com/wap/api/course/loadCourseList?marking=all&course_type=0&easy_type=&order=2&pageIndex=1&flag=&ex_learned=0'
		data1 = {'marking':'all',
				'course_type':0,
				'easy_type':'',	
				'order':2,
				'pageIndex':1,
				'flag':'',	
				'ex_learned':0,}

		res = mock_test(self.run.run_main,data1,url1,'POST',data1)
		#self.run.run_main = mock.Mock(return_value=data1)
		#res=self.run.run_main(url1,'POST',data1)
		print(res)
		
		self.assertEqual(res['ex_learned'],0,'测试成功')
示例#6
0
class TestMethod(unittest.TestCase):
    def setUp(self):
        self.run = RunMain()

    def test_01(self):  #测试用例的名称以test开头
        url = 'http://scmbase.loongjoy.com/api/auth/postToken'
        data = {
            'fromSys': 'scmpcapp',
            'lang': 'zh',
            'nickname': 'plat_yxj',
            'password': '******'
        }
        res = self.run.run_main(url, 'POST', data)
        # print(res) #返回结果
        #添加断言,如果失败返回message
        self.assertEqual(res['status'], 0, '测试失败')
        print('测试用例01')

    # @unittest.skip('test_02')  #跳过测试用例
    def test_02(self):
        url = 'http://scmbase.loongjoy.com/api/auth/postToken'
        data = {
            'fromSys': 'scmpcapp',
            'lang': 'zh',
            'nickname': 'plat06',
            'password': '******'
        }
        res = self.run.run_main(url, 'POST', data)
        # print(res) #返回结果
        #添加断言,如果失败返回message
        self.assertEqual(res['status'], 0, '测试失败')
        print('测试用例02')

    #mock 练习
    def test_03(self):
        url = 'http://scmbase.loongjoy.com/api/auth/postToken'
        data = {
            'fromSys': 'scmpcapp',
            'lang': 'zh',
            'nickname': 'plat06',
            'password': '******'
        }
        """
            #mock未封装时的方法
            mock_data = mock.Mock(return_value= data)
            self.run.run_main = mock_data
            res = self.run.run_main(url,'POST',data)
            """
        #mock封装后的方法
        res = mock_test(self.run.run_main, data, url, 'POST', data)

        print(res)  #返回结果
        #添加断言,如果失败返回message
        self.assertEqual(res['lang'], 'zh', '测试失败')
        print('测试用例03')
示例#7
0
class TestMethod(unittest.TestCase):
    def setUp(self):
        self.run = RunMain()

    def test_01(self):
        url = 'http://coding.imooc.com/api/cate'
        data = {
            'timestamp': '1507034803124',
            'uid': '5249191',
            'uuid': '5ae7d1a22c82fb89c78f603420870ad7',
            'secrect': '078474b41dd37ddd5efeb04aa591ec12',
            'token': '7d6f14f21ec96d755de41e6c076758dd',
            'cid': '0',
            'errorCode': 1001
        }
        # mock_data = mock.Mock(return_value=data)
        # print(mock_data)
        # self.run.run_main = mock_data
        res = mock_test(self.run.run_main, data, url, 'POST', data)
        # res = self.run.run_main(url,'POST', data)
        print(res)
        self.assertEqual(res['errorCode'], 1001, '测试失败')
        print('这是第一个case')

    def test_02(self):
        url = 'http://www.imooc.com/m/web/shizhanapi/loadmorepingjia.html?cart=11'
        data = {'cart': '11'}
        res = self.run.run_main(url, 'GET', data)
        print(res)
        self.assertEqual(res['code'], 200, '测试失败')
        print('这是第二个case')
示例#8
0
class TestMethod(unittest.TestCase):

    def setUp(self):
        self.run = RunMain()

    def tearDown(self):
        print('tearDown')

    def test_01(self):
        data = {
            "weatherinfo": {
                "city": "\u00e5\u008c\u0097\u00e4\u00ba\u00ac",
                "cityid": "101010102",
                "img1": "n1.gif",
                "img2": "d2.gif",
                "ptime": "18:00",
                "temp1": "18\u00e2\u0084\u0083",
                "temp2": "31\u00e2\u0084\u0083",
                "weather": "\u00e5\u00a4\u009a\u00e4\u00ba\u0091\u00e8\u00bd\u00ac\u00e9\u0098\u00b4"
            }
        }
        url = 'http://www.weather.com.cn/data/cityinfo/101010100.html'                
        
        # mock返回的数据
        # mock_data = mock.Mock(return_value = data)
        # print(mock_data)
        # self.run.run_main = mock_data

        # 单独封装的mock方法
        mock_test(self.run.run_main,url,'GET',data)

        req = self.run.run_main(url,'GET')
        # print(req['weatherinfo']['cityid'])
        self.assertEqual(req['weatherinfo']['cityid'],'101010102','正确的代码')
示例#9
0
 def test_02(self):
     url = "http://web-api-test.energymost.com/api/vee/getscanswitch"
     data = {"hierarchyId": 353069}
     method = "get"
     run = RunMain()
     r = run.run_main(url, method, data)
     print "第二个case\n"
     print r.status_code
示例#10
0
class TestMethod(unittest.TestCase):
    def setUp(self):
        self.run = RunMain()

    def test_01(self):
        url = "http://106.75.9.19:88/topic/topic_list"
        data = {'page': 2, 'pagesize': 3}
        res = self.run.run_main(url, 'POST', data)
        print(res)
示例#11
0
class RuhrTest(unittest.TestCase):
    def setUp(self):
        self.run = RunMain()

    def test_01(self):
        find_all_station_url = 'http://192.168.1.104:8081/u/community/find/community'
        res = self.run.run_main(find_all_station_url, 'GET')
        print(id)
        print(json.dumps(res, indent=2, sort_keys=True))
        self.assertEqual(res['status'], 'success', '测试失败')
示例#12
0
class TestMethod(unittest.TestCase):
    def setUp(self):

        self.run = RunMain()

    def test_01(self):
        data = {
            'userId': 'bf28e175219d47b1ae8384de50493052',
            'access_token': '1352467890bqfy',
            'pageSize': '100',
            'pageIndex': '1'
        }
        url = 'https://y3zhbh5.zhbservice.com/h5service/personal/productFavoriteList'

        #run=RunMain(url,'POST',data)
        res = self.run.run_main(url, 'POST', data)
        #print (res)
        self.assertEqual(res['access_token'], '1352467890bqfy', "测试不通过")
        globals()['a'] = '123'
        '''
		if res['access_token']=='1352467890bqfy':
			print("测试通过")
		else:
			print("测试不通过")
		'''

    #@unittest.skip('test_02')
    def test_02(self):
        print(a)
        data = {
            'userId': 'bf28e175219d47b1ae8384de50493052',
            'access_token': '1352467890bqfy',
            'pageSize': '100',
            'pageIndex': '1'
        }
        url = 'https://y3zhbh5.zhbservice.com/h5service/personal/productFavoriteList'

        #run=RunMain(url,'POST',data)
        res = self.run.run_main(url, 'POST', data)
        #print (res)
        self.assertEqual(res['access_token'], '1352467890bqfy123', "测试不通过")
        '''
示例#13
0
 def test_02(self):
     url = 'http://open.jeejio.com/developer/aptitude/getAptitudeUserByUserId'
     data = {'createUser': userID}
     headers = \
         {
             "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36",
             "Content-Type": "application/json;charset=UTF-8"
         }
     run = RunMain(url, 'POST', headers, data)
     res = run.run_main(url, 'POST', headers, data).json()
     print(res)
     self.assertEqual(res['statusCode'], 200, '测试失败')
示例#14
0
class TestMethod(unittest.TestCase):
    def setUp(self):
        self.run = RunMain()

    def test_03(self):
        url = 'http://coding.imooc.com/api/cate'
        data = {
            'timestamp': '1507034803124',
            'uid': '5249191',
            'uuid': '5ae7d1a22c82fb89c78f603420870ad7',
            'secrect': '078474b41dd37ddd5efeb04aa591ec12',
            'token': '7d6f14f21ec96d755de41e6c076758dd',
            'cid': '0',
            'errorCode': 1001
        }
        # run=RunMain()   # 调用的demo中的类,赋值为 run
        res = mock_test(self.run.run_main, data, url, 'POST', data)
        # mock_data = mock.Mock(return_value=data)  #把data作为一个mock的返回值
        # print (mock_data)
        # self.run.run_main=mock_data
        res = self.run.run_main(url, 'POST', data)  # 调用demo 中的run_main()方法
        print(res)

    # @unittest.skip('test_02')
    def test_02(self):
        url = 'http://coding.imooc.com/api/cate'
        data = {
            'timestamp': '1507034803124',
            'uid': '5249191',
            'uuid': '5ae7d1a22c82fb89c78f603420870ad7',
            'secrect': '078474b41dd37ddd5efeb04aa591ec12',
            'token': '7d6f14f21ec96d755de41e6c076758dd',
            'cid': '0',
            'errorCode': 1001
        }
        res = self.run.run_main(url, 'POST', data)
        # print (res)  #不能使用loads,因为在demo中已经进行loads了
        res = eval(res)
        self.assertNotEqual(res['errorCode'], 1001, '测试失败')
        print("这是第二个case")
示例#15
0
class TestMethod(unittest.TestCase):
    def setUp(self):
        self.rm = RunMain()

    # 获取雇员列表
    def test_01(self):
        url = 'https://stargate.ar.elenet.me/delimont.saas_tnt/employee/list'
        data = "{\"index\": 1,\"limit\": 10,\"total\": 10,\"pageName\": 3}\n"
        #把data作为返回值
        mock_data = mock.Mock(return_value=data)
        self.rm.run_main = mock_data
        res = self.rm.run_main(url, 'POST', data)
        print res
        #self.assertEqual(res['code'], '200', '测试失败')
        print '这是第一个测试'

    def test_04(self):
        url = 'https://stargate.ar.elenet.me/delimont.saas_tnt/employee/get'
        data = "{\"employeeId\": 571}"
        res = self.rm.run_main(url, 'POST', data)
        self.assertEqual(res['code'], '200', '测试失败')
        print '这是第二个测试'
示例#16
0
 def test_01(self):
     url = 'http://login.jeejio.com/user/users/accountLogin'
     data = {'userKey': '17600253218', 'userPasswd': '1234qwer'}
     headers = \
         {
             "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36",
             "Content-Type": "application/json;charset=UTF-8"
         }
     run = RunMain(url, 'POST', headers, data)
     res = run.run_main(url, 'POST', headers, data).json()
     print(res)
     globals()['userID'] = res['resultValue']['id']
     print(userID)
     self.assertEqual(res['statusCode'], 200, '测试失败')
示例#17
0
class TestMethod(unittest.TestCase):
    def setUp(self):
        self.run = RunMain()

        print('这个是开始执行的方法')

    def tearDown(self):
        print('这个是执行之后的方法')

    def test_01(self):
        url = 'https://sxreader.com:9006/login'
        data = {'username': '******', 'password': '******'}
        res = self.run.run_main(url, 'POST', data)
        self.assertEqual(res['userName'], '232323', '测试失败')
        print(res)
        print(type(res))
示例#18
0
class TestMethod(unittest.TestCase):
    def setUp(self):
        self.run = RunMain()

    def test_03(self):
        url = 'http://coding.imooc.com/api/cate'
        data = {
            'timestamp': '1507034803124',
            'uid': '5249191',
            'uuid': '5ae7d1a22c82fb89c78f603420870ad7',
            'secrect': '078474b41dd37ddd5efeb04aa591ec12',
            'token': '7d6f14f21ec96d755de41e6c076758dd',
            'cid': '0',
            'errorCode': 1001
        }
        #self.run.run_main = mock.Mock(return_value=data)
        res = mock_test(self.run.run_main, data, url, "POST", data)
        #res = self.run.run_main(url,'POST',data)

        print(res)
        self.assertEqual(res['errorCode'], 1001, "测试失败")
        print("这是第一个case")

    #@unittest.skip('test_02')
    def test_02(self):

        url = 'http://coding.imooc.com/api/cate'
        data = {
            'timestamp': '1507034803124',
            'uid': '5249191',
            'uuid': '5ae7d1a22c82fb89c78f603420870ad7',
            'secrect': '078474b41dd37ddd5efeb04aa591ec12',
            'token': '7d6f14f21ec96d755de41e6c076758dd',
            'cid': '0'
        }

        res = self.run.run_main(url, 'POST', data)
        self.assertEqual(res['errorCode'], 1001, "测试失败")
        print("这是第二个case")
        #mock
    def tearDown(self):
        print("当条测试用例结束")
示例#19
0
class TestMethod(unittest.TestCase):
    # @classmethod
    # def setUpClass(cls):  #类方法定义
    #     print "类执行之前的方法"
    #
    # @classmethod
    # def tearDownClass(cls):
    #     print "类执行之后的方法"

    #每次方法前执行
    def setUp(self):
        print 'test-->setup 每次方法前执行'
        self.run = RunMain()

    def test_03(self):
        print "test_03"

    def test_02(self):
        url = "http://web-api-test.energymost.com/api/vee/getscanswitch"
        data = {"hierarchyId": 353069}
        method = "get"
        run = RunMain()
        r = run.run_main(url, method, data)
        print "第二个case\n"
        print r.status_code

    def test_01(self):
        url = "http://web-api-test.energymost.com/api/vee/getdatastructure"
        data = {"UserId": 312135, "CustomerId": 347373}
        method = 'post'
        #run = RunMain(url=url,method="POST",data=data)
        res = self.run.run_main(url, method, data)
        print type(res)
        #self.assertEqual(r.status_code,200)
        print "test_01"
        r = res.status_code
        a = {}
        self.assertEqual(r, 200, "验证是否返回200")  #参数是否相等

    # 每次方法后执行
    def tearDown(self):
        print "test-->tearDown 每次方法后执行"
示例#20
0
class TestMethod(unittest.TestCase):
    def setUp(self):
        self.run = RunMain()
        print('test---->setUp')

    def test_01(self):
        url = 'http://coding.imooc.com/api/cate'
        data = {
            'timestamp': '1507006626132',
            'uid': '5249191',
            'uuid': '5ae7d1a22c82fb89c78f603420870ad7',
            'secrect': '078474b41dd37ddd5efeb04aa591ec12',
            'token': '0b4c502ba647664be04dfedb32ad4f3d',
            'cid': '0',
            'errorCode': 1001
        }
        #mock_data = mock.Mock(return_value=data)
        #self.run.run_main = mock_data
        #res = self.run.run_main(url,'POST',data)

        res = mock_test(self.run.run_main, url, 'POST', data, data)
        print(json.dumps(res, indent=2, sort_keys=True))
        self.assertEqual(res['errorCode'], 1001, '测试失败')
        print('这是第一个测试方法')

    def test_02(self):
        url = 'http://coding.imooc.com/api/cate'
        data = {
            'timestamp': '1507006626132',
            'uid': '5249191',
            'uuid': '5ae7d1a22c82fb89c78f603420870ad7',
            'secrect': '078474b41dd37ddd5efeb04aa591ec12',
            'token': '0b4c502ba647664be04dfedb32ad4f3d',
            'cid': '0'
        }
        res = self.run.run_main(url, 'POST', data)
        print(res)
        print('这是第二个测试方法')

    def tearDown(self):
        print('test---->tearDown')
示例#21
0
class TestMethod(unittest.TestCase):
    def setUp(self):
        self.run = RunMain()

    def test_03(self):
        url = ''
        data = {
            'timestamp': '1507034803124',
            'uid': '5249191',
            'uuid': '5ae7d1a22c82fb89c78f603420870ad7',
            'secrect': '078474b41dd37ddd5efeb04aa591ec12',
            'token': '7d6f14f21ec96d755de41e6c076758dd',
            'cid': '0',
            'errorCode': 1001,
        }
        res = mock_test(self.run.run_main, data, url, 'POST', data)
        # print res
        # 不是xxxx的话 测试失败
        self.assertEqual(res['errorCode'], 1001, '测试失败')
        print '这是第一个case'

    # @unittest.skip('test_02') #←---跳过 xxx 用例
    def test_02(self):
        url = ''
        data = {
            'timestamp': '1507034803124',
            'uid': '5249192',
            'uuid': '5ae7d1a22c82fb89c78f603420870ad7',
            'secrect': '078474b41dd37ddd5efeb04aa591ec12',
            'token': '7d6f14f21ec96d755de41e6c076758dd',
            'cid': '0'
        }
        res = self.run.run_main(url, 'POST', data)
        # print res
        # 不是xxxx的话 测试失败
        self.assertEqual(res['errorCode'], 1000, '测试失败')
        print '这是第二个case'