def test_fields(self): now = util.utcnow() cellid = encode_cellid(Radio.gsm, GB_MCC, GB_MNC, 123, 2345) self.session.add(CellOCID.create( cellid=cellid, created=now, modified=now, radio=Radio.gsm, mcc=GB_MCC, mnc=GB_MNC, lac=123, cid=2345, psc=1, lat=GB_LAT, lon=GB_LON, max_lat=GB_LAT + 0.1, min_lat=GB_LAT - 0.1, max_lon=GB_LON + 0.1, min_lon=GB_LON - 0.1, radius=11, region='GB', samples=15, source=StationSource.gnss, block_first=now.date(), block_last=now.date(), block_count=1)) self.session.flush() result = (self.session.query(CellOCID) .filter(CellOCID.cellid == cellid)).first() self.assertEqual(result.areaid, cellid[:7]) self.assertEqual(encode_cellid(*result.cellid), cellid) self.assertEqual(result.radio, Radio.gsm) self.assertEqual(result.mcc, GB_MCC) self.assertEqual(result.mnc, GB_MNC) self.assertEqual(result.lac, 123) self.assertEqual(result.cid, 2345) self.assertEqual(result.psc, 1) self.assertEqual(result.created, now) self.assertEqual(result.modified, now) self.assertEqual(result.lat, GB_LAT) self.assertEqual(result.lon, GB_LON) self.assertEqual(result.radius, 11) self.assertEqual(result.region, 'GB') self.assertEqual(result.samples, 15) self.assertEqual(result.source, StationSource.gnss) self.assertEqual(result.block_first, now.date()) self.assertEqual(result.block_last, now.date()) self.assertEqual(result.block_count, 1)
def test_encode_cell(self): value = encode_cellid(Radio.gsm, 310, 0, 1, 1) assert len(value) == 11 assert value == b"\x00\x016\x00\x00\x00\x01\x00\x00\x00\x01" value = encode_cellid(Radio.wcdma, 310, 1, 12, 0) assert len(value) == 11 assert value == b"\x02\x016\x00\x01\x00\x0c\x00\x00\x00\x00"
def test_encode_cell(self): value = encode_cellid(Radio.gsm, 310, 0, 1, 1) assert len(value) == 11 assert value == b'\x00\x016\x00\x00\x00\x01\x00\x00\x00\x01' value = encode_cellid(Radio.wcdma, 310, 1, 12, 0) assert len(value) == 11 assert value == b'\x02\x016\x00\x01\x00\x0c\x00\x00\x00\x00'
def test_encode_cell(self): value = encode_cellid(Radio.gsm, 310, 0, 1, 1) self.assertEqual(len(value), 11) self.assertEqual(value, b'\x00\x016\x00\x00\x00\x01\x00\x00\x00\x01') value = encode_cellid(Radio.wcdma, 310, 1, 12, 0) self.assertEqual(len(value), 11) self.assertEqual(value, b'\x02\x016\x00\x01\x00\x0c\x00\x00\x00\x00')
def test_fields(self, session): now = util.utcnow() cellid = encode_cellid(Radio.gsm, GB_MCC, GB_MNC, 123, 2345) model = CellShard.shard_model(Radio.gsm) session.add( model.create( cellid=cellid, created=now, modified=now, radio=Radio.gsm, mcc=GB_MCC, mnc=GB_MNC, lac=123, cid=2345, psc=1, lat=GB_LAT, lon=GB_LON, max_lat=GB_LAT + 0.1, min_lat=GB_LAT - 0.1, max_lon=GB_LON + 0.1, min_lon=GB_LON - 0.1, radius=11, region="GB", samples=15, source=ReportSource.gnss, weight=1.5, last_seen=now.date(), block_first=now.date(), block_last=now.date(), block_count=1, )) session.flush() result = (session.query(model).filter(model.cellid == cellid)).first() assert area_id(result) == cellid[:7] assert encode_cellid(*result.cellid) == cellid assert result.radio == Radio.gsm assert result.mcc == GB_MCC assert result.mnc == GB_MNC assert result.lac == 123 assert result.cid == 2345 assert result.psc == 1 assert result.created == now assert result.modified == now assert result.lat == GB_LAT assert result.lon == GB_LON assert result.radius == 11 assert result.region == "GB" assert result.samples == 15 assert result.source == ReportSource.gnss assert result.weight == 1.5 assert result.last_seen == now.date() assert result.block_first == now.date() assert result.block_last == now.date() assert result.block_count == 1
def test_min(self): value = encode_cellid(Radio.gsm, 0, 0, 0, 0, codec='base64') self.assertEqual(value, b'AAAAAAAAAAAAAAA=') value = decode_cellid(b'AAAAAAAAAAAAAAA=', codec='base64') self.assertEqual(value, (Radio.gsm, 0, 0, 0, 0)) self.assertEqual(type(value[0]), Radio)
def test_max(self): bit16 = 2**16 - 1 bit32 = 2**32 - 1 value = encode_cellarea(Radio.wcdma, bit16, bit16, bit16, codec="base64") assert value == b"Av///////w==" value = encode_cellid(Radio.wcdma, bit16, bit16, bit16, bit32, codec="base64") assert value == b"Av////////////8=" value = decode_cellarea(b"Av///////w==", codec="base64") assert value == (Radio.wcdma, bit16, bit16, bit16) assert type(value[0]) is Radio value = decode_cellid(b"Av////////////8=", codec="base64") assert value == (Radio.wcdma, bit16, bit16, bit16, bit32) assert type(value[0]) is Radio
def cellid(self): return encode_cellid( self.radioType, self.mobileCountryCode, self.mobileNetworkCode, self.locationAreaCode, self.cellId)
def test_max(self): bit16 = 2**16 - 1 bit32 = 2**32 - 1 value = encode_cellarea(Radio.wcdma, bit16, bit16, bit16, codec='base64') self.assertEqual(value, b'Av///////w==') value = encode_cellid(Radio.wcdma, bit16, bit16, bit16, bit32, codec='base64') self.assertEqual(value, b'Av////////////8=') value = decode_cellarea(b'Av///////w==', codec='base64') self.assertEqual(value, (Radio.wcdma, bit16, bit16, bit16)) self.assertEqual(type(value[0]), Radio) value = decode_cellid(b'Av////////////8=', codec='base64') self.assertEqual(value, (Radio.wcdma, bit16, bit16, bit16, bit32)) self.assertEqual(type(value[0]), Radio)
def test_region(self): cellid = encode_cellid(Radio.gsm, GB_MCC, GB_MNC, 123, 2345) self.session.add(CellOCID.create( cellid=cellid, lat=GB_LAT, lon=GB_LON, region=None, radio=Radio.gsm, mcc=GB_MCC, mnc=GB_MNC, lac=123, cid=2345)) self.session.flush() result = self.session.query(CellOCID).first() self.assertEqual(result.region, 'GB')
def test_areaid(self): cellid = encode_cellid(Radio.gsm, GB_MCC, GB_MNC, 123, 2345) self.session.add(CellOCID.create( cellid=cellid, radio=Radio.gsm, mcc=GB_MCC, mnc=GB_MNC, lac=123, cid=2345)) self.session.flush() result = self.session.query(CellOCID).first() self.assertEqual(result.areaid, cellid[:7])
def test_areaid(self): cellid = encode_cellid(Radio.gsm, GB_MCC, GB_MNC, 123, 2345) self.session.add(CellShardOCID.create( cellid=cellid, radio=Radio.gsm, mcc=GB_MCC, mnc=GB_MNC, lac=123, cid=2345)) self.session.flush() result = self.session.query(CellShardGsmOCID).first() self.assertEqual(result.areaid, cellid[:7])
def test_region(self): cellid = encode_cellid(Radio.gsm, GB_MCC, GB_MNC, 123, 2345) self.session.add(CellShardOCID.create( cellid=cellid, lat=GB_LAT, lon=GB_LON, region=None, radio=Radio.gsm, mcc=GB_MCC, mnc=GB_MNC, lac=123, cid=2345)) self.session.flush() result = self.session.query(CellShardGsmOCID).first() self.assertEqual(result.region, 'GB')
def test_shard_model(self): assert CellShard.shard_model(Radio.gsm) is CellShardGsm assert CellShard.shard_model(Radio.wcdma) is CellShardWcdma assert CellShard.shard_model(Radio.lte) is CellShardLte assert CellShard.shard_model("") is None assert CellShard.shard_model(None) is None cell_tuple = (Radio.lte, GB_MCC, GB_MNC, 1, 2) assert CellShard.shard_model(cell_tuple) is CellShardLte cellid = encode_cellid(*cell_tuple) assert CellShard.shard_model(cellid) is CellShardLte
def test_shard_model(self): assert CellShard.shard_model(Radio.gsm) is CellShardGsm assert CellShard.shard_model(Radio.wcdma) is CellShardWcdma assert CellShard.shard_model(Radio.lte) is CellShardLte assert CellShard.shard_model('') is None assert CellShard.shard_model(None) is None cell_tuple = (Radio.lte, GB_MCC, GB_MNC, 1, 2) assert CellShard.shard_model(cell_tuple) is CellShardLte cellid = encode_cellid(*cell_tuple) assert CellShard.shard_model(cellid) is CellShardLte
def test_max(self): bit16 = 2 ** 16 - 1 bit32 = 2 ** 32 - 1 value = encode_cellid( Radio.wcdma, bit16, bit16, bit16, bit32, codec='base64') self.assertEqual(value, b'Av////////////8=') value = decode_cellid(b'Av////////////8=', codec='base64') self.assertEqual(value, (Radio.wcdma, bit16, bit16, bit16, bit32)) self.assertEqual(type(value[0]), Radio)
def test_shard_model(self): self.assertIs(CellShard.shard_model(Radio.gsm), CellShardGsm) self.assertIs(CellShard.shard_model(Radio.wcdma), CellShardWcdma) self.assertIs(CellShard.shard_model(Radio.lte), CellShardLte) self.assertIs(CellShard.shard_model(''), None) self.assertIs(CellShard.shard_model(None), None) cell_tuple = (Radio.lte, GB_MCC, GB_MNC, 1, 2) self.assertEqual(CellShard.shard_model(cell_tuple), CellShardLte) cellid = encode_cellid(*cell_tuple) self.assertEqual(CellShard.shard_model(cellid), CellShardLte)
def test_shard_id(self): assert CellShard.shard_id(Radio.lte) == "lte" assert CellShard.shard_id(Radio.wcdma) == "wcdma" assert CellShard.shard_id("gsm") == "gsm" assert CellShard.shard_id("wcdma") == "wcdma" assert CellShard.shard_id("") is None assert CellShard.shard_id(None) is None cell_tuple = (Radio.lte, GB_MCC, GB_MNC, 1, 2) assert CellShard.shard_id(cell_tuple) == "lte" cellid = encode_cellid(*cell_tuple) assert CellShard.shard_id(cellid) == "lte"
def test_shard_id(self): assert CellShard.shard_id(Radio.lte) == 'lte' assert CellShard.shard_id(Radio.umts) == 'wcdma' assert CellShard.shard_id('gsm') == 'gsm' assert CellShard.shard_id('umts') == 'wcdma' assert CellShard.shard_id('') is None assert CellShard.shard_id(None) is None cell_tuple = (Radio.lte, GB_MCC, GB_MNC, 1, 2) assert CellShard.shard_id(cell_tuple) == 'lte' cellid = encode_cellid(*cell_tuple) assert CellShard.shard_id(cellid) == 'lte'
def test_shard_id(self): self.assertEqual(CellShard.shard_id(Radio.lte), 'lte') self.assertEqual(CellShard.shard_id(Radio.umts), 'wcdma') self.assertEqual(CellShard.shard_id('gsm'), 'gsm') self.assertEqual(CellShard.shard_id('umts'), 'wcdma') self.assertEqual(CellShard.shard_id(''), None) self.assertEqual(CellShard.shard_id(None), None) cell_tuple = (Radio.lte, GB_MCC, GB_MNC, 1, 2) self.assertEqual(CellShard.shard_id(cell_tuple), 'lte') cellid = encode_cellid(*cell_tuple) self.assertEqual(CellShard.shard_id(cellid), 'lte')
def test_areaid(self, session): cellid = encode_cellid(Radio.gsm, GB_MCC, GB_MNC, 123, 2345) session.add( CellShardOCID.create(cellid=cellid, radio=Radio.gsm, mcc=GB_MCC, mnc=GB_MNC, lac=123, cid=2345)) session.flush() result = session.query(CellShardGsmOCID).first() assert area_id(result) == cellid[:7]
def test_fields(self, session): now = util.utcnow() cellid = encode_cellid(Radio.gsm, GB_MCC, GB_MNC, 123, 2345) session.add(CellShardOCID.create( cellid=cellid, created=now, modified=now, radio=Radio.gsm, mcc=GB_MCC, mnc=GB_MNC, lac=123, cid=2345, psc=1, lat=GB_LAT, lon=GB_LON, max_lat=GB_LAT + 0.1, min_lat=GB_LAT - 0.1, max_lon=GB_LON + 0.1, min_lon=GB_LON - 0.1, radius=11, region='GB', samples=15, source=ReportSource.gnss, weight=1.5, last_seen=now.date(), block_first=now.date(), block_last=now.date(), block_count=1)) session.flush() query = (session.query(CellShardGsmOCID) .filter(CellShardGsmOCID.cellid == cellid)) result = query.first() assert result.areaid == cellid[:7] assert encode_cellid(*result.cellid) == cellid assert result.radio is Radio.gsm assert result.mcc == GB_MCC assert result.mnc == GB_MNC assert result.lac == 123 assert result.cid == 2345 assert result.psc == 1 assert result.created == now assert result.modified == now assert result.lat == GB_LAT assert result.lon == GB_LON assert result.radius == 11 assert result.region == 'GB' assert result.samples == 15 assert result.source is ReportSource.gnss assert result.weight == 1.5 assert result.last_seen == now.date() assert result.block_first == now.date() assert result.block_last == now.date() assert result.block_count == 1
def test_min(self): value = encode_cellarea(Radio.gsm, 0, 0, 0, codec='base64') assert value == b'AAAAAAAAAA==' value = encode_cellid(Radio.gsm, 0, 0, 0, 0, codec='base64') assert value == b'AAAAAAAAAAAAAAA=' value = decode_cellarea(b'AAAAAAAAAA==', codec='base64') assert value == (Radio.gsm, 0, 0, 0) assert type(value[0]) is Radio value = decode_cellid(b'AAAAAAAAAAAAAAA=', codec='base64') assert value == (Radio.gsm, 0, 0, 0, 0) assert type(value[0]) is Radio
def test_min(self): value = encode_cellarea(Radio.gsm, 0, 0, 0, codec="base64") assert value == b"AAAAAAAAAA==" value = encode_cellid(Radio.gsm, 0, 0, 0, 0, codec="base64") assert value == b"AAAAAAAAAAAAAAA=" value = decode_cellarea(b"AAAAAAAAAA==", codec="base64") assert value == (Radio.gsm, 0, 0, 0) assert type(value[0]) is Radio value = decode_cellid(b"AAAAAAAAAAAAAAA=", codec="base64") assert value == (Radio.gsm, 0, 0, 0, 0) assert type(value[0]) is Radio
def test_min(self): value = encode_cellarea(Radio.gsm, 0, 0, 0, codec='base64') self.assertEqual(value, b'AAAAAAAAAA==') value = encode_cellid(Radio.gsm, 0, 0, 0, 0, codec='base64') self.assertEqual(value, b'AAAAAAAAAAAAAAA=') value = decode_cellarea(b'AAAAAAAAAA==', codec='base64') self.assertEqual(value, (Radio.gsm, 0, 0, 0)) self.assertEqual(type(value[0]), Radio) value = decode_cellid(b'AAAAAAAAAAAAAAA=', codec='base64') self.assertEqual(value, (Radio.gsm, 0, 0, 0, 0)) self.assertEqual(type(value[0]), Radio)
def test_region(self, session): cellid = encode_cellid(Radio.gsm, GB_MCC, GB_MNC, 123, 2345) session.add( CellShard.create(cellid=cellid, lat=GB_LAT, lon=GB_LON, region=None, radio=Radio.gsm, mcc=GB_MCC, mnc=GB_MNC, lac=123, cid=2345)) session.flush() result = session.query(CellShardGsm).first() assert result.region == 'GB'
def test_max(self): bit16 = 2 ** 16 - 1 bit32 = 2 ** 32 - 1 value = encode_cellarea( Radio.wcdma, bit16, bit16, bit16, codec='base64') assert value == b'Av///////w==' value = encode_cellid( Radio.wcdma, bit16, bit16, bit16, bit32, codec='base64') assert value == b'Av////////////8=' value = decode_cellarea(b'Av///////w==', codec='base64') assert value == (Radio.wcdma, bit16, bit16, bit16) assert type(value[0]) is Radio value = decode_cellid(b'Av////////////8=', codec='base64') assert value == (Radio.wcdma, bit16, bit16, bit16, bit32) assert type(value[0]) is Radio
def _cache_keys_cell(self, cell_query): keys = [] for cell in cell_query: keys.append(self.cache_key_cell + encode_cellid( cell.radio, cell.mcc, cell.mnc, cell.lac, cell.cid)) return keys
def cellid(self): return encode_cellid( self.radio, self.mcc, self.mnc, self.lac, self.cid)
def cellid(self): return encode_cellid(self.radio, self.mcc, self.mnc, self.lac, self.cid)