Skip to content

Commit

Permalink
Implement Resource, Operation and Spec __eq__ method
Browse files Browse the repository at this point in the history
  • Loading branch information
macisamuele committed Nov 23, 2019
1 parent 85aca37 commit 5b1089c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions bravado_core/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ def __init__(self, swagger_spec, path_name, http_method, op_spec):
# (key, value) = (param name, Param)
self.params = {}

def __eq__(self, other):
return (
isinstance(other, self.__class__) and
self.path_name == other.path_name and
self.http_method == other.http_method and
self.op_spec == other.op_spec and
self.swagger_spec == other.swagger_spec
)

@cached_property
def consumes(self):
"""Note that the operation can override the value defined globally
Expand Down
7 changes: 7 additions & 0 deletions bravado_core/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,10 @@ def __dir__(self):
:return: list of operation names
"""
return self.operations.keys()

def __eq__(self, other):
return (
isinstance(other, self.__class__) and
self.name == other.name and
self.operations == other.operations
)
11 changes: 11 additions & 0 deletions bravado_core/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ def __init__(
# it will be overridden by the dereferenced specs (by build method). More context in PR#263
self._internal_spec_dict = spec_dict

def __eq__(self, other):
return (
isinstance(other, self.__class__) and
self.spec_dict == other.spec_dict and
self.origin_url == other.origin_url and
self.http_client == other.http_client and
self.config == other.config and
self.api_url == other.api_url and
self.definitions == other.definitions
)

def __deepcopy__(self, memo=None):
if memo is None:
memo = {}
Expand Down

0 comments on commit 5b1089c

Please sign in to comment.