# Path: baroque/entities/event.py
# class Event:
#     """An event that can be published.
# 
#     Args:
#         eventtype (:obj:`baroque.entities.eventtype.EventType` instance or `type` object): the type of the event
#         payload (dict, optional): the content of this event
#         description (str, optional): the description of this event
#         owner (str, optional): the owner of this event
# 
#     """
#     def __init__(self, eventtype, payload=None, description=None, owner=None):
#         assert eventtype is not None
#         if type(eventtype) == type:
#             eventtype = eventtype()
#         assert isinstance(eventtype, EventType)
#         if payload is not None:
#             assert isinstance(payload, dict)
#         self.id = str(uuid.uuid4())
#         self.type = eventtype
#         self.owner = owner
#         self.status = EventStatus.UNPUBLISHED
#         self.description = description
#         self.payload = payload
#         self.tags = set()
#         self.timestamp = None
#         self.touch()
# 
#     def set_published(self):
#         """Sets the status of this event to published."""
#         self.status = EventStatus.PUBLISHED
# 
#     def set_unpublished(self):
#         """Sets the status of this event to unpublished."""
#         self.status = EventStatus.UNPUBLISHED
# 
#     def touch(self):
#         """Sets the current time as timestamp of this event"""
#         self.timestamp = ts.utc_now()
# 
#     def json(self):
#         """Dumps this object to a JSON string.
# 
#         Returns:
#             str
# 
#         """
#         data = dict(id=self.id, type=self.type.json(),
#                     owner=self.owner, status=self.status,
#                     description=self.description, payload=self.payload,
#                     tags=list(self.tags), timestamp=ts.stringify(self.timestamp))
#         return dumps(data)
# 
#     def md5(self):
#         """Returns the MD5 hash of this object.
# 
#         Returns:
#             str
# 
#         """
#         m = hashlib.md5()
#         m.update(self.json().encode('utf-8'))
#         return m.hexdigest()
# 
#     def __repr__(self):
#         return '<{}.{} - type: {} - id: {}>'.format(
#             __name__,
#             self.__class__.__name__,
#             self.type.__class__.__name__,
#             self.id
#         )
# 
# class EventStatus:
#     """
#     Represents the binary state of events publication: ``published`` or
#     ``unpublished``"""
#     UNPUBLISHED = 'unpublished'
#     PUBLISHED = 'published'
# 
# Path: baroque/defaults/eventtypes.py
# class GenericEventType(EventType):
#     """Describes generic events with a free-form content.
# 
#     Args:
#         owner (str, optional): ID of the owner of this event type.
# 
#     """
#     def __init__(self, owner=None):
#         EventType.__init__(self,
#                            '''{
#                              "$schema": "http://json-schema.org/draft-04/schema#"
#                            }''',
#                            description='Generic event',
#                            owner=owner)


import pytest
from baroque.entities.event import Event, EventStatus
from baroque.defaults.eventtypes import GenericEventType
              owner=1234)
    assert isinstance(e.type, GenericEventType)
    assert e.id is not None
    assert not e.tags
    assert e.status == EventStatus.UNPUBLISHED
    assert e.timestamp is not None


def test_constructor_with_type_objects():
    e1 = Event(GenericEventType(), payload=dict(a=1, b=2), description='hello',
               owner=1234)
    e2 = Event(GenericEventType, payload=dict(a=1, b=2), description='hello',
               owner=1234)
    assert isinstance(e1.type, GenericEventType)
    assert isinstance(e2.type, GenericEventType)


def test_touch():
    e = Event(GenericEventType(), payload=dict(a=1, b=2), description='hello',
              owner=1234)
    ts1 = e.timestamp
    e = Event(GenericEventType(), payload=dict(a=1, b=2), description='hello',
              owner=1234)
    ts2 = e.timestamp
    assert ts2 > ts1


def test_md5():
    e = Event(GenericEventType(), payload=dict(a=1, b=2), description='hello',
              owner=1234)

