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


Python factories.BlueShardFactory类代码示例

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


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

示例1: test_update

    def test_update(self):
        area = CellAreaFactory(radio=Radio.gsm, num_cells=1)
        area.region = None
        BlueShardFactory.create_batch(2, region='CA')
        BlueShardFactory.create_batch(3, region='GB')
        CellAreaFactory(radio=Radio.gsm, region='DE', num_cells=1)
        CellAreaFactory(radio=Radio.gsm, region='DE', num_cells=2)
        CellAreaFactory(radio=Radio.gsm, region='CA', num_cells=2)
        CellAreaFactory(radio=Radio.wcdma, region='DE', num_cells=3)
        CellAreaFactory(radio=Radio.lte, region='CA', num_cells=4)
        WifiShardFactory.create_batch(5, region='DE')
        WifiShardFactory.create_batch(6, region='US')
        wifi = WifiShardFactory()
        wifi.region = None
        self.session.add(RegionStat(region='US', blue=1, wifi=2))
        self.session.add(RegionStat(region='TW', wifi=1))
        self.session.flush()

        update_statregion.delay().get()
        stats = self.session.query(RegionStat).all()
        self.assertEqual(len(stats), 4)

        for stat in stats:
            values = (stat.gsm, stat.wcdma, stat.lte, stat.blue, stat.wifi)
            if stat.region == 'DE':
                self.assertEqual(values, (3, 3, 0, 0, 5))
            elif stat.region == 'CA':
                self.assertEqual(values, (2, 0, 4, 2, 0))
            elif stat.region == 'GB':
                self.assertEqual(values, (0, 0, 0, 3, 0))
            elif stat.region == 'US':
                self.assertEqual(values, (0, 0, 0, 0, 6))
开发者ID:amolk4games,项目名称:ichnaea,代码行数:32,代码来源:test_stats.py

示例2: test_get_blue

 def test_get_blue(self):
     blues = BlueShardFactory.build_batch(2)
     query = Query(blue=self.blue_model_query(blues))
     self.assertEqual(self.cache.get(query), None)
     self.check_stats(counter=[
         ('locate.fallback.cache', 1, 1, ['status:miss']),
     ])
开发者ID:mate1983,项目名称:ichnaea,代码行数:7,代码来源:test_fallback.py

示例3: test_blue

    def test_blue(self, app, celery):
        blue = BlueShardFactory.build()
        self._post(app, [{
            'latitude': blue.lat,
            'longitude': blue.lon,
            'bluetoothBeacons': [{
                'macAddress': blue.mac,
                'age': 3,
                'signalStrength': -90,
                'name': 'my-beacon',
                'xtra_field': 3,
            }]},
        ])

        assert self.queue(celery).size() == 1
        item = self.queue(celery).dequeue()[0]
        assert item['api_key'] is None
        report = item['report']
        assert 'timestamp' in report
        position = report['position']
        assert position['latitude'] == blue.lat
        assert position['longitude'] == blue.lon
        blues = item['report']['bluetoothBeacons']
        assert len(blues) == 1
        assert blues[0]['macAddress'] == blue.mac
        assert blues[0]['age'] == 3
        assert blues[0]['signalStrength'] == -90
        assert blues[0]['name'] == 'my-beacon'
        assert 'xtra_field' not in blues[0]
开发者ID:amjadm61,项目名称:ichnaea,代码行数:29,代码来源:test_submit_v1.py

示例4: test_blue

    def test_blue(self):
        blue = BlueShardFactory.build()
        res = self._post([{
            'lat': blue.lat,
            'lon': blue.lon,
            'blue': [{
                'key': blue.mac,
                'age': 3000,
                'name': 'beacon',
                'signal': -101,
            }]},
        ])
        self.assertEqual(res.body, b'')

        self.assertEqual(self.queue.size(), 1)
        item = self.queue.dequeue()[0]
        self.assertEqual(item['api_key'], None)
        report = item['report']
        position = report['position']
        self.assertEqual(position['latitude'], blue.lat)
        self.assertEqual(position['longitude'], blue.lon)
        blues = item['report']['bluetoothBeacons']
        self.assertEqual(len(blues), 1)
        self.assertEqual(blues[0]['macAddress'], blue.mac)
        self.assertEqual(blues[0]['age'], 3000),
        self.assertEqual(blues[0]['name'], 'beacon'),
        self.assertEqual(blues[0]['signalStrength'], -101),
