def test_data_insert_data_Read(self): self.assertIsInstance(self.connection, MySQLdb.connection, "Database connection accurately set") jsondata ={"type":"image", "time":"2014.3.4_14.40.30", "ext":"png", "deviceType":"Mobile", "deviceOS":"Badda", "browsertype":"Firefox", "position":{"lon":25.4583105, "lat":65.0600797, "alt":-1000, "acc":48.38800048828125}, "device":{"ax":0, "ay":0, "az":0, "gx":0, "gy":0, "gz":0, "ra":210.5637, "rb":47.5657, "rg":6.9698, "orientation":"potrait"}, "vwidth":480, "vheight":800} alt = str(jsondata["position"]["alt"]); if alt=="None": alt = '0' heading = '0' speed = '0' width = jsondata["vwidth"] height =jsondata["vheight"] if width > height : screenorientation= 1.00#landscape else : screenorientation= 0.00#potrait filename = jsondata["type"]+"_"+jsondata["time"]+"."+jsondata["ext"] sqlstring1 = "INSERT INTO Imagedata values (\'"+filename+"\',GeomFromText ('POINT("+ str(jsondata["position"]["lat"])+" "+str(jsondata["position"]["lon"])+")'),"+str(jsondata["position"]["alt"])+","+str(jsondata["position"]["acc"]) sqlstring2 =","+str(jsondata["device"]["gx"])+","+str(jsondata["device"]["gy"])+","+str(jsondata["device"]["gz"]) sqlstring3 = ","+str(jsondata["device"]["ra"])+","+str(jsondata["device"]["rb"])+","+str(jsondata["device"]["rg"])+","+str(screenorientation)+",\'"+jsondata["device"]["orientation"]+"\',now(),\'"+str(jsondata["deviceOS"])+"\',\'"+str(jsondata["browsertype"])+"\',\'"+str(jsondata["deviceType"])+"\');" sqlstring = sqlstring1 + sqlstring2+ sqlstring3 #print(sqlstring) es.dbInsert(sqlstring) sqlreadsting = 'select imagename, Browser,devicetype,X(location) as latitude, Y(location) as longitude from Imagedata where time=\'2014.3.4_14.40.31\'' result = es.dbRead(sqlreadsting) self.assertIsNotNone(result, "Inserted data is retrieved and it is not null") for row in result: self.assertEqual(row[0], "image_2014.3.4_14.40.30.png", "Image name is correctly set and saved") self.assertEqual(row[1], 65.0600797, "Latitudes are saved") self.assertEqual(row[2], 25.4583105, "Longitude are saved")
def test_closest_Image_retrieval(self): jsondata1 ={"type":"image", "time":"2014.3.4_14.40.31", "ext":"png", "deviceType":"Mobile", "deviceOS":"Badda", "browsertype":"Firefox", "position":{"lon":25.4583105, "lat":65.0600797, "alt":-1000, "acc":48.38800048828125}, "device":{"ax":0, "ay":0, "az":0, "gx":0, "gy":0, "gz":0, "ra":210.5637, "rb":47.5657, "rg":6.9698, "orientation":"potrait"}, "vwidth":480, "vheight":800} jsondata2 ={"type":"image", "time":"2014.3.4_14.40.32", "ext":"png", "deviceType":"Mobile", "deviceOS":"Badda", "browsertype":"Firefox", "position":{"lon":25.4582115, "lat":65.0600797, "alt":-1000, "acc":48.38800048828125}, "device":{"ax":0, "ay":0, "az":0, "gx":0, "gy":0, "gz":0, "ra":210.5637, "rb":47.5657, "rg":6.9698, "orientation":"potrait"}, "vwidth":480, "vheight":800} jsondata3 ={"type":"image", "time":"2014.3.4_14.40.33", "ext":"png", "deviceType":"Mobile", "deviceOS":"Badda", "browsertype":"Firefox", "position":{"lon":25.4584104, "lat":65.0600797, "alt":-1000, "acc":48.38800048828125}, "device":{"ax":0, "ay":0, "az":0, "gx":0, "gy":0, "gz":0, "ra":210.5637, "rb":47.5657, "rg":6.9698, "orientation":"potrait"}, "vwidth":480, "vheight":800} jsondata4 ={"type":"image", "time":"2014.3.4_14.40.34", "ext":"png", "deviceType":"Mobile", "deviceOS":"Badda", "browsertype":"Firefox", "position":{"lon":25.4586115, "lat":65.0600797, "alt":-1000, "acc":48.38800048828125}, "device":{"ax":0, "ay":0, "az":0, "gx":0, "gy":0, "gz":0, "ra":210.5637, "rb":47.5657, "rg":6.9698, "orientation":"potrait"}, "vwidth":480, "vheight":800} jsondata5 ={"type":"image", "time":"2014.3.4_14.40.35", "ext":"png", "deviceType":"Mobile", "deviceOS":"Badda", "browsertype":"Firefox", "position":{"lon":25.4587125, "lat":65.0600797, "alt":-1000, "acc":48.38800048828125}, "device":{"ax":0, "ay":0, "az":0, "gx":0, "gy":0, "gz":0, "ra":210.5637, "rb":47.5657, "rg":6.9698, "orientation":"potrait"}, "vwidth":480, "vheight":800} jsondata6 ={"type":"image", "time":"2014.3.4_14.40.36", "ext":"png", "deviceType":"Mobile", "deviceOS":"Badda", "browsertype":"Firefox", "position":{"lon":25.4588125, "lat":65.0600797, "alt":-1000, "acc":48.38800048828125}, "device":{"ax":0, "ay":0, "az":0, "gx":0, "gy":0, "gz":0, "ra":210.5637, "rb":47.5657, "rg":6.9698, "orientation":"potrait"}, "vwidth":480, "vheight":800} es.saveData(jsondata1) es.saveData(jsondata2) es.saveData(jsondata3) es.saveData(jsondata4) es.saveData(jsondata5) es.saveData(jsondata6) radius = 0.0001 photoList = es.getClosestImages( 65.0601787, 25.4583107, radius ) self.assertEqual(len(photoList), 4, "Length of the list should be equal of the first test") for row in photoList: assert 'image_2014.3.4_14.40.32.png' or 'image_2014.3.4_14.40.31.png' in row[0] photoList2 = es.getClosestImages( 65.0601787, 25.4587107, radius ) self.assertEqual(len(photoList2), 2, "Length of the list should be equal of the second test") for row in photoList2: assert 'image_2014.3.4_14.40.34.png' or 'image_2014.3.4_14.40.35.png' in row[0]
def setUp(self): self.connection = es.dbConnect()
def test_closest_Image_retrieval(self): jsondata1 = { "type": "image", "time": "2014.3.4_14.40.31", "ext": "png", "deviceType": "Mobile", "deviceOS": "Badda", "browsertype": "Firefox", "position": { "lon": 25.4583105, "lat": 65.0600797, "alt": -1000, "acc": 48.38800048828125 }, "device": { "ax": 0, "ay": 0, "az": 0, "gx": 0, "gy": 0, "gz": 0, "ra": 210.5637, "rb": 47.5657, "rg": 6.9698, "orientation": "potrait" }, "vwidth": 480, "vheight": 800 } jsondata2 = { "type": "image", "time": "2014.3.4_14.40.32", "ext": "png", "deviceType": "Mobile", "deviceOS": "Badda", "browsertype": "Firefox", "position": { "lon": 25.4582115, "lat": 65.0600797, "alt": -1000, "acc": 48.38800048828125 }, "device": { "ax": 0, "ay": 0, "az": 0, "gx": 0, "gy": 0, "gz": 0, "ra": 210.5637, "rb": 47.5657, "rg": 6.9698, "orientation": "potrait" }, "vwidth": 480, "vheight": 800 } jsondata3 = { "type": "image", "time": "2014.3.4_14.40.33", "ext": "png", "deviceType": "Mobile", "deviceOS": "Badda", "browsertype": "Firefox", "position": { "lon": 25.4584104, "lat": 65.0600797, "alt": -1000, "acc": 48.38800048828125 }, "device": { "ax": 0, "ay": 0, "az": 0, "gx": 0, "gy": 0, "gz": 0, "ra": 210.5637, "rb": 47.5657, "rg": 6.9698, "orientation": "potrait" }, "vwidth": 480, "vheight": 800 } jsondata4 = { "type": "image", "time": "2014.3.4_14.40.34", "ext": "png", "deviceType": "Mobile", "deviceOS": "Badda", "browsertype": "Firefox", "position": { "lon": 25.4586115, "lat": 65.0600797, "alt": -1000, "acc": 48.38800048828125 }, "device": { "ax": 0, "ay": 0, "az": 0, "gx": 0, "gy": 0, "gz": 0, "ra": 210.5637, "rb": 47.5657, "rg": 6.9698, "orientation": "potrait" }, "vwidth": 480, "vheight": 800 } jsondata5 = { "type": "image", "time": "2014.3.4_14.40.35", "ext": "png", "deviceType": "Mobile", "deviceOS": "Badda", "browsertype": "Firefox", "position": { "lon": 25.4587125, "lat": 65.0600797, "alt": -1000, "acc": 48.38800048828125 }, "device": { "ax": 0, "ay": 0, "az": 0, "gx": 0, "gy": 0, "gz": 0, "ra": 210.5637, "rb": 47.5657, "rg": 6.9698, "orientation": "potrait" }, "vwidth": 480, "vheight": 800 } jsondata6 = { "type": "image", "time": "2014.3.4_14.40.36", "ext": "png", "deviceType": "Mobile", "deviceOS": "Badda", "browsertype": "Firefox", "position": { "lon": 25.4588125, "lat": 65.0600797, "alt": -1000, "acc": 48.38800048828125 }, "device": { "ax": 0, "ay": 0, "az": 0, "gx": 0, "gy": 0, "gz": 0, "ra": 210.5637, "rb": 47.5657, "rg": 6.9698, "orientation": "potrait" }, "vwidth": 480, "vheight": 800 } es.saveData(jsondata1) es.saveData(jsondata2) es.saveData(jsondata3) es.saveData(jsondata4) es.saveData(jsondata5) es.saveData(jsondata6) radius = 0.0001 photoList = es.getClosestImages(65.0601787, 25.4583107, radius) self.assertEqual( len(photoList), 4, "Length of the list should be equal of the first test") for row in photoList: assert 'image_2014.3.4_14.40.32.png' or 'image_2014.3.4_14.40.31.png' in row[ 0] photoList2 = es.getClosestImages(65.0601787, 25.4587107, radius) self.assertEqual( len(photoList2), 2, "Length of the list should be equal of the second test") for row in photoList2: assert 'image_2014.3.4_14.40.34.png' or 'image_2014.3.4_14.40.35.png' in row[ 0]
def test_data_insert_data_Read(self): self.assertIsInstance(self.connection, MySQLdb.connection, "Database connection accurately set") jsondata = { "type": "image", "time": "2014.3.4_14.40.30", "ext": "png", "deviceType": "Mobile", "deviceOS": "Badda", "browsertype": "Firefox", "position": { "lon": 25.4583105, "lat": 65.0600797, "alt": -1000, "acc": 48.38800048828125 }, "device": { "ax": 0, "ay": 0, "az": 0, "gx": 0, "gy": 0, "gz": 0, "ra": 210.5637, "rb": 47.5657, "rg": 6.9698, "orientation": "potrait" }, "vwidth": 480, "vheight": 800 } alt = str(jsondata["position"]["alt"]) if alt == "None": alt = '0' heading = '0' speed = '0' width = jsondata["vwidth"] height = jsondata["vheight"] if width > height: screenorientation = 1.00 #landscape else: screenorientation = 0.00 #potrait filename = jsondata["type"] + "_" + jsondata["time"] + "." + jsondata[ "ext"] sqlstring1 = "INSERT INTO Imagedata values (\'" + filename + "\',GeomFromText ('POINT(" + str( jsondata["position"]["lat"]) + " " + str( jsondata["position"]["lon"]) + ")')," + str( jsondata["position"]["alt"]) + "," + str( jsondata["position"]["acc"]) sqlstring2 = "," + str(jsondata["device"]["gx"]) + "," + str( jsondata["device"]["gy"]) + "," + str(jsondata["device"]["gz"]) sqlstring3 = "," + str(jsondata["device"]["ra"]) + "," + str( jsondata["device"]["rb"]) + "," + str( jsondata["device"]["rg"]) + "," + str( screenorientation) + ",\'" + jsondata["device"][ "orientation"] + "\',now(),\'" + str( jsondata["deviceOS"]) + "\',\'" + str( jsondata["browsertype"]) + "\',\'" + str( jsondata["deviceType"]) + "\');" sqlstring = sqlstring1 + sqlstring2 + sqlstring3 #print(sqlstring) es.dbInsert(sqlstring) sqlreadsting = 'select imagename, Browser,devicetype,X(location) as latitude, Y(location) as longitude from Imagedata where time=\'2014.3.4_14.40.31\'' result = es.dbRead(sqlreadsting) self.assertIsNotNone(result, "Inserted data is retrieved and it is not null") for row in result: self.assertEqual(row[0], "image_2014.3.4_14.40.30.png", "Image name is correctly set and saved") self.assertEqual(row[1], 65.0600797, "Latitudes are saved") self.assertEqual(row[2], 25.4583105, "Longitude are saved")