def test_deserialization_no_dashes(): uuid_attribute = UUIDAttribute(remove_dashes=True) uuid_str_no_dashes = "19c4f2515e364cc0bfeb983dd5d2bacd" assert UUID( "19c4f251-5e36-4cc0-bfeb-983dd5d2bacd") == uuid_attribute.deserialize( uuid_str_no_dashes, )
class Guest(Model, UserMixin): class Meta: table_name = os.getenv("DYNAMO_TABLE") region = os.getenv("AWS_REGION") host = os.getenv("AWS_ENDPOINT_URL", None) id = UUIDAttribute(hash_key=True, default=uuid.uuid4) email = UnicodeAttribute() name = UnicodeAttribute() food_allergies = UnicodeAttribute(null=True) favourite_music = UnicodeAttribute(null=True) last_viewed = UTCDateTimeAttribute(null=True) last_responded = UTCDateTimeAttribute(null=True) number_of_guests = NumberAttribute(default=0) notes = UnicodeAttribute(null=True) will_attend = BooleanAttribute(null=True) filled_by_admin = BooleanAttribute(null=True) def get_id(self): return str(self.id) @staticmethod def find(guest_id: str): try: return Guest.get(guest_id) except DoesNotExist: return None @staticmethod def find_multi_id(guest_ids: list) -> iter: try: return Guest.batch_get(guest_ids) except DoesNotExist: return []
class People(Model): class Meta: table_name = "people" uuid = UUIDAttribute(hash_key=True) first_name = UnicodeAttribute() last_name = UnicodeAttribute() gender = UnicodeEnumAttribute(Gender) age = IntegerAttribute()
class Office(Model): class Meta: table_name = "OfficeModel" host = "http://localhost:{}".format(environ.get("DOCKER_PORT", 8000)) aws_access_key_id = "my_access_key_id" aws_secret_access_key = "my_secret_access_key" office_id = UUIDAttribute(hash_key=True) address = Location() employees = ListAttribute(of=OfficeEmployeeMap) departments = UnicodeSetAttribute() numbers = NumberSetAttribute() security_number = UnicodeAttribute(null=True) office_times = ListAttribute() cls = DiscriminatorAttribute()
class BaseDocument(Model): uuid = UUIDAttribute(default=uuid.uuid4) description = UnicodeAttribute(default="bar") cls = DiscriminatorAttribute()
from pynamodb_attributes import UUIDAttribute from helpers.get_uuid import get_uuid from interface.initializers.nosql import Base from indexes import {{cookiecutter.model_name_camel}}CreatedIndex class {{cookiecutter.model_name_camel}}Document(Base, discriminator="{{cookiecutter.model_name_camel}}"): # type: ignore """{{cookiecutter.model_name_camel}} Model.""" uuid = UUIDAttribute(hash_key=True, default=get_uuid) created_date_index = {{cookiecutter.model_name_camel}}CreatedIndex() class Meta(Base.Meta): pass
def test_serialization_no_dashes(): uuid_attribute = UUIDAttribute(remove_dashes=True) uuid_value = UUID("19c4f251-5e36-4cc0-bfeb-983dd5d2bacd") assert "19c4f2515e364cc0bfeb983dd5d2bacd" == uuid_attribute.serialize( uuid_value)
class MyModel(Model): Meta = dynamodb_table_meta(__name__) key = UnicodeAttribute(hash_key=True) value = UUIDAttribute(null=True)