Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions abe/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,24 @@ def __init__(self, filename):

# Make all example requests and reponses accessible via dot syntax
# (e.g. mock["OK"].request.status)
for k, v in self.examples.items():
self.examples[k] = dotify(v)
for key, value in self.examples.items():
# Add the request URL automatically if missing.
self._feed_inherited_fields(value, 'request', ['url', 'method'])
self.examples[key] = dotify(value)

def _feed_inherited_fields(self, value, where, inheritable):
"""
If missing in request or response, some fields are inherited.

URL and method are defined at the top level. They don't need to be
redefined in example requests or responses.

:param where: 'request' or 'response'
:param inheritable: list of inheritable fields

"""
if where not in value:
value[where] = {}
for key in inheritable:
if key not in value[where]:
value[where][key] = getattr(self, key)