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


Python CellFactory.build方法代码示例

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


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

示例1: test_invalid_radiotype

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

示例2: test_cache_single_cell

# 需要导入模块: from ichnaea.tests.factories import CellFactory [as 别名]
# 或者: from ichnaea.tests.factories.CellFactory import build [as 别名]
    def test_cache_single_cell(self):
        cell = CellFactory.build()

        with requests_mock.Mocker() as mock_request:
            mock_request.register_uri(
                'POST', requests_mock.ANY, json=self.fallback_result)

            query = self.model_query(cells=[cell])
            query.cell[0].signal = -77
            result = self.source.search(query)
            self.check_model_result(result, self.fallback_model)

            self.assertEqual(mock_request.call_count, 1)
            self.check_stats(counter=[
                ('locate.fallback.cache', ['status:miss']),
                ('locate.fallback.lookup', ['status:200']),
            ], timer=[
                'locate.fallback.lookup',
            ])

            # vary the signal strength, not part of cache key
            query.cell[0].signal = -82
            result = self.source.search(query)
            self.check_model_result(result, self.fallback_model)

            self.assertEqual(mock_request.call_count, 1)
            self.check_stats(counter=[
                ('locate.fallback.cache', ['status:hit']),
                ('locate.fallback.lookup', ['status:200']),
            ], timer=[
                'locate.fallback.lookup',
            ])
开发者ID:voolitels,项目名称:ichnaea,代码行数:34,代码来源:test_fallback.py

示例3: test_locate_finds_country_from_mcc

# 需要导入模块: from ichnaea.tests.factories import CellFactory [as 别名]
# 或者: from ichnaea.tests.factories.CellFactory import build [as 别名]
    def test_locate_finds_country_from_mcc(self):
        country = mobile_codes.mcc("235")[0]
        cell = CellFactory.build(mcc=235)

        query = self.model_query(cells=[cell])
        location = self.provider.locate(query)
        self.check_model_location(location, country)
开发者ID:SOFTowaha,项目名称:ichnaea,代码行数:9,代码来源:test_cell.py

示例4: test_set_cache_redis_failure

# 需要导入模块: from ichnaea.tests.factories import CellFactory [as 别名]
# 或者: from ichnaea.tests.factories.CellFactory import build [as 别名]
    def test_set_cache_redis_failure(self):
        cell = CellFactory.build()
        mock_redis_client = self._mock_redis_client()
        mock_redis_client.mget.return_value = []
        mock_redis_client.mset.side_effect = RedisError()
        mock_redis_client.expire.side_effect = RedisError()
        mock_redis_client.execute.side_effect = RedisError()

        with requests_mock.Mocker() as mock_request:
            mock_request.register_uri(
                'POST', requests_mock.ANY, json=self.fallback_result)

            with mock.patch.object(self.source.cache, 'redis_client',
                                   mock_redis_client):
                query = self.model_query(cells=[cell])
                result = self.source.search(query)
                self.check_model_result(result, self.fallback_model)

            self.assertTrue(mock_redis_client.mget.called)
            self.assertTrue(mock_redis_client.mset.called)
            self.assertTrue(mock_request.called)

        self.check_stats(counter=[
            ('locate.fallback.cache', ['status:miss']),
        ])
开发者ID:voolitels,项目名称:ichnaea,代码行数:27,代码来源:test_fallback.py

示例5: test_empty_result_from_fallback_cached

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

示例6: test_success

# 需要导入模块: from ichnaea.tests.factories import CellFactory [as 别名]
# 或者: from ichnaea.tests.factories.CellFactory import build [as 别名]
    def test_success(self):
        cell = CellFactory.build()

        with requests_mock.Mocker() as mock_request:
            mock_request.register_uri(
                'POST', requests_mock.ANY, json=self.fallback_result)

            query = self.model_query(
                cells=[cell],
                fallback={
                    'lacf': True,
                    'ipf': False,
                },
            )
            result = self.source.search(query)
            self.check_model_result(result, self.fallback_model)

            request_json = mock_request.request_history[0].json()

        self.assertEqual(request_json['fallbacks'], {'lacf': True})
        self.check_stats(counter=[
            ('locate.fallback.lookup', ['status:200']),
        ], timer=[
            'locate.fallback.lookup',
        ])
