Example #1
0
 def test_ok_cell_radio_in_celltowers_dupes(self):
     # This test covered a bug related to FxOS calling the
     # geolocate API incorrectly.
     app = self.app
     session = self.db_slave_session
     cell = Cell()
     cell.lat = PARIS_LAT
     cell.lon = PARIS_LON
     cell.radio = 0
     cell.mcc = FRANCE_MCC
     cell.mnc = 1
     cell.lac = 2
     cell.cid = 1234
     cell.range = 1000
     session.add(cell)
     session.commit()
     res = app.post_json(
         '%s?key=test' % self.url, {
             "cellTowers": [
                 {"radio": "gsm",
                  "mobileCountryCode": FRANCE_MCC,
                  "mobileNetworkCode": 1,
                  "locationAreaCode": 2,
                  "cellId": 1234},
                 {"radio": "gsm",
                  "mobileCountryCode": FRANCE_MCC,
                  "mobileNetworkCode": 1,
                  "locationAreaCode": 2,
                  "cellId": 1234},
             ]},
         status=200)
     self.assertEqual(res.content_type, 'application/json')
     self.assertEqual(res.json, {"location": {"lat": PARIS_LAT,
                                              "lng": PARIS_LON},
                                 "accuracy": CELL_MIN_ACCURACY})
Example #2
0
    def test_ok_cell(self):
        app = self.app
        session = self.db_slave_session
        cell = Cell()
        cell.lat = 123456781
        cell.lon = 234567892
        cell.radio = 0
        cell.mcc = 123
        cell.mnc = 1
        cell.lac = 2
        cell.cid = 1234
        session.add(cell)
        session.commit()

        res = app.post_json(
            '/v1/geolocate?key=test', {
                "radioType": "gsm",
                "cellTowers": [
                    {"mobileCountryCode": 123, "mobileNetworkCode": 1,
                     "locationAreaCode": 2, "cellId": 1234},
                ]},
            status=200)

        find_msg = self.find_heka_messages
        self.assertEquals(
            len(find_msg('counter', 'http.request')), 1)
        self.assertEqual(1, len(find_msg('counter', 'geolocate.api_key.test')))

        self.assertEqual(res.content_type, 'application/json')
        self.assertEqual(res.json, {"location": {"lat": 12.3456781,
                                                 "lng": 23.4567892},
                                    "accuracy": 35000.0})
Example #3
0
    def test_ok_cell(self):
        app = self.app
        session = self.get_session()
        cell = Cell()
        cell.lat = PARIS_LAT
        cell.lon = PARIS_LON
        cell.radio = RADIO_TYPE['gsm']
        cell.mcc = FRANCE_MCC
        cell.mnc = 1
        cell.lac = 2
        cell.cid = 1234
        session.add(cell)
        session.commit()

        res = app.post_json(
            '%s?key=test' % self.url, {
                "radioType": "gsm",
                "cellTowers": [
                    {"mobileCountryCode": FRANCE_MCC,
                     "mobileNetworkCode": 1,
                     "locationAreaCode": 2,
                     "cellId": 1234},
                ]},
            status=200)

        self.check_stats(
            counter=[self.metric_url + '.200', self.metric + '.api_key.test']
        )

        self.assertEqual(res.content_type, 'application/json')
        self.assertEqual(res.json, {"location": {"lat": PARIS_LAT,
                                                 "lng": PARIS_LON},
                                    "accuracy": CELL_MIN_ACCURACY})
