# Path: microcosm_pubsub/fields.py
# class UUIDField(Field):
#     """
#     UUID valued field, as either a string or UUID object.
# 
#     """
#     def _serialize(self, value, attr, obj, **kwargs):
#         """
#         Serialize value as a uuid, either as a string or an UUID object.
#         """
#         if value is None:
#             return None
# 
#         if isinstance(value, UUID):
#             return str(value)
#         else:
#             return value
# 
#     def _deserialize(self, value, attr, data, **kwargs):
#         """
#         Deserialize value as a uuid.
# 
#         Handle both string and UUID object.
#         """
#         if value is None:
#             return None
# 
#         try:
#             if isinstance(value, UUID):
#                 return str(value)
#             else:
#                 return str(UUID(value))
# 
#         except ValueError:
#             raise ValidationError('Not a valid UUID.')


from uuid import UUID
from hamcrest import (
    assert_that,
    calling,
    equal_to,
    is_,
    raises,
)
from marshmallow import Schema, ValidationError
from microcosm_pubsub.fields import UUIDField
"""
Test fields

"""




UUID_STR = "051263b8-707a-4561-a114-11d6706ca5d5"
# UUID_UUID = UUID(UUID_STR)
INVALID_UUID_STR = "INVALID_UUID_STRING"


class UUIDSchema(Schema):
    uuid_str = UUIDField()

# Path: microcosm_pubsub/fields.py
# class UUIDField(Field):
#     """
#     UUID valued field, as either a string or UUID object.
# 
#     """
#     def _serialize(self, value, attr, obj, **kwargs):
#         """
#         Serialize value as a uuid, either as a string or an UUID object.
#         """
#         if value is None:
#             return None
# 
#         if isinstance(value, UUID):
#             return str(value)
#         else:
#             return value
# 
#     def _deserialize(self, value, attr, data, **kwargs):
#         """
#         Deserialize value as a uuid.
# 
#         Handle both string and UUID object.
#         """
#         if value is None:
#             return None
# 
#         try:
#             if isinstance(value, UUID):
#                 return str(value)
#             else:
#                 return str(UUID(value))
# 
#         except ValueError:
#             raise ValidationError('Not a valid UUID.')


# Path: microcosm_pubsub/tests/test_fields.py
from uuid import UUID
from hamcrest import (
    assert_that,
    calling,
    equal_to,
    is_,
    raises,
)
from marshmallow import Schema, ValidationError
from microcosm_pubsub.fields import UUIDField

"""
Test fields

"""




UUID_STR = "051263b8-707a-4561-a114-11d6706ca5d5"
# UUID_UUID = UUID(UUID_STR)
INVALID_UUID_STR = "INVALID_UUID_STRING"


class UUIDSchema(Schema):
    uuid_str = UUIDField()

    uuid_uuid = UUIDField()