Example #1
0
 def test_score(self):
     now = util.utcnow()
     area = CellArea.create(
         radio=Radio.gsm, mcc=GB_MCC, mnc=GB_MNC, lac=2,
         created=now, modified=now, radius=10, num_cells=4)
     assert round(area.score(now), 2) == 0.2
     area = CellArea.create(
         radio=Radio.gsm, mcc=GB_MCC, mnc=GB_MNC, lac=2,
         created=now, modified=now, radius=0, num_cells=100)
     assert round(area.score(now), 2) == 0.1
Example #2
0
 def test_score(self):
     now = util.utcnow()
     area = CellArea.create(
         radio=Radio.gsm, mcc=GB_MCC, mnc=GB_MNC, lac=2,
         created=now, modified=now, radius=10, num_cells=4)
     self.assertAlmostEqual(area.score(now), 0.2, 2)
     area = CellArea.create(
         radio=Radio.gsm, mcc=GB_MCC, mnc=GB_MNC, lac=2,
         created=now, modified=now, radius=0, num_cells=100)
     self.assertAlmostEqual(area.score(now), 0.1, 2)
Example #3
0
 def test_score(self):
     now = util.utcnow()
     area = CellArea.create(
         radio=Radio.gsm, mcc=GB_MCC, mnc=GB_MNC, lac=2,
         created=now, modified=now, radius=10, num_cells=4)
     self.assertAlmostEqual(area.score(now), 0.2, 2)
     area = CellArea.create(
         radio=Radio.gsm, mcc=GB_MCC, mnc=GB_MNC, lac=2,
         created=now, modified=now, radius=0, num_cells=100)
     self.assertAlmostEqual(area.score(now), 0.1, 2)
Example #4
0
    def test_fields(self):
        self.session.add(
            CellArea.create(areaid=(Radio.wcdma, GB_MCC, GB_MNC, 1234),
                            radio=Radio.wcdma,
                            mcc=GB_MCC,
                            mnc=GB_MNC,
                            lac=1234,
                            lat=GB_LAT,
                            lon=GB_LON,
                            region='GB',
                            radius=10,
                            avg_cell_radius=10,
                            num_cells=15))
        self.session.flush()

        result = self.session.query(CellArea).first()
        self.assertEqual(result.areaid, (Radio.wcdma, GB_MCC, GB_MNC, 1234)),
        self.assertEqual(result.radio, Radio.wcdma)
        self.assertEqual(result.mcc, GB_MCC)
        self.assertEqual(result.mnc, GB_MNC)
        self.assertEqual(result.lac, 1234)
        self.assertEqual(result.lat, GB_LAT)
        self.assertEqual(result.lon, GB_LON)
        self.assertEqual(result.radius, 10)
        self.assertEqual(result.region, 'GB')
        self.assertEqual(result.avg_cell_radius, 10)
        self.assertEqual(result.num_cells, 15)
Example #5
0
    def test_fields(self, session):
        session.add(
            CellArea.create(
                areaid=(Radio.wcdma, GB_MCC, GB_MNC, 1234),
                radio=Radio.wcdma,
                mcc=GB_MCC,
                mnc=GB_MNC,
                lac=1234,
                lat=GB_LAT,
                lon=GB_LON,
                region="GB",
                radius=10,
                avg_cell_radius=10,
                num_cells=15,
            ))
        session.flush()

        result = session.query(CellArea).first()
        assert result.areaid == (Radio.wcdma, GB_MCC, GB_MNC, 1234)
        assert result.radio is Radio.wcdma
        assert result.mcc == GB_MCC
        assert result.mnc == GB_MNC
        assert result.lac == 1234
        assert result.lat == GB_LAT
        assert result.lon == GB_LON
        assert result.radius == 10
        assert result.region == "GB"
        assert result.avg_cell_radius == 10
        assert result.num_cells == 15