# Path: baroque/entities/event.py
# class Event:
#     """An event that can be published.
# 
#     Args:
#         eventtype (:obj:`baroque.entities.eventtype.EventType` instance or `type` object): the type of the event
#         payload (dict, optional): the content of this event
#         description (str, optional): the description of this event
#         owner (str, optional): the owner of this event
# 
#     """
#     def __init__(self, eventtype, payload=None, description=None, owner=None):
#         assert eventtype is not None
#         if type(eventtype) == type:
#             eventtype = eventtype()
#         assert isinstance(eventtype, EventType)
#         if payload is not None:
#             assert isinstance(payload, dict)
#         self.id = str(uuid.uuid4())
#         self.type = eventtype
#         self.owner = owner
#         self.status = EventStatus.UNPUBLISHED
#         self.description = description
#         self.payload = payload
#         self.tags = set()
#         self.timestamp = None
#         self.touch()
# 
#     def set_published(self):
#         """Sets the status of this event to published."""
#         self.status = EventStatus.PUBLISHED
# 
#     def set_unpublished(self):
#         """Sets the status of this event to unpublished."""
#         self.status = EventStatus.UNPUBLISHED
# 
#     def touch(self):
#         """Sets the current time as timestamp of this event"""
#         self.timestamp = ts.utc_now()
# 
#     def json(self):
#         """Dumps this object to a JSON string.
# 
#         Returns:
#             str
# 
#         """
#         data = dict(id=self.id, type=self.type.json(),
#                     owner=self.owner, status=self.status,
#                     description=self.description, payload=self.payload,
#                     tags=list(self.tags), timestamp=ts.stringify(self.timestamp))
#         return dumps(data)
# 
#     def md5(self):
#         """Returns the MD5 hash of this object.
# 
#         Returns:
#             str
# 
#         """
#         m = hashlib.md5()
#         m.update(self.json().encode('utf-8'))
#         return m.hexdigest()
# 
#     def __repr__(self):
#         return '<{}.{} - type: {} - id: {}>'.format(
#             __name__,
#             self.__class__.__name__,
#             self.type.__class__.__name__,
#             self.id
#         )
# 
# class EventStatus:
#     """
#     Represents the binary state of events publication: ``published`` or
#     ``unpublished``"""
#     UNPUBLISHED = 'unpublished'
#     PUBLISHED = 'published'
# 
# Path: baroque/defaults/eventtypes.py
# class GenericEventType(EventType):
#     """Describes generic events with a free-form content.
# 
#     Args:
#         owner (str, optional): ID of the owner of this event type.
# 
#     """
#     def __init__(self, owner=None):
#         EventType.__init__(self,
#                            '''{
#                              "$schema": "http://json-schema.org/draft-04/schema#"
#                            }''',
#                            description='Generic event',
#                            owner=owner)


# Path: tests/entities/test_event.py
import pytest
from baroque.entities.event import Event, EventStatus
from baroque.defaults.eventtypes import GenericEventType

              owner=1234)
    assert isinstance(e.type, GenericEventType)
    assert e.id is not None
    assert not e.tags
    assert e.status == EventStatus.UNPUBLISHED
    assert e.timestamp is not None


def test_constructor_with_type_objects():
    e1 = Event(GenericEventType(), payload=dict(a=1, b=2), description='hello',
               owner=1234)
    e2 = Event(GenericEventType, payload=dict(a=1, b=2), description='hello',
               owner=1234)
    assert isinstance(e1.type, GenericEventType)
    assert isinstance(e2.type, GenericEventType)


def test_touch():
    e = Event(GenericEventType(), payload=dict(a=1, b=2), description='hello',
              owner=1234)
    ts1 = e.timestamp
    e = Event(GenericEventType(), payload=dict(a=1, b=2), description='hello',
              owner=1234)
    ts2 = e.timestamp
    assert ts2 > ts1


def test_md5():
    e = Event(GenericEventType(), payload=dict(a=1, b=2), description='hello',
              owner=1234)

    assert e.md5() is not None