コード例 #1
0
ファイル: tests.py プロジェクト: JaredKerim-Mozilla/ichnaea
 def _check_geoip_result(self, result, status=200):
     self.assertEqual(result.content_type, 'application/json')
     self.assertEqual(result.charset, 'UTF-8')
     if status == 200:
         self.assertEqual(result.json,
                          {'country_name': 'United Kingdom',
                           'country_code': 'GB'})
     elif status == 400:
         self.assertEqual(result.json, InvalidAPIKey.json_body())
     elif status == 404:
         self.assertEqual(result.json, LocationNotFound.json_body())
コード例 #2
0
ファイル: base.py プロジェクト: therewillbecode/ichnaea
 def check_response(self, response, status):
     self.assertEqual(response.content_type, 'application/json')
     self.assertEqual(response.charset, 'UTF-8')
     if status == 'ok':
         self.assertEqual(response.json, self.ip_response)
     elif status == 'invalid_key':
         self.assertEqual(response.json, InvalidAPIKey.json_body())
     elif status == 'not_found':
         self.assertEqual(response.json, self.not_found.json_body())
     elif status == 'parse_error':
         self.assertEqual(response.json, ParseError.json_body())
     elif status == 'limit_exceeded':
         self.assertEqual(response.json, DailyLimitExceeded.json_body())
コード例 #3
0
ファイル: base.py プロジェクト: mate1983/ichnaea
 def check_response(self, response, status):
     self.assertEqual(response.content_type, 'application/json')
     self.assertEqual(response.charset, 'UTF-8')
     self.assertEqual(response.headers['Access-Control-Allow-Origin'], '*')
     self.assertEqual(response.headers['Access-Control-Max-Age'], '2592000')
     if status == 'ok':
         self.assertEqual(response.json, self.ip_response)
     elif status == 'invalid_key':
         self.assertEqual(response.json, InvalidAPIKey.json_body())
     elif status == 'not_found':
         self.assertEqual(response.json, self.not_found.json_body())
     elif status == 'parse_error':
         self.assertEqual(response.json, ParseError.json_body())
     elif status == 'limit_exceeded':
         self.assertEqual(response.json, DailyLimitExceeded.json_body())
コード例 #4
0
ファイル: base.py プロジェクト: cemoulto/ichnaea
 def check_response(self, response, status):
     self.assertEqual(response.content_type, "application/json")
     self.assertEqual(response.charset, "UTF-8")
     self.assertEqual(response.headers["Access-Control-Allow-Origin"], "*")
     self.assertEqual(response.headers["Access-Control-Max-Age"], "2592000")
     if status == "ok":
         self.assertEqual(response.json, self.ip_response)
     elif status == "invalid_key":
         self.assertEqual(response.json, InvalidAPIKey.json_body())
     elif status == "not_found":
         self.assertEqual(response.json, self.not_found.json_body())
     elif status == "parse_error":
         self.assertEqual(response.json, ParseError.json_body())
     elif status == "limit_exceeded":
         self.assertEqual(response.json, DailyLimitExceeded.json_body())
コード例 #5
0
 def check_response(self, response, status):
     self.assertEqual(response.content_type, 'application/json')
     self.assertEqual(response.charset, 'UTF-8')
     self.assertEqual(response.headers['Access-Control-Allow-Origin'], '*')
     self.assertEqual(response.headers['Access-Control-Max-Age'], '2592000')
     if status == 'ok':
         self.assertEqual(response.json, self.ip_response)
     elif status == 'invalid_key':
         self.assertEqual(response.json, InvalidAPIKey.json_body())
     elif status == 'not_found':
         self.assertEqual(response.json, self.not_found.json_body())
     elif status == 'parse_error':
         self.assertEqual(response.json, ParseError.json_body())
     elif status == 'limit_exceeded':
         self.assertEqual(response.json, DailyLimitExceeded.json_body())