Example #4
0
    def test_ok_cell(self):
        app = self.app
        session = self.get_session()
        cell = Cell()
        cell.lat = PARIS_LAT
        cell.lon = PARIS_LON
        cell.radio = RADIO_TYPE['gsm']
        cell.mcc = FRANCE_MCC
        cell.mnc = 1
        cell.lac = 2
        cell.cid = 1234
        session.add(cell)
        session.commit()

        res = app.post_json(
            '%s?key=test' % self.url, {
                "radioType": "gsm",
                "cellTowers": [
                    {"mobileCountryCode": FRANCE_MCC,
                     "mobileNetworkCode": 1,
                     "locationAreaCode": 2,
                     "cellId": 1234},
                ]},
            status=200)

        self.check_stats(
            counter=[self.metric_url + '.200',
                     self.metric + '.api_key.test',
                     self.metric + '.api_log.test.cell_hit']
        )

        self.assertEqual(res.content_type, 'application/json')
        self.assertEqual(res.json, {"location": {"lat": PARIS_LAT,
                                                 "lng": PARIS_LON},
                                    "accuracy": CELL_MIN_ACCURACY})
Example #5
0
 def test_ok_cell_radio_in_celltowers_dupes(self):
     # This test covered a bug related to FxOS calling the
     # geolocate API incorrectly.
     app = self.app
     session = self.get_session()
     cell = Cell()
     cell.lat = PARIS_LAT
     cell.lon = PARIS_LON
     cell.radio = 0
     cell.mcc = FRANCE_MCC
     cell.mnc = 1
     cell.lac = 2
     cell.cid = 1234
     session.add(cell)
     session.commit()
     res = app.post_json(
         '%s?key=test' % self.url, {
             "cellTowers": [
                 {"radio": "gsm",
                  "mobileCountryCode": FRANCE_MCC,
                  "mobileNetworkCode": 1,
                  "locationAreaCode": 2,
                  "cellId": 1234},
                 {"radio": "gsm",
                  "mobileCountryCode": FRANCE_MCC,
                  "mobileNetworkCode": 1,
                  "locationAreaCode": 2,
                  "cellId": 1234},
             ]},
         status=200)
     self.assertEqual(res.content_type, 'application/json')
     self.assertEqual(res.json, {"location": {"lat": PARIS_LAT,
                                              "lng": PARIS_LON},
                                 "accuracy": CELL_MIN_ACCURACY})
Example #6
0
    def test_ok_cell(self):
        app = self.app
        session = self.db_slave_session
        cell = Cell()
        cell.lat = 123456781
        cell.lon = 234567892
        cell.radio = 0
        cell.mcc = 123
        cell.mnc = 1
        cell.lac = 2
        cell.cid = 1234
        session.add(cell)
        session.commit()

        res = app.post_json(
            '/v1/geolocate?key=test', {
                "radioType": "gsm",
                "cellTowers": [
                    {"mobileCountryCode": 123, "mobileNetworkCode": 1,
                     "locationAreaCode": 2, "cellId": 1234},
                ]},
            status=200)
        self.assertEqual(res.content_type, 'application/json')
        self.assertEqual(res.body, '{"location": {"lat": 12.3456781, '
                                   '"lng": 23.4567892}, "accuracy": 35000.0}')
Example #7
0
    def test_ok_cell(self):
        app = self.app
        session = self.db_slave_session
        cell = Cell()
        cell.lat = 123456781
        cell.lon = 234567892
        cell.radio = 0
        cell.mcc = 123
        cell.mnc = 1
        cell.lac = 2
        cell.cid = 1234
        session.add(cell)
        session.commit()

        res = app.post_json('/v1/geolocate', {
            "radioType":
            "gsm",
            "cellTowers": [
                {
                    "mobileCountryCode": 123,
                    "mobileNetworkCode": 1,
                    "locationAreaCode": 2,
                    "cellId": 1234
                },
            ]
        },
                            status=200)
        self.assertEqual(res.content_type, 'application/json')
        self.assertEqual(
            res.body, '{"location": {"lat": 12.3456781, '
            '"lng": 23.4567892}, "accuracy": 35000.0}')
