Skip to content

Commit

Permalink
add docstrings to OrderedRegistry (#587)
Browse files Browse the repository at this point in the history
Add docstrings to OrderedRegistry

Co-authored-by: Mark Story <mark@mark-story.com>
  • Loading branch information
beliaev-maksim and markstory authored Sep 8, 2022
1 parent 240504c commit 873ddb4
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions responses/registries.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,32 @@ def replace(self, response: "BaseResponse") -> "BaseResponse":


class OrderedRegistry(FirstMatchRegistry):
"""Registry where `Response` objects are dependent on the insertion order and invocation index.
OrderedRegistry applies the rule of first in - first out. Responses should be invoked in
the same order in which they were added to the registry. Otherwise, an error is returned.
"""

def find(
self, request: "PreparedRequest"
) -> Tuple[Optional["BaseResponse"], List[str]]:
"""Find the next registered `Response` and check if it matches the request.
Search is performed by taking the first element of the registered responses list
and removing this object (popping from the list).
Parameters
----------
request : PreparedRequest
Request that was caught by the custom adapter.
Returns
-------
Tuple[Optional["BaseResponse"], List[str]]
Matched `Response` object and empty list in case of match.
Otherwise, None and a list with reasons for not finding a match.
"""

if not self.registered:
return None, ["No more registered responses"]
Expand Down

0 comments on commit 873ddb4

Please sign in to comment.