Skip to content

Commit

Permalink
Added option for content for bytes string style
Browse files Browse the repository at this point in the history
  • Loading branch information
ezturner committed Jun 16, 2017
1 parent dc53986 commit 8fe5798
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
11 changes: 2 additions & 9 deletions restclients_core/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
PositiveIntegerField,
PositiveSmallIntegerField,
SlugField, SmallIntegerField,
TextField, TimeField, URLField,
BaseField)
TextField, TimeField, URLField)


class MockHTTP(object):
Expand All @@ -20,6 +19,7 @@ class MockHTTP(object):
status = 0
data = ""
headers = {}
content = b''

def read(self):
"""
Expand Down Expand Up @@ -107,11 +107,4 @@ def clean_fields(self):

pass

def __str__(self):
return ", ".join([
"%s: %s" % (k, getattr(self, k))
for k, v in self.__class__.__dict__.iteritems()
if issubclass(type(v), BaseField)])


PROTECT = None
4 changes: 3 additions & 1 deletion restclients_core/util/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ def load_resource_from_path(resource_dir, service_name,
return None

data = handle.read()
response = MockHTTP()
response.content = data

try:
data = data.decode('utf-8')
except UnicodeDecodeError:
pass

response = MockHTTP()
response.status = 200
response.data = data
response.headers = {"X-Data-Source": service_name + " file mock data",
Expand Down

0 comments on commit 8fe5798

Please sign in to comment.