Example #8
0
    def test_ok_cell_radio_in_celltowers(self):
        app = self.app
        session = self.db_slave_session
        cell = Cell()
        cell.lat = 123456781
        cell.lon = 234567892
        cell.radio = 0
        cell.mcc = 123
        cell.mnc = 1
        cell.lac = 2
        cell.cid = 1234
        session.add(cell)
        session.commit()

        res = app.post_json(
            '/v1/geolocate?key=test', {
                "cellTowers": [
                    {"radio": "gsm",
                     "mobileCountryCode": 123,
                     "mobileNetworkCode": 1,
                     "locationAreaCode": 2,
                     "cellId": 1234},
                ]},
            status=200)

        self.check_expected_heka_messages(
            counter=['http.request', 'geolocate.api_key.test']
        )

        self.assertEqual(res.content_type, 'application/json')
        self.assertEqual(res.json, {"location": {"lat": 12.3456781,
                                                 "lng": 23.4567892},
                                    "accuracy": CELL_MIN_ACCURACY})
Example #9
0
    def test_ok_cell(self):
        app = self.app
        session = self.db_slave_session
        cell = Cell()
        cell.lat = 123456781
        cell.lon = 234567892
        cell.radio = 0
        cell.mcc = 123
        cell.mnc = 1
        cell.lac = 2
        cell.cid = 1234
        session.add(cell)
        session.commit()

        res = app.post_json(
            '/v1/geolocate?key=test', {
                "radioType": "gsm",
                "cellTowers": [
                    {"mobileCountryCode": 123, "mobileNetworkCode": 1,
                     "locationAreaCode": 2, "cellId": 1234},
                ]},
            status=200)

        self.check_expected_heka_messages(
            counter=['http.request', 'geolocate.api_key.test']
        )

        self.assertEqual(res.content_type, 'application/json')
        self.assertEqual(res.json, {"location": {"lat": 12.3456781,
                                                 "lng": 23.4567892},
                                    "accuracy": 35000.0})
Example #10
0
    def test_ok_cell(self):
        app = self.app
        session = self.db_master_session
        cell = Cell()
        cell.lat = GB_LAT
        cell.lon = GB_LON
        cell.radio = 0
        cell.mcc = GB_MCC
        cell.mnc = 1
        cell.lac = 2
        cell.cid = 1234
        cell.total_measures = 1
        cell.new_measures = 0

        session.add(cell)
        session.commit()

        res = app.post_json('/v1/geosubmit?key=test',
                            {'items': [{"latitude": GB_LAT + 0.1,
                                        "longitude": GB_LON + 0.1,
                                        "accuracy": 12.4,
                                        "radioType": "gsm",
                                        "cellTowers": [{
                                            "cellId": 1234,
                                            "locationAreaCode": 2,
                                            "mobileCountryCode": GB_MCC,
                                            "mobileNetworkCode": 1,
                                        }]},
                                       {"latitude": GB_LAT - 0.1,
                                        "longitude": GB_LON - 0.1,
                                        "accuracy": 22.4,
                                        "radioType": "gsm",
                                        "cellTowers": [{
                                            "cellId": 2234,
                                            "locationAreaCode": 22,
                                            "mobileCountryCode": GB_MCC,
                                            "mobileNetworkCode": 2,
                                        }]}]},
                            status=200)

        # check that we get an empty response
        self.assertEqual(res.content_type, 'application/json')
        self.assertEqual(res.json, {})

        # check that two new CellMeasure records are created
        self.assertEquals(2, session.query(CellMeasure).count())
        cm1 = session.query(CellMeasure).filter(
            CellMeasure.cid == 1234).count()
        cm2 = session.query(CellMeasure).filter(
            CellMeasure.cid == 2234).count()
        self.assertEquals(1, cm1)
        self.assertEquals(1, cm2)

        self.check_stats(
            counter=['geosubmit.api_key.test',
                     'items.uploaded.batches',
                     'items.uploaded.reports',
                     ],
            timer=['items.uploaded.batch_size'])
