Exemple #1
0
    def test_fallback(self, app, ro_session, stats):
        # 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 = CellShardFactory.create_batch(
            2, session=ro_session, radio=Radio.wcdma)
        wifis = WifiShardFactory.build_batch(3)
        api_key = ApiKey.get(ro_session, 'test')
        api_key.allow_fallback = True
        ro_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(app, body=query)

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

        self.check_model_response(res, None, lat=1.0, lon=1.0, accuracy=100)
        stats.check(counter=[
            ('request', [self.metric_path, 'method:post', 'status:200']),
            (self.metric_type + '.request', [self.metric_path, 'key:test']),
            (self.metric_type + '.query',
                ['key:test', 'region:none',
                 'geoip:false', 'blue:none', 'cell:many', 'wifi:many']),
            (self.metric_type + '.result',
                ['key:test', 'region:none', 'fallback_allowed:true',
                 'accuracy:high', 'status:hit', 'source:fallback']),
            (self.metric_type + '.source',
                ['key:test', 'region:none', 'source:internal',
                 'accuracy:high', 'status:miss']),
            (self.metric_type + '.source',
                ['key:test', 'region:none', 'source:fallback',
                 'accuracy:high', 'status:hit']),
        ], timer=[
            ('request', [self.metric_path, 'method:post']),
        ])
Exemple #2
0
    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 = CellShardFactory.create_batch(2, radio=Radio.wcdma)
        wifis = WifiShardFactory.build_batch(3)
        api_key = ApiKey.get(self.session, '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', 'region:none',
                 'geoip:false', 'blue:none', 'cell:many', 'wifi:many']),
            (self.metric_type + '.result',
                ['key:test', 'region:none', 'fallback_allowed:true',
                 'accuracy:high', 'status:hit', 'source:fallback']),
            (self.metric_type + '.source',
                ['key:test', 'region:none', 'source:internal',
                 'accuracy:high', 'status:miss']),
            (self.metric_type + '.source',
                ['key:test', 'region:none', 'source:fallback',
                 'accuracy:high', 'status:hit']),
        ], timer=[
            ('request', [self.metric_path, 'method:post']),
        ])
Exemple #3
0
    def test_fallback_used_with_geoip(self, app, ro_session, stats):
        cells = CellShardFactory.create_batch(
            2, session=ro_session, radio=Radio.wcdma)
        wifis = WifiShardFactory.build_batch(3)
        api_key = ApiKey.get(ro_session, 'test')
        api_key.allow_fallback = True
        ro_session.flush()

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

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

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

        self.check_model_response(res, None, lat=1.0, lon=1.0, accuracy=100)
        stats.check(counter=[
            ('request', [self.metric_path, 'method:post', 'status:200']),
            (self.metric_type + '.request', [self.metric_path, 'key:test']),
            (self.metric_type + '.result',
                ['key:test', 'region:GB', 'fallback_allowed:true',
                 'accuracy:high', 'status:hit', 'source:fallback']),
            (self.metric_type + '.source',
                ['key:test', 'region:GB', 'source:fallback',
                 'accuracy:high', 'status:hit']),
        ], timer=[
            ('request', [self.metric_path, 'method:post']),
        ])
Exemple #4
0
    def test_fallback_used_with_geoip(self):
        cells = CellShardFactory.create_batch(2, radio=Radio.wcdma)
        wifis = WifiShardFactory.build_batch(3)
        api_key = ApiKey.get(self.session, '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.0,
            }
            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', 'region:GB', 'fallback_allowed:true',
                 'accuracy:high', 'status:hit', 'source:fallback']),
            (self.metric_type + '.source',
                ['key:test', 'region:GB', 'source:fallback',
                 'accuracy:high', 'status:hit']),
        ], timer=[
            ('request', [self.metric_path, 'method:post']),
        ])