开发者ID:amolk4games,项目名称:ichnaea,代码行数:27,代码来源:test_submit_v0.py

示例5: test_blue

    def test_blue(self, app, celery):
        blue = BlueShardFactory.build()
        res = self._post(app, [{
            'lat': blue.lat,
            'lon': blue.lon,
            'source': '',
            'blue': [{
                'key': blue.mac,
                'age': 3000,
                'name': 'beacon',
                'signal': -101,
            }]},
        ])
        assert res.body == b''

        assert self.queue(celery).size() == 1
        item = self.queue(celery).dequeue()[0]
        assert item['api_key'] is None
        report = item['report']
        position = report['position']
        assert position['latitude'] == blue.lat
        assert position['longitude'] == blue.lon
        assert 'source' not in position
        blues = item['report']['bluetoothBeacons']
        assert len(blues) == 1
        assert blues[0]['macAddress'] == blue.mac
        assert blues[0]['age'] == 3000
        assert blues[0]['name'] == 'beacon'
        assert blues[0]['signalStrength'] == -101
开发者ID:amjadm61,项目名称:ichnaea,代码行数:29,代码来源:test_submit_v0.py

示例6: test_blue_miss

    def test_blue_miss(self):
        blues = BlueShardFactory.build_batch(2, samples=10)
        self.session.flush()

        query = self.model_query(blues=blues)
        results = self.source.search(query)
        self.check_model_results(results, None)
开发者ID:amolk4games,项目名称:ichnaea,代码行数:7,代码来源:test_internal.py

示例7: add_reports

    def add_reports(self, num=1, blue_factor=0, cell_factor=1, wifi_factor=2,
                    api_key='test', nickname=None,
                    blue_key=None, cell_mcc=None, wifi_key=None,
                    lat=None, lon=None):
        reports = []
        for i in range(num):
            pos = CellShardFactory.build()
            report = {
                'timestamp': time.time() * 1000.0,
                'position': {},
                'bluetoothBeacons': [],
                'cellTowers': [],
                'wifiAccessPoints': [],
            }
            report['position']['latitude'] = lat or pos.lat
            report['position']['longitude'] = lon or pos.lon
            report['position']['accuracy'] = 17.0 + i

            blues = BlueShardFactory.build_batch(blue_factor,
                                                 lat=pos.lat, lon=pos.lon)
            for blue in blues:
                blue_data = {
                    'macAddress': blue_key or blue.mac,
                    'signalStrength': -100 + i,
                }
                report['bluetoothBeacons'].append(blue_data)

            cells = CellShardFactory.build_batch(cell_factor,
                                                 lat=pos.lat, lon=pos.lon)
            for cell in cells:
                cell_data = {
                    'radioType': cell.radio.name,
                    'mobileCountryCode': cell_mcc or cell.mcc,
                    'mobileNetworkCode': cell.mnc,
                    'locationAreaCode': cell.lac,
                    'cellId': cell.cid,
                    'primaryScramblingCode': cell.psc,
                    'signalStrength': -110 + i,
                }
                report['cellTowers'].append(cell_data)

            wifis = WifiShardFactory.build_batch(wifi_factor,
                                                 lat=pos.lat, lon=pos.lon)
            for wifi in wifis:
                wifi_data = {
                    'macAddress': wifi_key or wifi.mac,
                    'signalStrength': -90 + i,
                    'ssid': 'my-wifi',
                }
                report['wifiAccessPoints'].append(wifi_data)

            reports.append(report)

        items = [{'api_key': api_key,
                  'nickname': nickname,
                  'report': rep} for rep in reports]

        self.incoming_queue.enqueue(items)
        update_incoming.delay().get()
        return reports
开发者ID:mate1983,项目名称:ichnaea,代码行数:60,代码来源:base.py

