From e4039bb2df48c2f95f1c19ef0f5f9478c09ec014 Mon Sep 17 00:00:00 2001 From: Roy Tang <25113108+Roytangrb@users.noreply.github.com> Date: Wed, 15 May 2024 19:16:41 -0400 Subject: [PATCH 1/2] add module export, make prefix optional --- pynamodb_attributes/__init__.py | 2 ++ pynamodb_attributes/unicode_protobuf_enum.py | 2 +- tests/unicode_protobuf_enum_attribute_test.py | 12 +++++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pynamodb_attributes/__init__.py b/pynamodb_attributes/__init__.py index 765f8c7..fc6d21e 100644 --- a/pynamodb_attributes/__init__.py +++ b/pynamodb_attributes/__init__.py @@ -12,6 +12,7 @@ from .unicode_datetime import UnicodeDatetimeAttribute from .unicode_delimited_tuple import UnicodeDelimitedTupleAttribute from .unicode_enum import UnicodeEnumAttribute +from .unicode_protobuf_enum import UnicodeProtobufEnumAttribute from .uuid import UUIDAttribute __all__ = [ @@ -22,6 +23,7 @@ "IntegerEnumAttribute", "UnicodeDelimitedTupleAttribute", "UnicodeEnumAttribute", + "UnicodeProtobufEnumAttribute", "TimedeltaAttribute", "TimedeltaMsAttribute", "TimedeltaUsAttribute", diff --git a/pynamodb_attributes/unicode_protobuf_enum.py b/pynamodb_attributes/unicode_protobuf_enum.py index 66ee104..7d8517a 100644 --- a/pynamodb_attributes/unicode_protobuf_enum.py +++ b/pynamodb_attributes/unicode_protobuf_enum.py @@ -50,7 +50,7 @@ def __init__( enum_type: Type[_TProtobufEnum], *, unknown_value: Optional[_TProtobufEnum] = _fail, - prefix: str, + prefix: str = "", lower: bool = True, **kwargs: Any, ) -> None: diff --git a/tests/unicode_protobuf_enum_attribute_test.py b/tests/unicode_protobuf_enum_attribute_test.py index 7c2882f..071ad5d 100644 --- a/tests/unicode_protobuf_enum_attribute_test.py +++ b/tests/unicode_protobuf_enum_attribute_test.py @@ -10,7 +10,7 @@ from pynamodb.models import Model from typing_extensions import assert_type -from pynamodb_attributes.unicode_protobuf_enum import UnicodeProtobufEnumAttribute +from pynamodb_attributes import UnicodeProtobufEnumAttribute from tests.connection import _connection from tests.meta import dynamodb_table_meta @@ -85,6 +85,12 @@ class MyModel(Model): prefix="SHAKE_FLAVOR_", null=True, ) + value_with_prefix = UnicodeProtobufEnumAttribute( + diner_pb2.ShakeFlavor, + unknown_value=diner_pb2.SHAKE_FLAVOR_UNKNOWN, + null=True, + lower=False, + ) map_attr = MyMapAttr(null=True) @@ -140,6 +146,7 @@ def test_serialization_unknown_value_success(uuid_key): "value": {"S": "vanilla"}, "value_upper": {"S": "VANILLA"}, "value_with_unknown": {"S": "vanilla"}, + "value_with_prefix": {"S": "SHAKE_FLAVOR_VANILLA"}, }, ), ( @@ -148,6 +155,7 @@ def test_serialization_unknown_value_success(uuid_key): "value": {"S": "chocolate"}, "value_upper": {"S": "CHOCOLATE"}, "value_with_unknown": {"S": "chocolate"}, + "value_with_prefix": {"S": "SHAKE_FLAVOR_CHOCOLATE"}, }, ), ], @@ -162,6 +170,7 @@ def test_serialization( model.value = value model.value_upper = value model.value_with_unknown = value + model.value_with_prefix = value model.save() # verify underlying storage @@ -173,6 +182,7 @@ def test_serialization( assert model.value == value assert model.value_upper == value assert model.value_with_unknown == value + assert model.value_with_prefix == value def test_map_attribute( # exercises the __deepcopy__ method From e1ac8e29a016c572b6f21185fdd624a882f810ed Mon Sep 17 00:00:00 2001 From: Roy Tang <25113108+Roytangrb@users.noreply.github.com> Date: Wed, 15 May 2024 19:17:35 -0400 Subject: [PATCH 2/2] bump version --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 5585f89..a8c5b1a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,7 +4,7 @@ universal = 1 [metadata] license_file = LICENSE name = pynamodb-attributes -version = 0.5.0 +version = 0.5.1 description = Common attributes for PynamoDB long_description = file:README.md long_description_content_type = text/markdown