def test_wants_json_resp(self): """Tests the accept header evaluation.""" app = flask.Flask(__name__) app.testing = True with app.test_request_context(headers=[('Accept', 'application/json, ' 'text/plain')]): self.assertTrue(webutils.wants_json_resp(flask.request)) with app.test_request_context(headers=[('Accept', 'text/html; q=1.0, ' 'text/*; q=0.8, image/gif; ' 'q=0.6, image/jpeg;')]): self.assertFalse(webutils.wants_json_resp(flask.request))
def get(self, **id_parts): """ Return metrics either as an attachment or as json. """ if webutils.wants_json_resp(flask.request): return self._get(self._to_rsrc_id(**id_parts)) else: return self._get_as_attach(self._to_rsrc_id(**id_parts))
def get(self, **id_parts): """ Return metrics either as an attachment or as json. """ args = metrics_req_parser.parse_args() if webutils.wants_json_resp(flask.request): return self._get(self._to_rsrc_id(**id_parts), args.get('timeframe')) else: return self._get_as_attach(self._to_rsrc_id(**id_parts), args.get('timeframe'))