示例8: test_blue

    def test_blue(self):
        blue = BlueShardFactory.build()
        self._post([{
            'latitude': blue.lat,
            'longitude': blue.lon,
            'bluetoothBeacons': [{
                'macAddress': blue.mac,
                'age': 3,
                'signalStrength': -90,
                'name': 'my-beacon',
                'xtra_field': 3,
            }]},
        ])

        self.assertEqual(self.queue.size(), 1)
        item = self.queue.dequeue()[0]
        self.assertEqual(item['api_key'], None)
        report = item['report']
        self.assertTrue('timestamp' in report)
        position = report['position']
        self.assertEqual(position['latitude'], blue.lat)
        self.assertEqual(position['longitude'], blue.lon)
        blues = item['report']['bluetoothBeacons']
        self.assertEqual(len(blues), 1)
        self.assertEqual(blues[0]['macAddress'], blue.mac)
        self.assertEqual(blues[0]['age'], 3),
        self.assertEqual(blues[0]['signalStrength'], -90),
        self.assertEqual(blues[0]['name'], 'my-beacon'),
        self.assertFalse('xtra_field' in blues[0])
开发者ID:amolk4games,项目名称:ichnaea,代码行数:29,代码来源:test_submit_v1.py

示例9: test_get_blue

 def test_get_blue(self, cache, stats):
     blues = BlueShardFactory.build_batch(2)
     query = self._query(blue=self.blue_model_query(blues))
     assert cache.get(query) is None
     stats.check(counter=[
         ('locate.fallback.cache', 1, 1,
             [self.fallback_tag, 'status:miss']),
     ])
开发者ID:crankycoder,项目名称:ichnaea,代码行数:8,代码来源:test_fallback.py

示例10: test_blue_duplicates

 def test_blue_duplicates(self):
     blue = BlueShardFactory.build()
     query = Query(blue=[
         {'macAddress': blue.mac, 'signalStrength': -90},
         {'macAddress': blue.mac, 'signalStrength': -82},
         {'macAddress': blue.mac, 'signalStrength': -85},
     ])
     assert len(query.blue) == 0
开发者ID:crankycoder,项目名称:ichnaea,代码行数:8,代码来源:test_query.py

示例11: test_blue_duplicates

 def test_blue_duplicates(self):
     blue = BlueShardFactory.build()
     query = Query(blue=[
         {'mac': blue.mac, 'signal': -90},
         {'mac': blue.mac, 'signal': -82},
         {'mac': blue.mac, 'signal': -85},
     ])
     self.assertEqual(len(query.blue), 0)
开发者ID:amolk4games,项目名称:ichnaea,代码行数:8,代码来源:test_query.py

示例12: test_check_one_blue

    def test_check_one_blue(self, geoip_db, http_session,
                            session, source, stats):
        blue = BlueShardFactory.build()

        query = self.model_query(
            geoip_db, http_session, session, stats,
            blues=[blue])
        self.check_should_search(source, query, False)
开发者ID:crankycoder,项目名称:ichnaea,代码行数:8,代码来源:test_fallback.py

示例13: test_blue_miss

    def test_blue_miss(self, geoip_db, http_session,
                       session, source, stats):
        blues = BlueShardFactory.build_batch(2, samples=10)
        session.flush()

        query = self.model_query(
            geoip_db, http_session, session, stats,
            blues=blues)
        results = source.search(query)
        self.check_model_results(results, None)
开发者ID:crankycoder,项目名称:ichnaea,代码行数:10,代码来源:test_internal.py

示例14: test_set_blue

 def test_set_blue(self):
     blues = BlueShardFactory.build_batch(2)
     blue = blues[0]
     query = Query(blue=self.blue_model_query(blues))
     result = ExternalResult(blue.lat, blue.lon, blue.radius, None)
     self.cache.set(query, result)
     self.assertEqual(self.cache.get(query), result)
     self.check_stats(counter=[
         ('locate.fallback.cache', 1, 1, ['status:hit']),
     ])
开发者ID:mate1983,项目名称:ichnaea,代码行数:10,代码来源:test_fallback.py

示例15: test_set_blue

 def test_set_blue(self, cache, stats):
     blues = BlueShardFactory.build_batch(2)
     blue = blues[0]
     query = self._query(blue=self.blue_model_query(blues))
     result = ExternalResult(blue.lat, blue.lon, blue.radius, None)
     cache.set(query, result)
     assert cache.get(query) == result
     stats.check(counter=[
         ('locate.fallback.cache', 1, 1,
             [self.fallback_tag, 'status:hit']),
     ])
开发者ID:crankycoder,项目名称:ichnaea,代码行数:11,代码来源:test_fallback.py


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