def test_add_message(message_repo: AbstractMessageRepository):
    uuid = str(uuid4())
    expected_title = "My title"
    expected_description = "My description"
    expected_event = "event_id"
    message = MessageEntity(uuid,
                            title=expected_title,
                            description=expected_description,
                            evenement_id=expected_event
                            )
    message_repo.add(message)

    assert message_repo.get_all()[0] == message
def test_fails_to_add_message_when_already_exists(message_repo: AbstractMessageRepository):
    message1_uuid = str(uuid4())
    serialized_message1 = {
        "uuid": message1_uuid,
        "title": "Message 1 title",
        "description": "Message 1 description",
        "evenement_id": "event_id"
    }
    message1 = MessageEntity(uuid=message1_uuid,
                             title=serialized_message1["title"],
                             description=serialized_message1["description"],
                             evenement_id=serialized_message1["evenement_id"],
                             )
    message_repo.add(message1)

    with pytest.raises(AlreadyExistingMessageUuid):
        message_repo.add(message1)
def test_get_by_uuid_when_message_present(message_repo: AbstractMessageRepository):
    message1_uuid = str(uuid4())
    serialized_message1 = {
        "uuid": message1_uuid,
        "title": "Message 1 title",
        "description": "Message 1 description",
        "evenement_id": "event_id"

    }
    message1 = MessageEntity(uuid=message1_uuid,
                             title=serialized_message1["title"],
                             description=serialized_message1["description"],
                             evenement_id=serialized_message1["evenement_id"],

                             )
    message_repo.add(message1)

    message = message_repo.get_by_uuid(message1_uuid)
    assert message == message1
def test_list_messages(message_repo: AbstractMessageRepository):
    message1_uuid = str(uuid4())
    serialized_message1 = {
        "uuid": message1_uuid,
        "title": "Message 1 title",
        "description": "Message 1 description",
        "evenement_id": "event_id"
    }
    message1 = MessageEntity(uuid=message1_uuid,
                             title=serialized_message1["title"],
                             description=serialized_message1["description"],
                             evenement_id=serialized_message1["evenement_id"],

                             )
    message_repo.add(message1)

    messages = message_repo.get_all()

    assert len(messages) == 1
    assert messages[0] == message1
def test_add_message_and_add_tag(message_repo: AbstractMessageRepository, tag_repo: AbstractTagRepository):
    if isinstance(tag_repo, PgRepositoryMixin) and isinstance(message_repo, PgRepositoryMixin):
        message_uuid = str(uuid4())
        tag_uuid = str(uuid4())
        event_uuid = str(uuid4())
        message = MessageEntity(message_uuid, title="Some title", description="Some description", evenement_id=event_uuid)
        tag = TagEntity(tag_uuid, "Some title")
        message_repo.add(message)
        tag_repo.add(tag)
        added_message = message_repo.get_by_uuid(message_uuid)
        added_tag = tag_repo.get_by_uuid(tag_uuid)
        print(added_tag)
        print(added_message)

        message_repo.add_tag_to_message(message=added_message,
                                  tag=added_tag)

        message: MessageEntity = message_repo.get_by_uuid(message_uuid)
        tag: TagEntity = tag_repo.get_by_uuid(tag_uuid)

        assert message.tags[0] == tag
def test_get_by_uuid_when_not_present(message_repo: AbstractMessageRepository):
    with pytest.raises(NotFoundMessage):
        message_repo.get_by_uuid("not_in_repo_uuid")
 def __init__(self, session: Session):
     PgRepositoryMixin.__init__(self,
                                session=session,
                                entity_type=MessageEntity)
     AbstractMessageRepository.__init__(self)