def test_ok_cell(self): app = self.app session = self.db_master_session cell = Cell() cell.lat = GB_LAT cell.lon = GB_LON cell.radio = 0 cell.mcc = GB_MCC cell.mnc = 1 cell.lac = 2 cell.cid = 1234 cell.total_measures = 1 cell.new_measures = 0 session.add(cell) session.commit() res = app.post_json('/v1/geosubmit?key=test', {'items': [{"latitude": GB_LAT + 0.1, "longitude": GB_LON + 0.1, "accuracy": 12.4, "radioType": "gsm", "cellTowers": [{ "cellId": 1234, "locationAreaCode": 2, "mobileCountryCode": GB_MCC, "mobileNetworkCode": 1, }]}, {"latitude": GB_LAT - 0.1, "longitude": GB_LON - 0.1, "accuracy": 22.4, "radioType": "gsm", "cellTowers": [{ "cellId": 2234, "locationAreaCode": 22, "mobileCountryCode": GB_MCC, "mobileNetworkCode": 2, }]}]}, status=200) # check that we get an empty response self.assertEqual(res.content_type, 'application/json') self.assertEqual(res.json, {}) # check that two new CellMeasure records are created self.assertEquals(2, session.query(CellMeasure).count()) cm1 = session.query(CellMeasure).filter( CellMeasure.cid == 1234).count() cm2 = session.query(CellMeasure).filter( CellMeasure.cid == 2234).count() self.assertEquals(1, cm1) self.assertEquals(1, cm2) self.check_stats( counter=['geosubmit.api_key.test', 'items.uploaded.batches', 'items.uploaded.reports', ], timer=['items.uploaded.batch_size'])
def test_ok_cell(self): app = self.app session = self.db_master_session cell = Cell() cell.lat = GB_LAT + 0.1 cell.lon = GB_LON + 0.1 cell.radio = 0 cell.mcc = GB_MCC cell.mnc = 1 cell.lac = 2 cell.cid = 1234 cell.total_measures = 1 cell.new_measures = 0 session.add(cell) session.commit() res = app.post_json('/v1/geosubmit?key=test', { "latitude": GB_LAT, "longitude": GB_LON, "accuracy": 12.4, "radioType": "gsm", "cellTowers": [{ "cellId": 1234, "locationAreaCode": 2, "mobileCountryCode": GB_MCC, "mobileNetworkCode": 1, }]}, status=200) # check that we get back a location self.assertEqual(res.content_type, 'application/json') self.assertEqual(res.json, {"location": {"lat": GB_LAT, "lng": GB_LON}, "accuracy": 12.4}) cell = session.query(Cell).first() self.assertEqual(2, cell.total_measures) self.assertEqual(1, cell.new_measures) # check that one new CellMeasure record is created self.assertEquals(1, session.query(CellMeasure).count()) self.check_stats( counter=['geosubmit.api_key.test', 'items.api_log.test.uploaded.batches', 'items.api_log.test.uploaded.reports', 'items.api_log.test.uploaded.cell_observations', 'items.uploaded.cell_observations', 'items.uploaded.batches', 'items.uploaded.reports', 'request.v1.geosubmit.200', ], timer=['items.api_log.test.uploaded.batch_size', 'items.uploaded.batch_size', 'request.v1.geosubmit'])
def test_geoip_match(self): app = self.app london = self.geoip_data['London'] session = self.db_master_session cell = Cell() cell.lat = GB_LAT cell.lon = GB_LON cell.radio = 0 cell.mcc = GB_MCC cell.mnc = 1 cell.lac = 2 cell.cid = 1234 cell.total_measures = 1 cell.new_measures = 0 session.add(cell) session.commit() res = app.post_json( '/v1/geosubmit?key=test', {'items': [{"latitude": GB_LAT + 0.1, "longitude": GB_LON + 0.1, "accuracy": 12.4, "radioType": "gsm", "cellTowers": [{ "cellId": 1234, "locationAreaCode": 2, "mobileCountryCode": GB_MCC, "mobileNetworkCode": 1, }]}, {"latitude": GB_LAT - 0.1, "longitude": GB_LON - 0.1, "accuracy": 22.4, "radioType": "gsm", "cellTowers": [{ "cellId": 2234, "locationAreaCode": 22, "mobileCountryCode": GB_MCC, "mobileNetworkCode": 2, }]}]}, extra_environ={'HTTP_X_FORWARDED_FOR': london['ip']}, status=200) # check that we get an empty response self.assertEqual(res.content_type, 'application/json') self.assertEqual(res.json, {}) # check that two new CellMeasure records are created self.assertEquals(2, session.query(CellMeasure).count()) cm1 = session.query(CellMeasure).filter( CellMeasure.cid == 1234).count() cm2 = session.query(CellMeasure).filter( CellMeasure.cid == 2234).count() self.assertEquals(1, cm1) self.assertEquals(1, cm2)
def update_lac(self, radio, mcc, mnc, lac): with self.db_session() as session: # Select all the cells in this LAC that aren't the virtual # cell itself, and derive a bounding box for them. q = session.query(Cell).filter(Cell.radio == radio).filter( Cell.mcc == mcc).filter(Cell.mnc == mnc).filter( Cell.lac == lac).filter(Cell.cid != CELLID_LAC) cells = q.all() points = [(to_degrees(c.lat), to_degrees(c.lon)) for c in cells] min_lat = to_degrees(min([c.min_lat for c in cells])) min_lon = to_degrees(min([c.min_lon for c in cells])) max_lat = to_degrees(max([c.max_lat for c in cells])) max_lon = to_degrees(max([c.max_lon for c in cells])) bbox_points = [(min_lat, min_lon), (min_lat, max_lon), (max_lat, min_lon), (max_lat, max_lon)] ctr = centroid(points) rng = range_to_points(ctr, bbox_points) # switch units back to DB preferred centimicrodegres angle # and meters distance. ctr_lat = from_degrees(ctr[0]) ctr_lon = from_degrees(ctr[1]) rng = int(round(rng * 1000.0)) # Now create or update the LAC virtual cell q = session.query(Cell).filter(Cell.radio == radio).filter( Cell.mcc == mcc).filter(Cell.mnc == mnc).filter( Cell.lac == lac).filter(Cell.cid == CELLID_LAC) lac = q.first() if lac is None: lac = Cell(radio=radio, mcc=mcc, mnc=mnc, lac=lac, cid=CELLID_LAC, lat=ctr_lat, lon=ctr_lon, range=rng) else: lac.new_measures = 0 lac.lat = ctr_lat lac.lon = ctr_lon lac.range = rng session.commit()
def test_geoip_match(self): app = self.app session = self.db_master_session cell = Cell() cell.lat = PARIS_LAT cell.lon = PARIS_LON cell.radio = 0 cell.mcc = FRANCE_MCC cell.mnc = 1 cell.lac = 2 cell.cid = 1234 cell.total_measures = 1 cell.new_measures = 0 session.add(cell) session.commit() res = app.post_json('/v1/geosubmit?key=test', {'items': [{"latitude": PARIS_LAT + 0.1, "longitude": PARIS_LON + 0.1, "accuracy": 12.4, "radioType": "gsm", "cellTowers": [{ "cellId": 1234, "locationAreaCode": 2, "mobileCountryCode": FRANCE_MCC, "mobileNetworkCode": 1, }]}, {"latitude": PARIS_LAT - 0.1, "longitude": PARIS_LON - 0.1, "accuracy": 22.4, "radioType": "gsm", "cellTowers": [{ "cellId": 2234, "locationAreaCode": 22, "mobileCountryCode": FRANCE_MCC, "mobileNetworkCode": 2, }]}]}, extra_environ={'HTTP_X_FORWARDED_FOR': PARIS_IP}, status=200) # check that we get an empty response self.assertEqual(res.content_type, 'application/json') self.assertEqual(res.json, {}) # check that two new CellMeasure records are created self.assertEquals(2, session.query(CellMeasure).count()) cm1 = session.query(CellMeasure).filter( CellMeasure.cid == 1234).count() cm2 = session.query(CellMeasure).filter( CellMeasure.cid == 2234).count() self.assertEquals(1, cm1) self.assertEquals(1, cm2)
def test_ok_cell(self): app = self.app session = self.db_master_session cell = Cell() cell.lat = PARIS_LAT + 0.1 cell.lon = PARIS_LON + 0.1 cell.radio = 0 cell.mcc = FRANCE_MCC cell.mnc = 1 cell.lac = 2 cell.cid = 1234 cell.total_measures = 1 cell.new_measures = 0 session.add(cell) session.commit() res = app.post_json('/v1/geosubmit?key=test', { "latitude": PARIS_LAT, "longitude": PARIS_LON, "accuracy": 12.4, "radioType": "gsm", "cellTowers": [{ "cellId": 1234, "locationAreaCode": 2, "mobileCountryCode": FRANCE_MCC, "mobileNetworkCode": 1, }]}, status=200) # check that we get back a location self.assertEqual(res.content_type, 'application/json') self.assertEqual(res.json, {"location": {"lat": PARIS_LAT, "lng": PARIS_LON}, "accuracy": 12.4}) cell = session.query(Cell).first() self.assertEqual(2, cell.total_measures) self.assertEqual(1, cell.new_measures) # check that one new CellMeasure record is created self.assertEquals(1, session.query(CellMeasure).count())
def update_lac(self, radio, mcc, mnc, lac): with self.db_session() as session: # Select all the cells in this LAC that aren't the virtual # cell itself, and derive a bounding box for them. q = session.query(Cell).filter( Cell.radio == radio).filter( Cell.mcc == mcc).filter( Cell.mnc == mnc).filter( Cell.lac == lac).filter( Cell.cid != CELLID_LAC).filter( Cell.new_measures == 0).filter( Cell.lat.isnot(None)).filter( Cell.lon.isnot(None)) cells = q.all() if len(cells) == 0: return points = [(to_degrees(c.lat), to_degrees(c.lon)) for c in cells] min_lat = to_degrees(min([c.min_lat for c in cells])) min_lon = to_degrees(min([c.min_lon for c in cells])) max_lat = to_degrees(max([c.max_lat for c in cells])) max_lon = to_degrees(max([c.max_lon for c in cells])) bbox_points = [(min_lat, min_lon), (min_lat, max_lon), (max_lat, min_lon), (max_lat, max_lon)] ctr = centroid(points) rng = range_to_points(ctr, bbox_points) # switch units back to DB preferred centimicrodegres angle # and meters distance. ctr_lat = from_degrees(ctr[0]) ctr_lon = from_degrees(ctr[1]) rng = int(round(rng * 1000.0)) # Now create or update the LAC virtual cell q = session.query(Cell).filter( Cell.radio == radio).filter( Cell.mcc == mcc).filter( Cell.mnc == mnc).filter( Cell.lac == lac).filter( Cell.cid == CELLID_LAC) lac = q.first() if lac is None: lac = Cell(radio=radio, mcc=mcc, mnc=mnc, lac=lac, cid=CELLID_LAC, lat=ctr_lat, lon=ctr_lon, range=rng) else: lac.new_measures = 0 lac.lat = ctr_lat lac.lon = ctr_lon lac.range = rng session.commit()
def test_ok_cell(self): app = self.app session = self.db_master_session cell = Cell() cell.lat = GB_LAT cell.lon = GB_LON cell.radio = RADIO_TYPE['cdma'] cell.mcc = GB_MCC cell.mnc = 1 cell.lac = 2 cell.cid = 1234 cell.range = 10000 cell.total_measures = 1 cell.new_measures = 0 session.add(cell) session.commit() res = app.post_json('/v1/geosubmit?key=test', { "items": [ { "latitude": GB_LAT + 0.1, "longitude": GB_LON + 0.1, "accuracy": 12.4, "radioType": "cdma", "cellTowers": [{ "cellId": 1234, "locationAreaCode": 2, "mobileCountryCode": GB_MCC, "mobileNetworkCode": 1, }] }, { "latitude": GB_LAT - 0.1, "longitude": GB_LON - 0.1, "accuracy": 22.4, "cellTowers": [{ "radioType": "wcdma", "cellId": 2234, "locationAreaCode": 22, "mobileCountryCode": GB_MCC, "mobileNetworkCode": 2, }] }, ] }, status=200) # check that we get an empty response self.assertEqual(res.content_type, 'application/json') self.assertEqual(res.json, {}) self.assertEqual(session.query(Cell).count(), 2) observations = session.query(CellObservation).all() self.assertEqual(len(observations), 2) radios = set([obs.radio for obs in observations]) self.assertEqual(radios, set([RADIO_TYPE['cdma'], RADIO_TYPE['umts']])) self.check_stats(counter=[ 'geosubmit.api_key.test', 'items.api_log.test.uploaded.batches', 'items.api_log.test.uploaded.reports', 'items.api_log.test.uploaded.cell_observations', 'items.uploaded.cell_observations', 'items.uploaded.batches', 'items.uploaded.reports', 'request.v1.geosubmit.200', ], timer=[ 'items.api_log.test.uploaded.batch_size', 'items.uploaded.batch_size', 'request.v1.geosubmit' ])