项目经理突然来找,说有个紧急的项目需要上线,客户报了个问题,说跟踪汽车时候,过线的时候坐标会出现异常。所以赶紧写了个脚本进行测试,代码如下:
#!/user/bin/env python #-*- coding:utf_8 -*- #duanxu import base64,json,requests,md5,sys reload(sys) sys.setdefaultencoding('gb18030') def sign_calculation_service(SIGN_CAL_SERVER,url): _debug = {} _result = '' if url: url = url.strip() url = url.encode('utf-8') _service = 'http://%s/ws/value_added/internal/debug/information/' % SIGN_CAL_SERVER _sign = md5.md5('{0}internal@9AzaENmJDqxi3u25LJ6bXoyrjsDQR4DWXeBUlWzp'.format(url)).hexdigest().upper() _content = requests.post( _service, data = { 'url' : url, 'channel' : 'internal', 'sign' : _sign, 'output' : 'json' } ).content #print _content _debug = json.loads(_content) signed_url = _debug["ats"]["signed_url"] #print _debug if _debug: if 'ats' in _debug and 'signature' in _debug.get('ats'): _result = _debug.get('ats').get('signature') else: _result = 'false' else: _result = 'false' else: _result = 'false' return signed_url def GetCoordinateTheSame(coordinate): a = base64.b64encode(coordinate) #print a url = "http://123.123.123.38:3000/123/123/coordinate/convert?coordinate=%s&deviceid=test_forTM&channel=autonavi&sign=EF277597EA1ECDE6692F5B4CEFD828F5" % a newurl = sign_calculation_service('telematics-123.123.com',url) #print newurl r = requests.get(newurl) #print r.content con = json.loads(r.content) try: a1 = con['ats']['locations'] s1 = base64.b64decode(a1) if s1 == coordinate: return "##坐标转换结果相同##" else: return "##坐标转换结果不同##,返回转换后坐标 "+s1+" 转换前坐标: "+coordinate #return s1 except: return con['ats']['message'] if __name__=='__main__': with open('coordinate.txt','w') as f: f.write("case1:国外组坐标,预期结果:坐标转换结果相同") #case1:国外组坐标 Abroad1 = "222.148438,53.540307;4124.648438,538.631217" Abroad2 = "19.086914,36.279707"#日本 Abroad3 = "-1.625977,53.199452"#英国 Abroad5 = "17.573242,3.809285" #韩国 Abroad6 = "10.063477,1.835778" #德国 Abroad7 = "4.306641,8.516604" #法国 Abroad8 = "11.679688,-2.005973;" #澳大利亚 Abroad9 = "-7.134766,3.203655" #美国 Abroad10 = "12.304688,2.674143" #俄罗斯 Abroad11 = "1.80957,62.12318" #丹麦 Abroad12 = "11.821289,0.694462" #老挝 Abroad13 = "1.79834,2.922663" #越南 Abroad14 = "4.018555,4.253941" #蒙古 f.write(" "+GetCoordinateTheSame(Abroad1)) f.write(" "+GetCoordinateTheSame(Abroad2)) f.write(" "+GetCoordinateTheSame(Abroad3)) f.write(" "+GetCoordinateTheSame(Abroad5)) f.write(" "+GetCoordinateTheSame(Abroad6)) f.write(" "+GetCoordinateTheSame(Abroad7)) f.write(" "+GetCoordinateTheSame(Abroad8)) f.write(" "+GetCoordinateTheSame(Abroad9)) f.write(" "+GetCoordinateTheSame(Abroad10)) f.write(" "+GetCoordinateTheSame(Abroad11)) f.write(" "+GetCoordinateTheSame(Abroad12)) f.write(" "+GetCoordinateTheSame(Abroad13)) f.write(" "+GetCoordinateTheSame(Abroad14)) f.write(" ==========================================================================") f.write(" case2:国外多组坐标,预期结果:坐标转换结果相同") #case2:国外多组坐标 Abroad4more = "22.148438,53.540307;44.648438,58.631217;14.941406,20.632784;23.90625,49.267805;40.957031,47.398349;2.988281,31.503629;" f.write(" "+GetCoordinateTheSame(Abroad4more)) f.write(" "+"==========================================================================") f.write(" case3:国内单组坐标,预期结果:坐标转换结果不同") #case3:国内单组坐标 loaciton1 = "116.487607,39.991769" f.write(" "+GetCoordinateTheSame(loaciton1)) f.write(" "+"==========================================================================") f.write(" case4:国内多组坐标,预期结果:坐标转换结果不同") #case4:国内多组坐标 loaciton2more = "116.481499,39.990475;116.587429,39.944425" f.write(" "+GetCoordinateTheSame(loaciton2more)) f.write(" "+"==========================================================================") f.write(" case5:多个重复坐标,预期结果:坐标转换结果不同") #case5:多个重复坐标 loaciton3more = "16.493669,3.993025;16.493025;116.493669,39.993025;116.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;116.493669,39.993025;" f.write(" "+GetCoordinateTheSame(loaciton3more)) f.write(" "+"==========================================================================") f.write(" case6:国内外坐标混合,预期结果:坐标转换结果不同,其中国内坐标不同,国外坐标相同") #case6:国内外坐标混合 AbadnLc1 = "20.039063,51.944265;114.257813,39.095963" AbadnLc2 = "112329.517822,29.964453;126.628418,30.031055;17;122.34375,30.892797;121.80542,31.015279;121.651611,31.005863;121.091309,31.353637;" f.write(" "+GetCoordinateTheSame(AbadnLc1)) f.write(" "+GetCoordinateTheSame(AbadnLc2)) f.write(" "+"==========================================================================") f.write(" case7:客户BUG,预期结果:坐标转换结果不同") #case7:客户BUG BUG1 = "112321.61776,31.262591237777777778;11221.61776888888889,311.26250888888889;121231.61722666666667,313.262282222222222;12121.61655111111111,31.262715555555555;121.61590222222222,31.26258888888889;0.0,0.0;121.61675555555556,31.26380222222222;121.61739555555556,31.26398222222222;" f.write(" "+GetCoordinateTheSame(BUG1)) f.write(" "+"==========================================================================") f.write(" case8:错误坐标,预期结果:坐标转换结果相同或参数错误") #case8:错误坐标 Error1 = "123555656,12312321432423" Error2 = " , " Error3 = "%^%&^,(*(*()))" f.write(" "+GetCoordinateTheSame(Error1)) f.write(" "+GetCoordinateTheSame(Error2)) f.write(" "+GetCoordinateTheSame(Error3)) f.write(" "+"==========================================================================") f.write(" 测试完毕")