当前位置: 首页>>代码示例>>Python>>正文


Python CellFactory.create_batch方法代码示例

本文整理汇总了Python中ichnaea.tests.factories.CellFactory.create_batch方法的典型用法代码示例。如果您正苦于以下问题:Python CellFactory.create_batch方法的具体用法?Python CellFactory.create_batch怎么用?Python CellFactory.create_batch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ichnaea.tests.factories.CellFactory的用法示例。


在下文中一共展示了CellFactory.create_batch方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_export_full

# 需要导入模块: from ichnaea.tests.factories import CellFactory [as 别名]
# 或者: from ichnaea.tests.factories.CellFactory import create_batch [as 别名]
    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)
开发者ID:therewillbecode,项目名称:ichnaea,代码行数:12,代码来源:test_ocid.py

示例2: test_daily_export

# 需要导入模块: from ichnaea.tests.factories import CellFactory [as 别名]
# 或者: from ichnaea.tests.factories.CellFactory import create_batch [as 别名]
    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)
开发者ID:SOFTowaha,项目名称:ichnaea,代码行数:12,代码来源:tests.py

示例3: test_fallback

# 需要导入模块: from ichnaea.tests.factories import CellFactory [as 别名]
# 或者: from ichnaea.tests.factories.CellFactory import create_batch [as 别名]
    def test_fallback(self):
        # this tests a cell + wifi based query which gets a cell based
        # internal result and continues on to the fallback to get a
        # better wifi based result
        cells = CellFactory.create_batch(2, radio=Radio.wcdma)
        wifis = WifiShardFactory.build_batch(3)
        api_key = self.session.query(ApiKey).get('test')
        api_key.allow_fallback = True
        self.session.flush()

        with requests_mock.Mocker() as mock:
            response_result = {
                'location': {
                    'lat': 1.0,
                    'lng': 1.0,
                },
                'accuracy': 100,
            }
            mock.register_uri(
                'POST', requests_mock.ANY, json=response_result)

            query = self.model_query(cells=cells, wifis=wifis)
            res = self._call(body=query)

            send_json = mock.request_history[0].json()
            self.assertEqual(len(send_json['cellTowers']), 2)
            self.assertEqual(len(send_json['wifiAccessPoints']), 3)
            self.assertEqual(send_json['cellTowers'][0]['radioType'], 'wcdma')

        self.check_model_response(res, None, lat=1.0, lon=1.0, accuracy=100)
        self.check_stats(counter=[
            ('request', [self.metric_path, 'method:post', 'status:200']),
            (self.metric_type + '.request', [self.metric_path, 'key:test']),
            (self.metric_type + '.query',
                ['key:test', 'country:none',
                 'geoip:false', 'cell:many', 'wifi:many']),
            (self.metric_type + '.result',
                ['key:test', 'country:none',
                 'accuracy:high', 'status:hit', 'source:fallback']),
            (self.metric_type + '.source',
                ['key:test', 'country:none', 'source:internal',
                 'accuracy:high', 'status:miss']),
            (self.metric_type + '.source',
                ['key:test', 'country:none', 'source:fallback',
                 'accuracy:high', 'status:hit']),
        ], timer=[
            ('request', [self.metric_path, 'method:post']),
        ])
开发者ID:therewillbecode,项目名称:ichnaea,代码行数:50,代码来源:base.py

示例4: test_fallback_used_with_geoip

# 需要导入模块: from ichnaea.tests.factories import CellFactory [as 别名]
# 或者: from ichnaea.tests.factories.CellFactory import create_batch [as 别名]
    def test_fallback_used_with_geoip(self):
        cells = CellFactory.create_batch(2, radio=Radio.wcdma)
        wifis = WifiShardFactory.build_batch(3)
        api_key = self.session.query(ApiKey).get('test')
        api_key.allow_fallback = True
        self.session.flush()

        with requests_mock.Mocker() as mock:
            response_result = {
                'location': {
                    'lat': 1.0,
                    'lng': 1.0,
                },
                'accuracy': 100,
            }
            mock.register_uri(
                'POST', requests_mock.ANY, json=response_result)

            query = self.model_query(cells=cells, wifis=wifis)
            res = self._call(body=query, ip=self.test_ip)

            send_json = mock.request_history[0].json()
            self.assertEqual(len(send_json['cellTowers']), 2)
            self.assertEqual(len(send_json['wifiAccessPoints']), 3)

        self.check_model_response(res, None, lat=1.0, lon=1.0, accuracy=100)
        self.check_stats(counter=[
            ('request', [self.metric_path, 'method:post', 'status:200']),
            (self.metric_type + '.request', [self.metric_path, 'key:test']),
            (self.metric_type + '.result',
                ['key:test', 'country:GB',
                 'accuracy:high', 'status:hit', 'source:fallback']),
            (self.metric_type + '.source',
                ['key:test', 'country:GB', 'source:fallback',
                 'accuracy:high', 'status:hit']),
        ], timer=[
            ('request', [self.metric_path, 'method:post']),
        ])
