Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
altera get_fields para ser público (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigondec authored Sep 24, 2020
1 parent 6e31c5e commit 665eb8d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
8 changes: 4 additions & 4 deletions imopay_wrapper/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def _init_nested_fields(self):
pass

@classmethod
def __get_fields(cls):
def get_fields(cls):
"""
Método para retornar todos os campos!
"""
Expand All @@ -30,7 +30,7 @@ def __get_field(self, name):
"""
try:
# noinspection PyUnresolvedReferences
return self.__get_fields()[name]
return self.get_fields()[name]
except KeyError as e:
raise AttributeError(f"Não existe o campo {name} em {self}") from e

Expand Down Expand Up @@ -104,7 +104,7 @@ def from_dict(cls, data: Union[dict, Any]):

missing_fields = {
field_name
for field_name in cls.__get_fields().keys()
for field_name in cls.get_fields().keys()
if field_name not in data.keys()
}

Expand All @@ -116,7 +116,7 @@ def from_dict(cls, data: Union[dict, Any]):

def to_dict(self):
data = {}
for field_name, field in self.__get_fields().items():
for field_name, field in self.get_fields().items():
value = getattr(self, field_name)

if self.__is_empty_value(value):
Expand Down
10 changes: 2 additions & 8 deletions tests/models/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,7 @@ def test_get_field_1(self):

mocked_field = MagicMock()

obj = MagicMock(
_BaseImopayObj__get_fields=MagicMock(
return_value={field_name: mocked_field}
)
)
obj = MagicMock(get_fields=MagicMock(return_value={field_name: mocked_field}))

expected = mocked_field

Expand All @@ -205,9 +201,7 @@ def test_get_field_2(self):

mocked_field = MagicMock()

obj = MagicMock(
_BaseImopayObj__get_fields=MagicMock(return_value={"bar": mocked_field})
)
obj = MagicMock(get_fields=MagicMock(return_value={"bar": mocked_field}))

with self.assertRaises(AttributeError):
BaseImopayObj._BaseImopayObj__get_field(obj, field_name)
Expand Down

0 comments on commit 665eb8d

Please sign in to comment.