Skip to content

Commit

Permalink
fix: validation of serialization methods
Browse files Browse the repository at this point in the history
Makes sure object_attribute_names() works correctly.
  • Loading branch information
joamag committed Feb 1, 2023
1 parent ca1eebf commit 6ff3e0b
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

*
* Issue with the `object_attribute_names()` method that prevented proper serialization

## [1.4.4] - 2022-12-31

Expand Down
3 changes: 2 additions & 1 deletion src/colony/libs/object_util.py
Expand Up @@ -81,7 +81,8 @@ def object_attribute_names(instance):

# filters the attribute names based on the type and value
# of them (non printable attributes are filtered out)
valid_attribute_names = [key for key, value in __object_items(instance) if type(value) in VALID_ATTRIBUTE_TYPES]
valid_attribute_names = [key for key, value in __object_items(instance) if\
isinstance(value, VALID_ATTRIBUTE_TYPES)]

# returns the valid attribute names (ready for print)
return valid_attribute_names
Expand Down
68 changes: 68 additions & 0 deletions src/colony/test/libs/object_util.py
@@ -0,0 +1,68 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Hive Colony Framework
# Copyright (c) 2008-2022 Hive Solutions Lda.
#
# This file is part of Hive Colony Framework
#
# Hive Colony Framework is free software: you can redistribute it and/or modify
# it under the terms of the Apache License as published by the Apache
# Foundation, either version 2.0 of the License, or (at your option) any
# later version.
#
# Hive Colony Framework is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# Apache License for more details.
#
# You should have received a copy of the Apache License along with
# Hive Colony Framework If not, see <http://www.apache.org/licenses/>.

__author__ = "João Magalhães <joamag@hive.pt>"
""" The author(s) of the module """

__version__ = "1.0.0"
""" The version of the module """

__revision__ = "$LastChangedRevision$"
""" The revision number of the module """

__date__ = "$LastChangedDate$"
""" The last change date of the module """

__copyright__ = "Copyright (c) 2008-2022 Hive Solutions Lda."
""" The copyright for the module """

__license__ = "Apache License, Version 2.0"
""" The license for the module """

import colony

class ObjectTest(colony.ColonyTestCase):
"""
Class that tests the object various functions method.
"""

def test_object_attribute_names(self):
"""
Tests the object attribute names selector function.
"""

result = colony.object_attribute_names(
dict(
a = 2,
b = 1,
c = set()
)
)
self.assertEqual(result, ["a", "b"])

result = colony.object_attribute_names(
dict(
a = 2,
b = 1,
c = colony.Decimal(2.0)
)
)
self.assertEqual(result, ["a", "b", "c"])

0 comments on commit 6ff3e0b

Please sign in to comment.