Esempio n. 1
0
 def check_response(self,
                    data_queues,
                    response,
                    status,
                    fallback=None,
                    details=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 == LocationNotFound().json_body()
     elif status == "parse_error":
         assert response.json == ParseError(details).json_body()
     elif status == "limit_exceeded":
         assert response.json == DailyLimitExceeded().json_body()
     if status != "ok":
         self.check_queue(data_queues, 0)
Esempio n. 2
0
    def test_404_response(self, geoip_db, http_session, raven, session, source,
                          metricsmock):
        cell = CellShardFactory.build()

        with requests_mock.Mocker() as mock_request:
            mock_request.register_uri(
                "POST",
                requests_mock.ANY,
                json=LocationNotFound().json_body(),
                status_code=404,
            )

            query = self.model_query(geoip_db,
                                     http_session,
                                     session,
                                     cells=[cell])
            results = source.search(query)
            self.check_model_results(results, None)

        raven.check([("HTTPError", 0)])
        metricsmock.assert_incr_once("locate.fallback.lookup",
                                     tags=[self.fallback_tag, "status:404"])
Esempio n. 3
0
 def fallback_not_found(self):
     return LocationNotFound().json_body()