开发者ID:voolitels,项目名称:ichnaea,代码行数:27,代码来源:test_fallback.py

示例7: test_cell

# 需要导入模块: from ichnaea.tests.factories import CellFactory [as 别名]
# 或者: from ichnaea.tests.factories.CellFactory import build [as 别名]
    def test_cell(self):
        cell = CellFactory.build()
        cell_query = {
            'radio': cell.radio.name,
            'mcc': cell.mcc,
            'mnc': cell.mnc,
            'lac': cell.lac,
            'cid': cell.cid,
            'psc': cell.psc,
            'signal': -90,
            'ta': 1,
        }
        query = Query(cell=[cell_query])

        self.assertEqual(len(query.cell), 1)
        query_cell = query.cell[0]
        for key, value in cell_query.items():
            if key == 'radio':
                self.assertEqual(query_cell[key], cell.radio)
            else:
                self.assertEqual(query_cell[key], value)

        self.assertEqual(len(query.cell_area), 1)
        query_area = query.cell_area[0]
        for key, value in cell_query.items():
            if key == 'radio':
                self.assertEqual(query_area[key], cell.radio)
            elif key in ('cid', 'psc'):
                pass
            else:
                self.assertEqual(query_area[key], value)
开发者ID:SOFTowaha,项目名称:ichnaea,代码行数:33,代码来源:test_query.py

示例8: test_blacklist

# 需要导入模块: from ichnaea.tests.factories import CellFactory [as 别名]
# 或者: from ichnaea.tests.factories.CellFactory import build [as 别名]
    def test_blacklist(self):
        now = util.utcnow()

        cell = CellFactory.build()
        observations = [dict(radio=int(cell.radio), mcc=cell.mcc,
                             mnc=cell.mnc, lac=cell.lac, cid=cell.cid + i,
                             psc=cell.psc,
                             lat=cell.lat + i * 0.0000001,
                             lon=cell.lon + i * 0.0000001)
                        for i in range(1, 4)]

        black = CellBlacklist(
            radio=cell.radio, mcc=cell.mcc, mnc=cell.mnc,
            lac=cell.lac, cid=cell.cid + 1,
            time=now, count=1,
        )
        self.session.add(black)
        self.session.flush()

        result = insert_measures_cell.delay(observations)
        self.assertEqual(result.get(), 2)

        self.assertEqual(self.data_queue.size(), 2)
        update_cell.delay().get()

        cells = self.session.query(Cell).all()
        self.assertEqual(len(cells), 2)

        self.check_statcounter(StatKey.cell, 2)
        self.check_statcounter(StatKey.unique_cell, 2)
开发者ID:SOFTowaha,项目名称:ichnaea,代码行数:32,代码来源:test_observation.py

示例9: add_reports

# 需要导入模块: from ichnaea.tests.factories import CellFactory [as 别名]
# 或者: from ichnaea.tests.factories.CellFactory import build [as 别名]
    def add_reports(self, number=3, api_key='test', email=None):
        reports = []
        for i in range(number):
            report = {
                'timestamp': time.time() * 1000.0,
                'position': {},
                'cellTowers': [],
                'wifiAccessPoints': [],
            }
            cell = CellFactory.build()
            report['position']['latitude'] = cell.lat
            report['position']['longitude'] = cell.lon
            report['position']['accuracy'] = 17 + i
            cell_data = {
                'radioType': cell.radio.name,
                'mobileCountryCode': cell.mcc,
                'mobileNetworkCode': cell.mnc,
                'locationAreaCode': cell.lac,
                'cellId': cell.cid,
                'primaryScramblingCode': cell.psc,
                'signalStrength': -110 + i,
            }
            report['cellTowers'].append(cell_data)
            wifis = WifiFactory.build_batch(2, lat=cell.lat, lon=cell.lon)
            for wifi in wifis:
                wifi_data = {
                    'macAddress': wifi.key,
                    'signalStrength': -90 + i,
                }
                report['wifiAccessPoints'].append(wifi_data)
            reports.append(report)

        queue_reports.delay(
            reports=reports, api_key=api_key, email=email).get()
        return reports
