Exemplo n.º 1
0
    def test_remove(self):
        area = CellAreaOCIDFactory()
        self.session.flush()

        areaid = encode_cellarea(*area.areaid)
        self.area_queue.enqueue([areaid], json=False)
        update_cellarea_ocid.delay().get()
        self.assertEqual(self.session.query(CellAreaOCID).count(), 0)
Exemplo n.º 2
0
 def import_csv(self, lo=1, hi=10, time=1408604686, cell_type='ocid'):
     task = FakeTask(self.celery_app)
     with self.get_csv(lo=lo, hi=hi, time=time) as path:
         with redis_pipeline(self.redis_client) as pipe:
             ImportLocal(task, pipe, cell_type=cell_type)(
                 self.session, filename=path)
     if cell_type == 'ocid':
         update_cellarea_ocid.delay().get()
     else:
         update_cellarea.delay().get()
Exemplo n.º 3
0
 def import_csv(self, lo=1, hi=10, time=1408604686, cell_type='ocid'):
     task = FakeTask(self.celery_app)
     with self.get_csv(lo=lo, hi=hi, time=time) as path:
         with redis_pipeline(self.redis_client) as pipe:
             ImportLocal(task, self.session, pipe,
                         cell_type=cell_type)(filename=path)
     if cell_type == 'ocid':
         update_cellarea_ocid.delay().get()
     else:
         update_cellarea.delay().get()
Exemplo n.º 4
0
 def import_csv(self, celery, redis, session, cell,
                lo=1, hi=10, time=1408604686, cell_type='ocid'):
     task = FakeTask(celery)
     with self.get_csv(cell, lo=lo, hi=hi, time=time) as path:
         with redis_pipeline(redis) as pipe:
             ImportLocal(task, cell_type=cell_type)(
                 pipe, session, filename=path)
     if cell_type == 'ocid':
         update_cellarea_ocid.delay().get()
     else:
         update_cellarea.delay().get()
Exemplo n.º 5
0
    def test_region_outside_tie(self):
        cell = CellOCIDFactory(
            radio=Radio.gsm, mcc=310, mnc=1, lac=1, cid=1,
            lat=18.33, lon=-64.9, radius=10000, region='PR')
        CellOCIDFactory(
            radio=cell.radio, mcc=cell.mcc, mnc=cell.mnc, lac=cell.lac, cid=2,
            lat=18.34, lon=-64.9, radius=10000, region='PR')
        self.session.flush()

        self.area_queue.enqueue([cell.areaid], json=False)
        update_cellarea_ocid.delay().get()

        area = self.session.query(CellAreaOCID).one()
        self.assertEqual(area.region, 'PR')
Exemplo n.º 6
0
    def test_region(self):
        cell = CellOCIDFactory(
            radio=Radio.gsm, mcc=425, mnc=1, lac=1, cid=1,
            lat=32.2, lon=35.0, radius=10000, region='XW')
        CellOCIDFactory(
            radio=cell.radio, mcc=cell.mcc, mnc=cell.mnc, lac=cell.lac, cid=2,
            lat=32.2, lon=34.9, radius=10000, region='IL')
        self.session.flush()

        self.area_queue.enqueue([cell.areaid], json=False)
        update_cellarea_ocid.delay().get()

        area = self.session.query(CellAreaOCID).one()
        self.assertEqual(area.region, 'IL')
Exemplo n.º 7
0
    def test_import_external(self):
        with self.get_csv() as path:
            with open(path, 'rb') as gzip_file:
                with requests_mock.Mocker() as req_m:
                    req_m.register_uri('GET', re.compile('.*'), body=gzip_file)
                    cell_import_external.delay().get()

        update_cellarea_ocid.delay().get()
        cells = (self.session.query(CellOCID)
                             .order_by(CellOCID.modified).all())
        self.assertEqual(len(cells), 9)

        areaids = set([cell.areaid for cell in cells])
        self.assertEqual(
            self.session.query(CellAreaOCID).count(), len(areaids))
Exemplo n.º 8
0
    def test_import_external(self):
        with self.get_csv() as path:
            with open(path, 'rb') as gzip_file:
                with requests_mock.Mocker() as req_m:
                    req_m.register_uri('GET', re.compile('.*'), body=gzip_file)
                    cell_import_external.delay().get()

        update_cellarea_ocid.delay().get()
        cells = (self.session.query(CellOCID).order_by(
            CellOCID.modified).all())
        self.assertEqual(len(cells), 9)

        areaids = set([cell.areaid for cell in cells])
        self.assertEqual(
            self.session.query(CellAreaOCID).count(), len(areaids))
Exemplo n.º 9
0
    def test_new(self):
        cell = CellOCIDFactory()
        self.session.flush()

        areaid = encode_cellarea(
            cell.radio, cell.mcc, cell.mnc, cell.lac)
        self.area_queue.enqueue([areaid], json=False)
        update_cellarea_ocid.delay().get()

        area = self.session.query(CellAreaOCID).one()
        self.assertAlmostEqual(area.lat, cell.lat)
        self.assertAlmostEqual(area.lon, cell.lon)
        self.assertEqual(area.radius, 0)
        self.assertEqual(area.region, 'GB')
        self.assertEqual(area.num_cells, 1)
        self.assertEqual(area.avg_cell_radius, cell.radius)
Exemplo n.º 10
0
    def test_import_external(self, celery, session):
        with self.get_csv(CellShardFactory.build(radio=Radio.wcdma)) as path:
            with open(path, 'rb') as gzip_file:
                with requests_mock.Mocker() as req_m:
                    req_m.register_uri('GET', re.compile('.*'), body=gzip_file)
                    cell_import_external.delay().get()

        update_cellarea_ocid.delay().get()

        model = CellShardOCID.shards()['wcdma']
        cells = (session.query(model)
                        .order_by(model.modified).all())
        assert len(cells) == 9

        areaids = set([cell.areaid for cell in cells])
        assert session.query(CellAreaOCID).count() == len(areaids)