def test_serialize(self): key = 'SECRET_KEY' pm = {'key': key, 'uuid': 'ID'} with mock.patch('tempest.lib.common.profiler._profiler', pm): with mock.patch('json.dumps') as jdm: jdm.return_value = '{"base_id": "ID", "parent_id": "ID"}' expected = { 'X-Trace-HMAC': '887292df9f13b8b5ecd6bbbd2e16bfaaa4d914b0', 'X-Trace-Info': b'eyJiYXNlX2lkIjogIklEIiwgInBhcmVudF9pZCI6ICJJRCJ9' } self.assertEqual(expected, profiler.serialize_as_http_headers())
def get_headers(self, accept_type=None, send_type=None): """Return the default headers which will be used with outgoing requests :param str accept_type: The media type to use for the Accept header, if one isn't provided the object var TYPE will be used :param str send_type: The media-type to use for the Content-Type header, if one isn't provided the object var TYPE will be used :rtype: dict :return: The dictionary of headers which can be used in the headers dict for outgoing request """ if accept_type is None: accept_type = 'json' if send_type is None: send_type = 'json' headers = {'Content-Type': 'application/%s' % send_type, 'Accept': 'application/%s' % accept_type} headers.update(profiler.serialize_as_http_headers()) return headers