From 665eb8d7413877690d5cd1bed3505ddc3e874d0a Mon Sep 17 00:00:00 2001 From: Rodrigo Castro Date: Thu, 24 Sep 2020 14:59:07 -0300 Subject: [PATCH] =?UTF-8?q?altera=20get=5Ffields=20para=20ser=20p=C3=BAbli?= =?UTF-8?q?co=20(#17)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- imopay_wrapper/models/base.py | 8 ++++---- tests/models/test_base.py | 10 ++-------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/imopay_wrapper/models/base.py b/imopay_wrapper/models/base.py index 06edf73..686778e 100644 --- a/imopay_wrapper/models/base.py +++ b/imopay_wrapper/models/base.py @@ -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! """ @@ -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 @@ -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() } @@ -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): diff --git a/tests/models/test_base.py b/tests/models/test_base.py index 2376ffe..3ca9eab 100644 --- a/tests/models/test_base.py +++ b/tests/models/test_base.py @@ -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 @@ -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)