Example #6
0
    def test_fields(self):
        cell = CellArea(
            radio=RADIO_TYPE['cdma'],
            lac=1234,
            mcc=100,
            mnc=5,
            lat=1.2345678,
            lon=2.3456789,
            range=10,
            avg_cell_range=10,
            num_cells=15,
        )
        session = self.db_master_session
        session.add(cell)
        session.commit()

        result = session.query(cell.__class__).first()
        self.assertEqual(result.radio, RADIO_TYPE['cdma'])
        self.assertEqual(result.mcc, 100)
        self.assertEqual(result.mnc, 5)
        self.assertEqual(result.lac, 1234)
        self.assertEqual(result.lat, 1.2345678)
        self.assertEqual(result.lon, 2.3456789)
        self.assertEqual(result.range, 10)
        self.assertEqual(result.avg_cell_range, 10)
        self.assertEqual(result.num_cells, 15)
Example #7
0
    def test_areaid_derived(self):
        self.session.add(CellArea.create(
            radio=Radio.wcdma, mcc=GB_MCC, mnc=GB_MNC, lac=1234))
        self.session.flush()

        result = self.session.query(CellArea).first()
        self.assertEqual(result.areaid, (Radio.wcdma, GB_MCC, GB_MNC, 1234))
Example #8
0
    def test_areaid_derived(self):
        self.session.add(CellArea.create(
            radio=Radio.wcdma, mcc=GB_MCC, mnc=GB_MNC, lac=1234))
        self.session.flush()

        result = self.session.query(CellArea).first()
        self.assertEqual(result.areaid, (Radio.wcdma, GB_MCC, GB_MNC, 1234))
Example #9
0
    def test_areaid_explicit(self, session):
        session.add(CellArea.create(
            areaid=(Radio.gsm, GB_MCC, GB_MNC, 1),
            radio=Radio.wcdma, mcc=GB_MCC, mnc=GB_MNC, lac=1234))
        session.flush()

        result = session.query(CellArea).first()
        assert result.areaid == (Radio.wcdma, GB_MCC, GB_MNC, 1234)
Example #10
0
    def test_region(self, session):
        areaid = encode_cellarea(Radio.gsm, GB_MCC, GB_MNC, 123)
        session.add(CellArea.create(
            areaid=areaid, lat=GB_LAT, lon=GB_LON, region=None,
            radio=Radio.gsm, mcc=GB_MCC, mnc=GB_MNC, lac=123))
        session.flush()

        result = session.query(CellArea).first()
        assert result.region == 'GB'
Example #11
0
    def test_areaid_null(self):
        result = (self.session.query(CellArea)
                              .filter(CellArea.areaid.is_(None))).all()
        self.assertEqual(result, [])

        self.session.add(CellArea(
            areaid=None,
            radio=Radio.wcdma, mcc=GB_MCC, mnc=GB_MNC, lac=1234))
        with self.assertRaises(Exception):
            self.session.flush()
    def test_areaid_explicit(self, session):
        session.add(
            CellArea.create(areaid=(Radio.gsm, GB_MCC, GB_MNC, 1),
                            radio=Radio.wcdma,
                            mcc=GB_MCC,
                            mnc=GB_MNC,
                            lac=1234))
        session.flush()

        result = session.query(CellArea).first()
        assert result.areaid == (Radio.wcdma, GB_MCC, GB_MNC, 1234)
Example #13
0
    def test_areaid_bytes(self):
        areaid = encode_cellarea(Radio.gsm, GB_MCC, GB_MNC, 1)
        self.session.add(CellArea(
            areaid=areaid,
            radio=Radio.wcdma, mcc=GB_MCC, mnc=GB_MNC, lac=1234))
        self.session.flush()

        result = self.session.query(CellArea).first()
        self.assertEqual(result.areaid, (Radio.gsm, GB_MCC, GB_MNC, 1))

        result = (self.session.query(CellArea)
                              .filter(CellArea.areaid == areaid)).first()
        self.assertEqual(result.areaid, (Radio.gsm, GB_MCC, GB_MNC, 1))
