本文整理汇总了Python中ichnaea.tests.factories.CellFactory类的典型用法代码示例。如果您正苦于以下问题:Python CellFactory类的具体用法?Python CellFactory怎么用?Python CellFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CellFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_invalid_radiotype
def test_invalid_radiotype(self):
cell = CellFactory.build()
cell2 = CellFactory.build(radio=Radio.wcdma)
self.app.post_json(
'/v1/geosubmit?key=test',
{'items': [
{'latitude': cell.lat,
'longitude': cell.lon,
'cellTowers': [{
'radioType': '18',
'mobileCountryCode': cell.mcc,
'mobileNetworkCode': cell.mnc,
'locationAreaCode': cell.lac,
'cellId': cell.cid,
}, {
'radioType': 'umts',
'mobileCountryCode': cell2.mcc,
'mobileNetworkCode': cell2.mnc,
'locationAreaCode': cell2.lac,
'cellId': cell2.cid,
}]},
]},
status=200)
obs = self.session.query(CellObservation).all()
self.assertEqual(len(obs), 1)
self.assertEqual(obs[0].cid, cell2.cid)
示例2: add_reports
def add_reports(self, num=1, blue_factor=0, cell_factor=1, wifi_factor=2,
api_key='test', email=None, ip=None, nickname=None,
blue_key=None, cell_mcc=None, wifi_key=None,
lat=None, lon=None):
reports = []
for i in range(num):
pos = CellFactory.build()
report = {
'timestamp': time.time() * 1000.0,
'position': {},
'bluetoothBeacons': [],
'cellTowers': [],
'wifiAccessPoints': [],
}
report['position']['latitude'] = lat or pos.lat
report['position']['longitude'] = lon or pos.lon
report['position']['accuracy'] = 17.0 + i
blues = WifiShardFactory.build_batch(blue_factor,
lat=pos.lat, lon=pos.lon)
for blue in blues:
blue_data = {
'macAddress': blue_key or blue.mac,
'signalStrength': -100 + i,
}
report['bluetoothBeacons'].append(blue_data)
cells = CellFactory.build_batch(cell_factor,
lat=pos.lat, lon=pos.lon)
for cell in cells:
cell_data = {
'radioType': cell.radio.name,
'mobileCountryCode': cell_mcc or cell.mcc,
'mobileNetworkCode': cell.mnc,
'locationAreaCode': cell.lac,
'cellId': cell.cid,
'primaryScramblingCode': cell.psc,
'signalStrength': -110 + i,
}
report['cellTowers'].append(cell_data)
wifis = WifiShardFactory.build_batch(wifi_factor,
lat=pos.lat, lon=pos.lon)
for wifi in wifis:
wifi_data = {
'macAddress': wifi_key or wifi.mac,
'signalStrength': -90 + i,
'ssid': 'my-wifi',
}
report['wifiAccessPoints'].append(wifi_data)
reports.append(report)
queue_reports.delay(reports=reports, api_key=api_key,
email=email, ip=ip, nickname=nickname).get()
return reports
示例3: test_export_full
def test_export_full(self):
CellFactory.create_batch(10, radio=Radio.gsm)
self.session.commit()
with mock_s3() as mock_key:
cell_export_full(_bucket='localhost.bucket')
pat = r'MLS-full-cell-export-\d+-\d+-\d+T000000\.csv\.gz'
self.assertRegex(mock_key.key, pat)
method = mock_key.set_contents_from_filename
self.assertRegex(method.call_args[0][0], pat)
示例4: test_daily_export
def test_daily_export(self):
CellFactory.create_batch(10, radio=Radio.gsm)
self.session.commit()
with mock_s3() as mock_key:
export_modified_cells(bucket='localhost.bucket', hourly=False)
pat = r'MLS-full-cell-export-\d+-\d+-\d+T000000\.csv\.gz'
self.assertRegexpMatches(mock_key.key, pat)
method = mock_key.set_contents_from_filename
self.assertRegexpMatches(method.call_args[0][0], pat)
示例5: test_cdma_cell
def test_cdma_cell(self):
# Specifying a CDMA radio type works,
# but the information is ignored.
cell = CellFactory(radio=Radio.gsm, radius=15000)
cell2 = CellFactory(radio=Radio.gsm, radius=35000,
lat=cell.lat + 0.0002, lon=cell.lon)
cell2.radio = Radio.cdma
self.session.flush()
query = self.model_query(cells=[cell, cell2])
res = self._call(body=query)
self.check_model_response(res, cell)
示例6: test_medium_hit
def test_medium_hit(self):
cells = CellFactory.build_batch(1)
self._make_query(self._make_result(accuracy=30000.0), cell=cells)
self.check_stats(counter=[
('locate.result',
['key:key', 'country:none', 'accuracy:medium', 'status:hit']),
])
示例7: test_cell_geoip_mismatch
def test_cell_geoip_mismatch(self):
# UK GeoIP with US mcc
cell = CellFactory.create(mcc=310)
query = self.model_query(cells=[cell])
res = self._call(body=query, ip=self.test_ip)
self.check_model_response(res, cell, country='US')
self.check_db_calls(rw=0, ro=0)
示例8: test_blacklist_time_used_as_creation_time
def test_blacklist_time_used_as_creation_time(self):
now = util.utcnow()
last_week = now - TEMPORARY_BLACKLIST_DURATION - timedelta(days=1)
cell = CellFactory.build()
self.session.add(
CellBlacklist(time=last_week, count=1,
radio=cell.radio, mcc=cell.mcc,
mnc=cell.mnc, lac=cell.lac, cid=cell.cid))
self.session.flush()
# add a new entry for the previously blacklisted cell
obs = dict(lat=cell.lat, lon=cell.lon,
radio=int(cell.radio), mcc=cell.mcc, mnc=cell.mnc,
lac=cell.lac, cid=cell.cid)
insert_measures_cell.delay([obs]).get()
self.assertEqual(self.data_queue.size(), 1)
update_cell.delay().get()
# the cell was inserted again
cells = self.session.query(Cell).all()
self.assertEqual(len(cells), 1)
# and the creation date was set to the date of the blacklist entry
self.assertEqual(cells[0].created, last_week)
self.check_statcounter(StatKey.cell, 1)
self.check_statcounter(StatKey.unique_cell, 0)
示例9: setUp
def setUp(self):
super(TestFallbackProvider, self).setUp()
self.provider.api_key.allow_fallback = True
self.response_location = {
'location': {
'lat': 51.5366,
'lng': 0.03989,
},
'accuracy': 1500,
'fallback': 'lacf',
}
self.cells = []
for cell in CellFactory.build_batch(2):
self.cells.append({
'radio': cell.radio,
'mcc': cell.mcc,
'mnc': cell.mnc,
'lac': cell.lac,
'cid': cell.cid,
'signal': -70,
})
self.cells[0]['ta'] = 1
self.wifis = []
for wifi in WifiFactory.build_batch(2):
self.wifis.append({
'key': wifi.key,
'signal': -77,
})
self.wifis[0]['channel'] = 6
self.wifis[0]['frequency'] = 2437
self.wifis[0]['snr'] = 13
示例10: test_get_cell_multi
def test_get_cell_multi(self):
cells = CellFactory.build_batch(2)
query = Query(cell=self.cell_model_query(cells))
self.assertEqual(self.cache.get(query), None)
self.check_stats(counter=[
('locate.fallback.cache', 1, 1, ['status:bypassed']),
])
示例11: test_cell
def test_cell(self):
# cell with unique mcc to region mapping
cell = CellFactory.create(mcc=235)
query = self.model_query(cells=[cell])
res = self._call(body=query)
self.check_model_response(res, cell, region='GB')
self.check_db_calls(rw=0, ro=0)
示例12: test_database_error
def test_database_error(self):
london = self.geoip_data['London']
self.session.execute(text('drop table wifi;'))
self.session.execute(text('drop table cell;'))
cell = CellFactory.build()
wifis = WifiFactory.build_batch(2)
res = self.app.post_json(
'/v1/geolocate?key=test', {
'cellTowers': [{
'radioType': cell.radio.name,
'mobileCountryCode': cell.mcc,
'mobileNetworkCode': cell.mnc,
'locationAreaCode': cell.lac,
'cellId': cell.cid},
],
'wifiAccessPoints': [
{'macAddress': wifis[0].key},
{'macAddress': wifis[1].key},
]},
extra_environ={'HTTP_X_FORWARDED_FOR': london['ip']},
status=200)
self.assertEqual(res.content_type, 'application/json')
self.assertEqual(res.json, {'location': {'lat': london['latitude'],
'lng': london['longitude']},
'accuracy': london['accuracy']})
self.check_stats(
timer=['request.v1.geolocate'],
counter=[
'request.v1.geolocate.200',
'geolocate.geoip_hit',
])
self.check_raven([('ProgrammingError', 2)])
示例13: test_cell
def test_cell(self):
cell = CellFactory.build()
cell_query = self.cell_model_query([cell])
query = Query(cell=cell_query)
self.assertEqual(len(query.cell), 1)
self.assertEqual(query.expected_accuracy, DataAccuracy.medium)
query_cell = query.cell[0]
for key, value in cell_query[0].items():
query_value = getattr(query_cell, key, None)
if key == 'radio':
self.assertEqual(query_value, cell.radio)
else:
self.assertEqual(query_value, value)
self.assertEqual(len(query.cell_area), 1)
query_area = query.cell_area[0]
for key, value in cell_query[0].items():
query_value = getattr(query_area, key, None)
if key == 'radio':
self.assertEqual(query_value, cell.radio)
elif key in ('cid', 'psc'):
pass
else:
self.assertEqual(query_value, value)
示例14: test_database_error
def test_database_error(self, db_errors=0):
cells = CellFactory.build_batch(2)
wifis = WifiShardFactory.build_batch(2)
for model in (Cell, CellArea, CellOCID, CellAreaOCID):
self.session.execute(text('drop table %s;' % model.__tablename__))
for name in set([wifi.__tablename__ for wifi in wifis]):
self.session.execute(text('drop table %s;' % name))
query = self.model_query(cells=cells, wifis=wifis)
res = self._call(body=query, ip=self.test_ip)
self.check_response(res, 'ok')
self.check_stats(counter=[
('request', [self.metric_path, 'method:post', 'status:200']),
], timer=[
('request', [self.metric_path, 'method:post']),
])
if self.apikey_metrics:
self.check_stats(counter=[
(self.metric_type + '.result',
['key:test', 'region:GB', 'fallback_allowed:false',
'accuracy:high', 'status:miss']),
])
self.check_raven([('ProgrammingError', db_errors)])
示例15: test_empty_result_from_fallback_cached
def test_empty_result_from_fallback_cached(self):
cell = CellFactory.build()
with requests_mock.Mocker() as mock_request:
mock_request.register_uri(
'POST',
requests_mock.ANY,
json=LocationNotFound.json_body(),
status_code=404
)
query = self.model_query(cells=[cell])
location = self.provider.locate(query)
self.check_model_location(location, None)
self.assertEqual(mock_request.call_count, 1)
self.check_stats(
counter=[
'm.fallback.lookup_status.404',
'm.fallback.cache.miss',
],
timer=['m.fallback.lookup'])
query = self.model_query(cells=[cell])
location = self.provider.locate(query)
self.check_model_location(location, None)
self.assertEqual(mock_request.call_count, 1)
self.check_stats(
counter=[
'm.fallback.lookup_status.404',
'm.fallback.cache.hit',
],
timer=['m.fallback.lookup'])