Example #11
0
    def test_ok_cell(self):
        app = self.app
        session = self.db_master_session
        cell = Cell()
        cell.lat = GB_LAT + 0.1
        cell.lon = GB_LON + 0.1
        cell.radio = 0
        cell.mcc = GB_MCC
        cell.mnc = 1
        cell.lac = 2
        cell.cid = 1234
        cell.total_measures = 1
        cell.new_measures = 0

        session.add(cell)
        session.commit()

        res = app.post_json('/v1/geosubmit?key=test', {
                            "latitude": GB_LAT,
                            "longitude": GB_LON,
                            "accuracy": 12.4,
                            "radioType": "gsm",
                            "cellTowers": [{
                                "cellId": 1234,
                                "locationAreaCode": 2,
                                "mobileCountryCode": GB_MCC,
                                "mobileNetworkCode": 1,
                            }]},
                            status=200)

        # check that we get back a location
        self.assertEqual(res.content_type, 'application/json')
        self.assertEqual(res.json, {"location": {"lat": GB_LAT,
                                                 "lng": GB_LON},
                                    "accuracy": 12.4})

        cell = session.query(Cell).first()
        self.assertEqual(2, cell.total_measures)
        self.assertEqual(1, cell.new_measures)

        # check that one new CellMeasure record is created
        self.assertEquals(1, session.query(CellMeasure).count())

        self.check_stats(
            counter=['geosubmit.api_key.test',
                     'items.api_log.test.uploaded.batches',
                     'items.api_log.test.uploaded.reports',
                     'items.api_log.test.uploaded.cell_observations',
                     'items.uploaded.cell_observations',
                     'items.uploaded.batches',
                     'items.uploaded.reports',
                     'request.v1.geosubmit.200',
                     ],
            timer=['items.api_log.test.uploaded.batch_size',
                   'items.uploaded.batch_size',
                   'request.v1.geosubmit'])
Example #12
0
    def test_geoip_match(self):
        app = self.app
        london = self.geoip_data['London']
        session = self.db_master_session
        cell = Cell()
        cell.lat = GB_LAT
        cell.lon = GB_LON
        cell.radio = 0
        cell.mcc = GB_MCC
        cell.mnc = 1
        cell.lac = 2
        cell.cid = 1234
        cell.total_measures = 1
        cell.new_measures = 0

        session.add(cell)
        session.commit()

        res = app.post_json(
            '/v1/geosubmit?key=test',
            {'items': [{"latitude": GB_LAT + 0.1,
                        "longitude": GB_LON + 0.1,
                        "accuracy": 12.4,
                        "radioType": "gsm",
                        "cellTowers": [{
                            "cellId": 1234,
                            "locationAreaCode": 2,
                            "mobileCountryCode": GB_MCC,
                            "mobileNetworkCode": 1,
                        }]},
                       {"latitude": GB_LAT - 0.1,
                        "longitude": GB_LON - 0.1,
                        "accuracy": 22.4,
                        "radioType": "gsm",
                        "cellTowers": [{
                            "cellId": 2234,
                            "locationAreaCode": 22,
                            "mobileCountryCode": GB_MCC,
                            "mobileNetworkCode": 2,
                        }]}]},
            extra_environ={'HTTP_X_FORWARDED_FOR': london['ip']},
            status=200)

        # check that we get an empty response
        self.assertEqual(res.content_type, 'application/json')
        self.assertEqual(res.json, {})

        # check that two new CellMeasure records are created
        self.assertEquals(2, session.query(CellMeasure).count())
        cm1 = session.query(CellMeasure).filter(
            CellMeasure.cid == 1234).count()
        cm2 = session.query(CellMeasure).filter(
            CellMeasure.cid == 2234).count()
        self.assertEquals(1, cm1)
        self.assertEquals(1, cm2)