Example #14
0
    def test_areaid_hex(self):
        value = '''\
cast(conv(substr(hex(`areaid`), 1, 2), 16, 10) as unsigned),
cast(conv(substr(hex(`areaid`), 3, 4), 16, 10) as unsigned),
cast(conv(substr(hex(`areaid`), 7, 4), 16, 10) as unsigned),
cast(conv(substr(hex(`areaid`), 11, 4), 16, 10) as unsigned)
'''
        self.session.add(CellArea(
            areaid=(Radio.gsm, 310, 1, 65534),
            radio=Radio.gsm, mcc=310, mnc=1, lac=65534))
        self.session.flush()
        stmt = 'select %s from cell_area' % value
        row = self.session.execute(stmt).fetchone()
        self.assertEqual(row, (0, 310, 1, 65534))
    def test_region(self, session):
        areaid = encode_cellarea(Radio.gsm, GB_MCC, GB_MNC, 123)
        session.add(
            CellArea.create(areaid=areaid,
                            lat=GB_LAT,
                            lon=GB_LON,
                            region=None,
                            radio=Radio.gsm,
                            mcc=GB_MCC,
                            mnc=GB_MNC,
                            lac=123))
        session.flush()

        result = session.query(CellArea).first()
        assert result.region == 'GB'
Example #16
0
    def test_areaid_null(self, session):
        result = (session.query(CellArea).filter(
            CellArea.areaid.is_(None))).all()
        assert result == []

        with warnings.catch_warnings():
            warnings.simplefilter("ignore", SAWarning)
            session.add(
                CellArea(areaid=None,
                         radio=Radio.wcdma,
                         mcc=GB_MCC,
                         mnc=GB_MNC,
                         lac=1234))
            with pytest.raises(Exception):
                session.flush()
Example #17
0
    def test_areaid(self):
        areaid = (Radio.gsm, GB_MCC, GB_MNC, 1)
        self.session.add(CellArea(
            areaid=areaid,
            radio=Radio.wcdma, mcc=GB_MCC, mnc=GB_MNC, lac=1234))
        self.session.flush()

        result = self.session.query(CellArea).first()
        self.assertEqual(result.areaid, (Radio.gsm, GB_MCC, GB_MNC, 1))

        result = (self.session.query(CellArea)
                              .filter(CellArea.areaid == areaid)).first()
        self.assertEqual(result.areaid, (Radio.gsm, GB_MCC, GB_MNC, 1))

        query = self.session.query(CellArea).filter(CellArea.areaid == (1, 2))
        self.assertRaises(Exception, query.first)
Example #18
0
    def test_fields(self):
        session = self.session
        session.add(CellArea.create(
            radio=Radio.cdma, mcc=GB_MCC, mnc=GB_MNC, lac=1234, range=10,
            lat=GB_LAT, lon=GB_LON, avg_cell_range=10, num_cells=15))
        session.flush()

        result = session.query(CellArea).first()
        self.assertEqual(result.radio, Radio.cdma)
        self.assertEqual(result.mcc, GB_MCC)
        self.assertEqual(result.mnc, GB_MNC)
        self.assertEqual(result.lac, 1234)
        self.assertEqual(result.lat, GB_LAT)
        self.assertEqual(result.lon, GB_LON)
        self.assertEqual(result.range, 10)
        self.assertEqual(result.avg_cell_range, 10)
        self.assertEqual(result.num_cells, 15)