开发者ID:therewillbecode,项目名称:ichnaea,代码行数:40,代码来源:base.py

示例5: test_blocklist_moving_cells

# 需要导入模块: from ichnaea.tests.factories import CellFactory [as 别名]
# 或者: from ichnaea.tests.factories.CellFactory import create_batch [as 别名]
    def test_blocklist_moving_cells(self):
        now = util.utcnow()
        obs = []
        obs_factory = CellObservationFactory
        moving = set()
        cells = CellFactory.create_batch(4)
        cells.append(CellFactory.build())
        # a cell with an entry but no prior position
        cell = cells[0]
        cell_key = cell.hashkey().__dict__
        cell.total_measures = 0
        obs.extend([
            obs_factory(lat=cell.lat + 0.01,
                        lon=cell.lon + 0.01, **cell_key),
            obs_factory(lat=cell.lat + 0.02,
                        lon=cell.lon + 0.05, **cell_key),
            obs_factory(lat=cell.lat + 0.03,
                        lon=cell.lon + 0.09, **cell_key),
        ])
        cell.lat = None
        cell.lon = None
        # a cell with a prior known position
        cell = cells[1]
        cell_key = cell.hashkey().__dict__
        cell.total_measures = 1
        cell.lat += 0.1
        obs.extend([
            obs_factory(lat=cell.lat + 1.0,
                        lon=cell.lon, **cell_key),
            obs_factory(lat=cell.lat + 3.0,
                        lon=cell.lon, **cell_key),
        ])
        moving.add(cell.hashkey())
        # a cell with a very different prior position
        cell = cells[2]
        cell_key = cell.hashkey().__dict__
        cell.total_measures = 1
        obs.extend([
            obs_factory(lat=cell.lat + 4.0,
                        lon=cell.lon, **cell_key),
            obs_factory(lat=cell.lat - 0.1,
                        lon=cell.lon, **cell_key),
        ])
        moving.add(cell.hashkey())
        # another cell with a prior known position (and negative lon)
        cell = cells[3]
        cell_key = cell.hashkey().__dict__
        cell.total_measures = 1
        cell.lon *= -1.0
        obs.extend([
            obs_factory(lat=cell.lat + 1.0,
                        lon=cell.lon, **cell_key),
            obs_factory(lat=cell.lat + 2.0,
                        lon=cell.lon, **cell_key),
        ])
        moving.add(cell.hashkey())
        # an already blocklisted cell
        cell = cells[4]
        cell_key = cell.hashkey().__dict__
        CellBlocklistFactory(time=now, count=1, **cell_key)
        obs.extend([
            obs_factory(lat=cell.lat,
                        lon=cell.lon, **cell_key),
            obs_factory(lat=cell.lat + 3.0,
                        lon=cell.lon, **cell_key),
        ])
        moving.add(cell.hashkey())

        self.data_queue.enqueue(obs)
        self.session.commit()
        update_cell.delay().get()

        block = self.session.query(CellBlocklist).all()
        self.assertEqual(set([b.hashkey() for b in block]), moving)

        # test duplicate call
        update_cell.delay().get()

        self.check_stats(counter=[
            ('data.station.blocklist', 1, 3,
                ['type:cell', 'action:add', 'reason:moving']),
        ], timer=[
            # We made duplicate calls
            ('task', 2, ['task:data.update_cell']),
            # One of those would've scheduled a remove_cell task
            ('task', 1, ['task:data.remove_cell'])
        ])
开发者ID:therewillbecode,项目名称:ichnaea,代码行数:89,代码来源:test_station.py


注:本文中的ichnaea.tests.factories.CellFactory.create_batch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。