コード例 #6
0
ファイル: base.py プロジェクト: amjadm61/ichnaea
 def check_response(self, data_queues, response, status):
     assert response.content_type == 'application/json'
     assert response.headers['Access-Control-Allow-Origin'] == '*'
     assert response.headers['Access-Control-Max-Age'] == '2592000'
     if status == 'ok':
         assert response.json == self.ip_response
     elif status == 'invalid_key':
         assert response.json == InvalidAPIKey.json_body()
     elif status == 'not_found':
         assert response.json == self.not_found.json_body()
     elif status == 'parse_error':
         assert response.json == ParseError.json_body()
     elif status == 'limit_exceeded':
         assert response.json == DailyLimitExceeded.json_body()
     if status != 'ok':
         self.check_queue(data_queues, 0)
コード例 #7
0
ファイル: tests.py プロジェクト: JaredKerim-Mozilla/ichnaea
    def test_unknown_api_key(self):
        key = dict(mcc=FRANCE_MCC, mnc=2, lac=3, cid=4)
        self.session.add(Cell(
            lat=PARIS_LAT,
            lon=PARIS_LON,
            range=1000,
            radio=Radio.umts, **key)
        )
        self.session.commit()

        res = self.app.post_json(
            '/v1/search?key=unknown_key',
            {'radio': Radio.gsm.name, 'cell': [
                dict(radio=Radio.umts.name, **key),
            ]},
            status=400)
        self.assertEqual(res.content_type, 'application/json')
        self.assertEqual(res.json, InvalidAPIKey.json_body())
        self.check_stats(counter=['search.unknown_api_key'])
コード例 #8
0
 def check_response(self, data_queues, response, status, fallback=None):
     assert response.content_type == 'application/json'
     assert response.headers['Access-Control-Allow-Origin'] == '*'
     assert response.headers['Access-Control-Max-Age'] == '2592000'
     if status == 'ok':
         body = dict(response.json)
         if fallback:
             assert body['fallback'] == fallback
             del body['fallback']
         assert body == self.ip_response
     elif status == 'invalid_key':
         assert response.json == InvalidAPIKey.json_body()
     elif status == 'not_found':
         assert response.json == self.not_found.json_body()
     elif status == 'parse_error':
         assert response.json == ParseError.json_body()
     elif status == 'limit_exceeded':
         assert response.json == DailyLimitExceeded.json_body()
     if status != 'ok':
         self.check_queue(data_queues, 0)
コード例 #9
0
 def check_response(self, data_queues, response, status, fallback=None):
     assert response.content_type == "application/json"
     assert response.headers["Access-Control-Allow-Origin"] == "*"
     assert response.headers["Access-Control-Max-Age"] == "2592000"
     if status == "ok":
         body = dict(response.json)
         if fallback:
             assert body["fallback"] == fallback
             del body["fallback"]
         assert body == self.ip_response
     elif status == "invalid_key":
         assert response.json == InvalidAPIKey.json_body()
     elif status == "not_found":
         assert response.json == self.not_found.json_body()
     elif status == "parse_error":
         assert response.json == ParseError.json_body()
     elif status == "limit_exceeded":
         assert response.json == DailyLimitExceeded.json_body()
     if status != "ok":
         self.check_queue(data_queues, 0)
コード例 #10
0
ファイル: tests.py プロジェクト: JaredKerim-Mozilla/ichnaea
    def test_unknown_api_key(self):
        cell = CellFactory()
        self.session.flush()

        res = self.app.post_json(
            '%s?key=unknown_key' % self.url, {
                'radioType': cell.radio.name,
                'cellTowers': [
                    {'mobileCountryCode': cell.mcc,
                     'mobileNetworkCode': cell.mnc,
                     'locationAreaCode': cell.lac,
                     'cellId': cell.cid},
                ]
            },
            status=400)
        self.assertEqual(res.content_type, 'application/json')
        self.assertEqual(res.json, InvalidAPIKey.json_body())

        self.check_stats(
            counter=[self.metric + '.unknown_api_key'])