Example #13
0
    def test_geoip_match(self):
        app = self.app
        session = self.db_master_session
        cell = Cell()
        cell.lat = PARIS_LAT
        cell.lon = PARIS_LON
        cell.radio = 0
        cell.mcc = FRANCE_MCC
        cell.mnc = 1
        cell.lac = 2
        cell.cid = 1234
        cell.total_measures = 1
        cell.new_measures = 0

        session.add(cell)
        session.commit()

        res = app.post_json('/v1/geosubmit?key=test',
                            {'items': [{"latitude": PARIS_LAT + 0.1,
                                        "longitude": PARIS_LON + 0.1,
                                        "accuracy": 12.4,
                                        "radioType": "gsm",
                                        "cellTowers": [{
                                            "cellId": 1234,
                                            "locationAreaCode": 2,
                                            "mobileCountryCode": FRANCE_MCC,
                                            "mobileNetworkCode": 1,
                                        }]},
                                       {"latitude": PARIS_LAT - 0.1,
                                        "longitude": PARIS_LON - 0.1,
                                        "accuracy": 22.4,
                                        "radioType": "gsm",
                                        "cellTowers": [{
                                            "cellId": 2234,
                                            "locationAreaCode": 22,
                                            "mobileCountryCode": FRANCE_MCC,
                                            "mobileNetworkCode": 2,
                                        }]}]},
                            extra_environ={'HTTP_X_FORWARDED_FOR': PARIS_IP},
                            status=200)

        # check that we get an empty response
        self.assertEqual(res.content_type, 'application/json')
        self.assertEqual(res.json, {})

        # check that two new CellMeasure records are created
        self.assertEquals(2, session.query(CellMeasure).count())
        cm1 = session.query(CellMeasure).filter(
            CellMeasure.cid == 1234).count()
        cm2 = session.query(CellMeasure).filter(
            CellMeasure.cid == 2234).count()
        self.assertEquals(1, cm1)
        self.assertEquals(1, cm2)
Example #14
0
    def test_inconsistent_cell_radio_in_towers(self):
        app = self.app
        session = self.db_slave_session
        cell = Cell()
        cell.lat = 123456781
        cell.lon = 234567892
        cell.radio = 0
        cell.mcc = 123
        cell.mnc = 1
        cell.lac = 2
        cell.cid = 1234
        session.add(cell)
        session.commit()

        res = app.post_json(
            '/v1/geolocate?key=test', {
                "cellTowers": [
                    {"radio": "gsm",
                     "mobileCountryCode": 123,
                     "mobileNetworkCode": 1,
                     "locationAreaCode": 2,
                     "cellId": 1234},
                    {"radio": "cdma",
                     "mobileCountryCode": 123,
                     "mobileNetworkCode": 1,
                     "locationAreaCode": 2,
                     "cellId": 1234},
                ]},
            status=400)

        self.check_expected_heka_messages(
            counter=['http.request', 'geolocate.api_key.test']
        )

        self.assertEqual(res.content_type, 'application/json')
        self.assertEqual(
            res.json, {"error": {
                "errors": [{
                    "domain": "global",
                    "reason": "parseError",
                    "message": "Parse Error",
                }],
                "code": 400,
                "message": "Parse Error"
            }}
        )
Example #15
0
    def test_ok_cell(self):
        app = self.app
        session = self.db_master_session
        cell = Cell()
        cell.lat = PARIS_LAT + 0.1
        cell.lon = PARIS_LON + 0.1
        cell.radio = 0
        cell.mcc = FRANCE_MCC
        cell.mnc = 1
        cell.lac = 2
        cell.cid = 1234
        cell.total_measures = 1
        cell.new_measures = 0

        session.add(cell)
        session.commit()

        res = app.post_json('/v1/geosubmit?key=test', {
                            "latitude": PARIS_LAT,
                            "longitude": PARIS_LON,
                            "accuracy": 12.4,
                            "radioType": "gsm",
                            "cellTowers": [{
                                "cellId": 1234,
                                "locationAreaCode": 2,
                                "mobileCountryCode": FRANCE_MCC,
                                "mobileNetworkCode": 1,
                            }]},
                            status=200)

        # check that we get back a location
        self.assertEqual(res.content_type, 'application/json')
        self.assertEqual(res.json, {"location": {"lat": PARIS_LAT,
                                                 "lng": PARIS_LON},
                                    "accuracy": 12.4})

        cell = session.query(Cell).first()
        self.assertEqual(2, cell.total_measures)
        self.assertEqual(1, cell.new_measures)

        # check that one new CellMeasure record is created
        self.assertEquals(1, session.query(CellMeasure).count())