开发者ID:awoland,项目名称:ichnaea,代码行数:37,代码来源:test_export.py

示例10: test_duplicated_cell_observations

# 需要导入模块: from ichnaea.tests.factories import CellFactory [as 别名]
# 或者: from ichnaea.tests.factories.CellFactory import build [as 别名]
 def test_duplicated_cell_observations(self):
     session = self.session
     cell = CellFactory.build()
     self.app.post_json(
         '/v1/geosubmit?key=test',
         {"items": [
             {"latitude": cell.lat,
              "longitude": cell.lon,
              "cellTowers": [
                  {"radioType": cell.radio.name,
                   "mobileCountryCode": cell.mcc,
                   "mobileNetworkCode": cell.mnc,
                   "locationAreaCode": cell.lac,
                   "cellId": cell.cid,
                   "asu": 10},
                  {"radioType": cell.radio.name,
                   "mobileCountryCode": cell.mcc,
                   "mobileNetworkCode": cell.mnc,
                   "locationAreaCode": cell.lac,
                   "cellId": cell.cid,
                   "asu": 16},
              ]},
         ]},
         status=200)
     self.assertEquals(session.query(CellObservation).count(), 1)
开发者ID:awoland,项目名称:ichnaea,代码行数:27,代码来源:tests.py

示例11: test_blacklist_time_used_as_creation_time

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

示例12: test_database_error

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

示例13: test_cell

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

示例14: test_single_cell_results_cached_preventing_external_call

# 需要导入模块: from ichnaea.tests.factories import CellFactory [as 别名]
# 或者: from ichnaea.tests.factories.CellFactory import build [as 别名]
    def test_single_cell_results_cached_preventing_external_call(self):
        cell = CellFactory.build()

        with requests_mock.Mocker() as mock_request:
            mock_request.register_uri(
                'POST', requests_mock.ANY, json=self.fallback_location)

            query = self.model_query(cells=[cell])
            query.cell[0]['signal'] = -77
            location = self.provider.locate(query)
            self.check_model_location(location, self.fallback_model)

            self.assertEqual(mock_request.call_count, 1)
            self.check_stats(
                counter=[
                    'm.fallback.lookup_status.200',
                    'm.fallback.cache.miss',
                ],
                timer=['m.fallback.lookup'])

            # vary the signal strength, not part of cache key
            query.cell[0]['signal'] = -82
            location = self.provider.locate(query)
            self.check_model_location(location, self.fallback_model)

            self.assertEqual(mock_request.call_count, 1)
            self.check_stats(
                counter=[
                    'm.fallback.lookup_status.200',
                    'm.fallback.cache.hit',
                ],
                timer=['m.fallback.lookup'])
开发者ID:SOFTowaha,项目名称:ichnaea,代码行数:34,代码来源:test_fallback.py

示例15: test_cache_empty_result

# 需要导入模块: from ichnaea.tests.factories import CellFactory [as 别名]
# 或者: from ichnaea.tests.factories.CellFactory import build [as 别名]
    def test_cache_empty_result(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])
            result = self.source.search(query)
            self.check_model_result(result, None)

            self.assertEqual(mock_request.call_count, 1)
            self.check_stats(counter=[
                ('locate.fallback.cache', ['status:miss']),
                ('locate.fallback.lookup', ['status:404']),
            ])

            query = self.model_query(cells=[cell])
            result = self.source.search(query)
            self.check_model_result(result, None)

            self.assertEqual(mock_request.call_count, 1)
            self.check_stats(counter=[
                ('locate.fallback.cache', ['status:hit']),
                ('locate.fallback.lookup', ['status:404']),
            ])
开发者ID:voolitels,项目名称:ichnaea,代码行数:32,代码来源:test_fallback.py


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