import unittest
from blueprints.settings import testConfig
from blueprints.requestResult import requestResult
from blueprints.tools.asertcase import asertcase
from blueprints.tools.dealCasefile import readCaseFile
class maintest(unittest.TestCase):
   def __init__(self, methodName='runTest', config=None):
       super(maintest, self).__init__(methodName)
       self.config = config
   @staticmethod
   def parametrize(testcase_klass, config=None):
       testloader = unittest.TestLoader()
       testnames = testloader.getTestCaseNames(testcase_klass) 
       suite = unittest.TestSuite()
       for name in testnames:
           print('name====',name)
           suite.addTest(testcase_klass(name, config=config))
       return suite

class koala_risk0(maintest):
   def test_100(self):
       res1=requestResult(self.config,'/Users/jiazhaopu/QGjobs/autointerface/testCase/koala_risk/699.json')
       res,finalresult=res1.requestJson()
       t=readCaseFile('/Users/jiazhaopu/QGjobs/autointerface/testCase/koala_risk/699.json').get('result')
       r=0 if 0 in finalresult and len(finalresult)>0 else 1
       if r:
           self.detail=res1.keyoption()+('Success',)
       else:
           if isinstance(res,dict):
               self.detail=res1.keyoption()+(res.__str__(),)
           elif len(res.text)>5000 :
               self.detail=res1.keyoption()+('响应数据过长',)
           else:
               self.detail=res1.keyoption()+(res.text,)
       if r==0:
           msg='断言失败，预期结果：'+str(t)+',实际结果查看响应数据'
           self.assertEqual(1, 0,msg=msg)
       else :
           msg='断言成功，预期结果：'+str(t)+',实际结果查看响应数据'
           self.assertEqual(0, 0,msg=msg)

class usercenter1(maintest):
   def test_100(self):
       res1=requestResult(self.config,'/Users/jiazhaopu/QGjobs/autointerface/testCase/usercenter/500.json')
       res,finalresult=res1.requestJson()
       t=readCaseFile('/Users/jiazhaopu/QGjobs/autointerface/testCase/usercenter/500.json').get('result')
       r=0 if 0 in finalresult and len(finalresult)>0 else 1
       if r:
           self.detail=res1.keyoption()+('Success',)
       else:
           if isinstance(res,dict):
               self.detail=res1.keyoption()+(res.__str__(),)
           elif len(res.text)>5000 :
               self.detail=res1.keyoption()+('响应数据过长',)
           else:
               self.detail=res1.keyoption()+(res.text,)
       if r==0:
           msg='断言失败，预期结果：'+str(t)+',实际结果查看响应数据'
           self.assertEqual(1, 0,msg=msg)
       else :
           msg='断言成功，预期结果：'+str(t)+',实际结果查看响应数据'
           self.assertEqual(0, 0,msg=msg)

class risk2(maintest):
   def test_100(self):
       res1=requestResult(self.config,'/Users/jiazhaopu/QGjobs/autointerface/testCase/risk/651.json')
       res,finalresult=res1.requestJson()
       t=readCaseFile('/Users/jiazhaopu/QGjobs/autointerface/testCase/risk/651.json').get('result')
       r=0 if 0 in finalresult and len(finalresult)>0 else 1
       if r:
           self.detail=res1.keyoption()+('Success',)
       else:
           if isinstance(res,dict):
               self.detail=res1.keyoption()+(res.__str__(),)
           elif len(res.text)>5000 :
               self.detail=res1.keyoption()+('响应数据过长',)
           else:
               self.detail=res1.keyoption()+(res.text,)
       if r==0:
           msg='断言失败，预期结果：'+str(t)+',实际结果查看响应数据'
           self.assertEqual(1, 0,msg=msg)
       else :
           msg='断言成功，预期结果：'+str(t)+',实际结果查看响应数据'
           self.assertEqual(0, 0,msg=msg)

class koala_risk3(maintest):
   def test_100(self):
       res1=requestResult(self.config,'/Users/jiazhaopu/QGjobs/autointerface/testCase/koala_risk/709.json')
       res,finalresult=res1.requestJson()
       t=readCaseFile('/Users/jiazhaopu/QGjobs/autointerface/testCase/koala_risk/709.json').get('result')
       r=0 if 0 in finalresult and len(finalresult)>0 else 1
       if r:
           self.detail=res1.keyoption()+('Success',)
       else:
           if isinstance(res,dict):
               self.detail=res1.keyoption()+(res.__str__(),)
           elif len(res.text)>5000 :
               self.detail=res1.keyoption()+('响应数据过长',)
           else:
               self.detail=res1.keyoption()+(res.text,)
       if r==0:
           msg='断言失败，预期结果：'+str(t)+',实际结果查看响应数据'
           self.assertEqual(1, 0,msg=msg)
       else :
           msg='断言成功，预期结果：'+str(t)+',实际结果查看响应数据'
           self.assertEqual(0, 0,msg=msg)
   def test_101(self):
       res1=requestResult(self.config,'/Users/jiazhaopu/QGjobs/autointerface/testCase/koala_risk/753.json')
       res,finalresult=res1.requestJson()
       t=readCaseFile('/Users/jiazhaopu/QGjobs/autointerface/testCase/koala_risk/753.json').get('result')
       r=0 if 0 in finalresult and len(finalresult)>0 else 1
       if r:
           self.detail=res1.keyoption()+('Success',)
       else:
           if isinstance(res,dict):
               self.detail=res1.keyoption()+(res.__str__(),)
           elif len(res.text)>5000 :
               self.detail=res1.keyoption()+('响应数据过长',)
           else:
               self.detail=res1.keyoption()+(res.text,)
       if r==0:
           msg='断言失败，预期结果：'+str(t)+',实际结果查看响应数据'
           self.assertEqual(1, 0,msg=msg)
       else :
           msg='断言成功，预期结果：'+str(t)+',实际结果查看响应数据'
           self.assertEqual(0, 0,msg=msg)
   def test_102(self):
       res1=requestResult(self.config,'/Users/jiazhaopu/QGjobs/autointerface/testCase/koala_risk/671.json')
       res,finalresult=res1.requestJson()
       t=readCaseFile('/Users/jiazhaopu/QGjobs/autointerface/testCase/koala_risk/671.json').get('result')
       r=0 if 0 in finalresult and len(finalresult)>0 else 1
       if r:
           self.detail=res1.keyoption()+('Success',)
       else:
           if isinstance(res,dict):
               self.detail=res1.keyoption()+(res.__str__(),)
           elif len(res.text)>5000 :
               self.detail=res1.keyoption()+('响应数据过长',)
           else:
               self.detail=res1.keyoption()+(res.text,)
       if r==0:
           msg='断言失败，预期结果：'+str(t)+',实际结果查看响应数据'
           self.assertEqual(1, 0,msg=msg)
       else :
           msg='断言成功，预期结果：'+str(t)+',实际结果查看响应数据'
           self.assertEqual(0, 0,msg=msg)