Example #16
0
    def test_ok_cell(self):
        app = self.app
        session = self.db_slave_session
        cell = Cell()
        cell.lat = 123456781
        cell.lon = 234567892
        cell.radio = 2
        cell.mcc = 123
        cell.mnc = 1
        cell.lac = 2
        cell.cid = 1234
        session.add(cell)
        session.commit()

        res = app.post_json('/v1/search',
                            {"radio": "gsm",
                             "cell": [{"radio": "umts", "mcc": 123, "mnc": 1,
                                       "lac": 2, "cid": 1234}]},
                            status=200)
        self.assertEqual(res.content_type, 'application/json')
        self.assertEqual(res.body, '{"status": "ok", "lat": 12.3456781, '
                                   '"lon": 23.4567892, "accuracy": 35000}')
Example #17
0
    def test_ok_cell(self):
        app = self.app
        session = self.db_master_session
        cell = Cell()
        cell.lat = GB_LAT
        cell.lon = GB_LON
        cell.radio = RADIO_TYPE['cdma']
        cell.mcc = GB_MCC
        cell.mnc = 1
        cell.lac = 2
        cell.cid = 1234
        cell.range = 10000
        cell.total_measures = 1
        cell.new_measures = 0

        session.add(cell)
        session.commit()

        res = app.post_json('/v1/geosubmit?key=test', {
            "items": [
                {
                    "latitude":
                    GB_LAT + 0.1,
                    "longitude":
                    GB_LON + 0.1,
                    "accuracy":
                    12.4,
                    "radioType":
                    "cdma",
                    "cellTowers": [{
                        "cellId": 1234,
                        "locationAreaCode": 2,
                        "mobileCountryCode": GB_MCC,
                        "mobileNetworkCode": 1,
                    }]
                },
                {
                    "latitude":
                    GB_LAT - 0.1,
                    "longitude":
                    GB_LON - 0.1,
                    "accuracy":
                    22.4,
                    "cellTowers": [{
                        "radioType": "wcdma",
                        "cellId": 2234,
                        "locationAreaCode": 22,
                        "mobileCountryCode": GB_MCC,
                        "mobileNetworkCode": 2,
                    }]
                },
            ]
        },
                            status=200)

        # check that we get an empty response
        self.assertEqual(res.content_type, 'application/json')
        self.assertEqual(res.json, {})

        self.assertEqual(session.query(Cell).count(), 2)

        observations = session.query(CellObservation).all()
        self.assertEqual(len(observations), 2)
        radios = set([obs.radio for obs in observations])
        self.assertEqual(radios, set([RADIO_TYPE['cdma'], RADIO_TYPE['umts']]))

        self.check_stats(counter=[
            'geosubmit.api_key.test',
            'items.api_log.test.uploaded.batches',
            'items.api_log.test.uploaded.reports',
            'items.api_log.test.uploaded.cell_observations',
            'items.uploaded.cell_observations',
            'items.uploaded.batches',
            'items.uploaded.reports',
            'request.v1.geosubmit.200',
        ],
                         timer=[
                             'items.api_log.test.uploaded.batch_size',
                             'items.uploaded.batch_size',
                             'request.v1.geosubmit'
                         ])