Example #19
0
    def test_areaid_hex(self, session):
        value = """\
cast(conv(substr(hex(`areaid`), 1, 2), 16, 10) as unsigned),
cast(conv(substr(hex(`areaid`), 3, 4), 16, 10) as unsigned),
cast(conv(substr(hex(`areaid`), 7, 4), 16, 10) as unsigned),
cast(conv(substr(hex(`areaid`), 11, 4), 16, 10) as unsigned)
"""
        session.add(
            CellArea(
                areaid=(Radio.gsm, 310, 1, 65534),
                radio=Radio.gsm,
                mcc=310,
                mnc=1,
                lac=65534,
            ))
        session.flush()
        stmt = "select %s from cell_area" % value
        row = session.execute(stmt).fetchone()
        assert row == (0, 310, 1, 65534)
Example #20
0
    def test_fields(self):
        self.session.add(CellArea.create(
            areaid=(Radio.wcdma, GB_MCC, GB_MNC, 1234),
            radio=Radio.wcdma, mcc=GB_MCC, mnc=GB_MNC, lac=1234,
            lat=GB_LAT, lon=GB_LON, region='GB',
            radius=10, avg_cell_radius=10, num_cells=15))
        self.session.flush()

        result = self.session.query(CellArea).first()
        self.assertEqual(result.areaid, (Radio.wcdma, GB_MCC, GB_MNC, 1234)),
        self.assertEqual(result.radio, Radio.wcdma)
        self.assertEqual(result.mcc, GB_MCC)
        self.assertEqual(result.mnc, GB_MNC)
        self.assertEqual(result.lac, 1234)
        self.assertEqual(result.lat, GB_LAT)
        self.assertEqual(result.lon, GB_LON)
        self.assertEqual(result.radius, 10)
        self.assertEqual(result.region, 'GB')
        self.assertEqual(result.avg_cell_radius, 10)
        self.assertEqual(result.num_cells, 15)
Example #21
0
    def test_fields(self, session):
        session.add(CellArea.create(
            areaid=(Radio.wcdma, GB_MCC, GB_MNC, 1234),
            radio=Radio.wcdma, mcc=GB_MCC, mnc=GB_MNC, lac=1234,
            lat=GB_LAT, lon=GB_LON, region='GB',
            radius=10, avg_cell_radius=10, num_cells=15))
        session.flush()

        result = session.query(CellArea).first()
        assert result.areaid == (Radio.wcdma, GB_MCC, GB_MNC, 1234)
        assert result.radio is Radio.wcdma
        assert result.mcc == GB_MCC
        assert result.mnc == GB_MNC
        assert result.lac == 1234
        assert result.lat == GB_LAT
        assert result.lon == GB_LON
        assert result.radius == 10
        assert result.region == 'GB'
        assert result.avg_cell_radius == 10
        assert result.num_cells == 15
Example #22
0
    def test_fields(self):
        session = self.session
        session.add(
            CellArea(radio=Radio.cdma,
                     mcc=GB_MCC,
                     mnc=GB_MNC,
                     lac=1234,
                     range=10,
                     lat=GB_LAT,
                     lon=GB_LON,
                     avg_cell_range=10,
                     num_cells=15))
        session.flush()

        result = session.query(CellArea).first()
        self.assertEqual(result.radio, Radio.cdma)
        self.assertEqual(result.mcc, GB_MCC)
        self.assertEqual(result.mnc, GB_MNC)
        self.assertEqual(result.lac, 1234)
        self.assertEqual(result.lat, GB_LAT)
        self.assertEqual(result.lon, GB_LON)
        self.assertEqual(result.range, 10)
        self.assertEqual(result.avg_cell_range, 10)
        self.assertEqual(result.num_cells, 15)
 def test_invalid(self):
     assert CellArea.validate({'radio': 'invalid'}) is None
Example #24
0
 def test_invalid(self):
     self.assertEqual(CellArea.validate({'radio': 'invalid'}), None)
Example #25
0
 def test_invalid(self):
     self.assertEqual(CellArea.validate({'radio': 'invalid'}), None)
Example #26
0
 def test_invalid(self):
     assert CellArea.validate({"radio": "invalid"}) is None
Example #27
0
 def test_invalid(self):
     assert CellArea.validate({'radio': 'invalid'}) is None