Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export UnicodeProtobufEnumAttribute and make prefix optional #53

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pynamodb_attributes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = [
Expand All @@ -22,6 +23,7 @@
"IntegerEnumAttribute",
"UnicodeDelimitedTupleAttribute",
"UnicodeEnumAttribute",
"UnicodeProtobufEnumAttribute",
"TimedeltaAttribute",
"TimedeltaMsAttribute",
"TimedeltaUsAttribute",
Expand Down
2 changes: 1 addition & 1 deletion pynamodb_attributes/unicode_protobuf_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion tests/unicode_protobuf_enum_attribute_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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"},
},
),
(
Expand All @@ -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"},
},
),
],
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading