File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,5 +20,24 @@ def __init__(self, filename):
2020
2121 # Make all example requests and reponses accessible via dot syntax
2222 # (e.g. mock["OK"].request.status)
23- for k , v in self .examples .items ():
24- self .examples [k ] = dotify (v )
23+ for key , value in self .examples .items ():
24+ # Add the request URL automatically if missing.
25+ self ._feed_inherited_fields (value , 'request' , ['url' , 'method' ])
26+ self .examples [key ] = dotify (value )
27+
28+ def _feed_inherited_fields (self , value , where , inheritable ):
29+ """
30+ If missing in request or response, some fields are inherited.
31+
32+ URL and method are defined at the top level. They don't need to be
33+ redefined in example requests or responses.
34+
35+ :param where: 'request' or 'response'
36+ :param inheritable: list of inheritable fields
37+
38+ """
39+ if where not in value :
40+ value [where ] = {}
41+ for key in inheritable :
42+ if key not in value [where ]:
43+ value [where ][key ] = getattr (self , key )
You can’t perform that action at this time.
0 commit comments