Skip to content

Commit

Permalink
Added logging for request data
Browse files Browse the repository at this point in the history
  • Loading branch information
EdLeafe committed Jun 24, 2014
1 parent cff8730 commit 7217f9a
Show file tree
Hide file tree
Showing 6 changed files with 3,993 additions and 669 deletions.
50 changes: 31 additions & 19 deletions pyrax/fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ def json(self):
return self.content


class FakeIterator(utils.ResultsIterator):
def _init_methods(self):
pass


class FakeClient(object):
user_agent = "Fake"
USER_AGENT = "Fake"
Expand All @@ -109,9 +114,13 @@ def __init__(self, *args, **kwargs):


class FakeStorageClient(StorageClient):
def __init__(self, *args, **kwargs):
super(FakeStorageClient, self).__init__("fakeuser",
"fakepassword", *args, **kwargs)
def __init__(self, identity=None, *args, **kwargs):
if identity is None:
identity = FakeIdentity()
super(FakeStorageClient, self).__init__(identity, *args, **kwargs)

def create(self, name):
return FakeContainer(self._manager, {"name": name})


class FakeContainerManager(ContainerManager):
Expand All @@ -123,15 +132,10 @@ def __init__(self, api=None, *args, **kwargs):

class FakeContainer(Container):
def __init__(self, *args, **kwargs):
self.object_manager = FakeStorageObjectManager()

def _fetch_cdn_data(self):
self._cdn_uri = None
self._cdn_ttl = self.client.default_cdn_ttl
self._cdn_ssl_uri = None
self._cdn_streaming_uri = None
self._cdn_ios_uri = None
self._cdn_log_retention = False
super(FakeContainer, self).__init__(*args, **kwargs)
self.object_manager = FakeStorageObjectManager(self.manager.api,
uri_base=self.name)
self.object_manager._container = self


class FakeStorageObjectManager(StorageObjectManager):
Expand All @@ -144,19 +148,18 @@ def __init__(self, api=None, *args, **kwargs):


class FakeStorageObject(StorageObject):
def __init__(self, client, container, name=None, total_bytes=None,
content_type=None, last_modified=None, etag=None, attdict=None):
def __init__(self, manager, name=None, total_bytes=None, content_type=None,
last_modified=None, etag=None, attdict=None):
"""
The object can either be initialized with individual params, or by
passing the dict that is returned by swiftclient.
"""
self.client = client
self.container = container
self.manager = manager
self.name = name
self.total_bytes = total_bytes
self.bytes = total_bytes or 0
self.content_type = content_type
self.last_modified = last_modified
self.etag = etag
self.hash = etag
if attdict:
self._read_attdict(attdict)

Expand Down Expand Up @@ -631,7 +634,16 @@ def __init__(self, identity=None, *args, **kwargs):


class FakeEndpoint(Endpoint):
pass
def __init__(self, ep_dict=None, service=None, region=None, identity=None):
if ep_dict is None:
ep_dict = {}
if identity is None:
identity = FakeIdentity()
if service is None:
service = FakeIdentityService(identity)
if region is None:
region = "fake_region"
super(FakeEndpoint, self).__init__(ep_dict, service, region, identity)


class FakeRaxIdentity(RaxIdentity):
Expand Down
2 changes: 2 additions & 0 deletions pyrax/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def http_log_req(method, uri, args, kwargs):
log.debug("\nREQ: %s\n" % " ".join(string_parts))
if "body" in kwargs:
pyrax._logger.debug("REQ BODY: %s\n" % (kwargs["body"]))
if "data" in kwargs:
pyrax._logger.debug("REQ DATA: %s\n" % (kwargs["data"]))


def http_log_resp(resp, body):
Expand Down
Loading

0 comments on commit 7217f9a

Please sign in to comment.