def test_parse_response_json(self, log): tracer = get_dummy_tracer() tracer.debug_logging = True test_cases = { 'OK': dict( js=None, log= 'Cannot parse Datadog Agent response, please make sure your Datadog Agent is up to date', ), 'OK\n': dict( js=None, log= 'Cannot parse Datadog Agent response, please make sure your Datadog Agent is up to date', ), 'error:unsupported-endpoint': dict( js=None, log= 'Unable to parse Datadog Agent JSON response: .*? \'error:unsupported-endpoint\'', ), 42: dict( # int as key to trigger TypeError js=None, log='Unable to parse Datadog Agent JSON response: .*? 42', ), '{}': dict(js={}), '[]': dict(js=[]), # Priority sampling "rate_by_service" response ('{"rate_by_service": ' '{"service:,env:":0.5, "service:mcnulty,env:test":0.9, "service:postgres,env:test":0.6}}'): dict(js=dict(rate_by_service={ 'service:,env:': 0.5, 'service:mcnulty,env:test': 0.9, 'service:postgres,env:test': 0.6, }, ), ), ' [4,2,1] ': dict(js=[4, 2, 1]), } for k, v in iteritems(test_cases): log.reset_mock() r = Response.from_http_response(ResponseMock(k)) js = r.get_json() assert v['js'] == js if 'log' in v: log.assert_called_once() msg = log.call_args[0][0] % log.call_args[0][1:] assert re.match(v['log'], msg), msg
def test_parse_response_json(self, log): test_cases = { "OK": dict( js=None, log= "Cannot parse Datadog Agent response, please make sure your Datadog Agent is up to date", ), "OK\n": dict( js=None, log= "Cannot parse Datadog Agent response, please make sure your Datadog Agent is up to date", ), "error:unsupported-endpoint": dict( js=None, log= "Unable to parse Datadog Agent JSON response: 'error:unsupported-endpoint'", ), 42: dict( # int as key to trigger TypeError js=None, log="Unable to parse Datadog Agent JSON response: 42", ), "{}": dict(js={}), "[]": dict(js=[]), # Priority sampling "rate_by_service" response ('{"rate_by_service": ' '{"service:,env:":0.5, "service:mcnulty,env:test":0.9, "service:postgres,env:test":0.6}}'): dict(js=dict(rate_by_service={ "service:,env:": 0.5, "service:mcnulty,env:test": 0.9, "service:postgres,env:test": 0.6, }, ), ), " [4,2,1] ": dict(js=[4, 2, 1]), } for k, v in iteritems(test_cases): log.reset_mock() r = Response.from_http_response(ResponseMock(k)) js = r.get_json() assert v["js"] == js if "log" in v: log.assert_called_once() msg = log.call_args[0][0] % log.call_args[0][1:] assert re.match(v["log"], msg), msg
def _put(self, endpoint, data, count=0): conn = httplib.HTTPConnection(self.hostname, self.port) conn.request('HEAD', endpoint, data, self._headers) return Response.from_http_response(conn.getresponse())