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())
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())
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())
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())
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)
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'])
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)
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)
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'])