Esempio n. 1
0
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
Esempio n. 2
0
 def add_message_from_meeting(meeting: MeetingEntity,
                              uow: AbstractUnitOfWork):
     with uow:
         message: MessageEntity = MessageEntity.from_meeting(
             meeting=meeting)
         evenement: EvenementEntity = uow.evenement.get_by_uuid(
             uuid=meeting.evenement_id)
         MessageService.save_message(message, uow=uow)
         evenement.add_message(message=message)
         user: UserEntity = uow.user.get_by_uuid(uuid=meeting.creator_id)
         message.set_creator(user=user)
Esempio n. 3
0
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
Esempio n. 4
0
def test_remove_tag(message: MessageEntity, tag_factory):
    tag1 = tag_factory()
    message.add_tag(tag=tag1)
    message.remove_tag(tag=tag1)
    assert len(message.tags) == 0
    with pytest.raises(NotFoundTagInThisMessage):
        message.get_tag_by_id(uuid=tag1.uuid)
Esempio n. 5
0
def test_add_message(uow: AbstractUnitOfWork):
    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)
    with uow:
        uow.message.add(message)

        assert uow.message.get_all()[0] == message
Esempio n. 6
0
def test_add_tag(message: MessageEntity, tag_factory):
    tag1 = tag_factory()
    message.add_tag(tag=tag1)
    assert len(message.tags) == 1
    assert message.get_tag_by_id(uuid=tag1.uuid) == tag1
    with pytest.raises(TagAlreadyInThisMessage):
        message.add_tag(tag=tag1)
    tag2 = tag_factory()
    message.add_tag(tag=tag2)
    assert len(message.tags) == 2
    assert message.tags == [tag1, tag2]
Esempio n. 7
0
def test_fails_to_add_message_when_already_exists(uow: AbstractUnitOfWork):
    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"])
    with uow:
        uow.message.add(message1)

        with pytest.raises(AlreadyExistingMessageUuid):
            uow.message.add(message1)
Esempio n. 8
0
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)
Esempio n. 9
0
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
Esempio n. 10
0
def test_get_by_uuid_when_message_present(uow: AbstractUnitOfWork):
    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"],
    )
    with uow:
        uow.message.add(message1)

        message = uow.message.get_by_uuid(message1_uuid)
        assert message == message1
Esempio n. 11
0
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
Esempio n. 12
0
def test_list_messages(uow: AbstractUnitOfWork):
    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"],
    )

    with uow:
        uow.message.add(message1)

        messages = uow.message.get_all()

        assert len(messages) == 1
        assert messages[0] == message1
Esempio n. 13
0
 def make_message(self, data: dict, **kwargs):
     entity = MessageEntity.from_dict(data)
     return entity
Esempio n. 14
0
 def add_message_from_affair(affair: SimpleAffairEntity,
                             evenement: EvenementEntity,
                             uow: AbstractUnitOfWork):
     message: MessageEntity = MessageEntity.from_affair(affair=affair)
     MessageService.save_message(message, uow=uow)
     evenement.add_message(message=message)
Esempio n. 15
0
 def add_restricted_group(message: MessageEntity, uow: AbstractUnitOfWork):
     if message.restricted_to_group_ids:
         for group_id in message.restricted_to_group_ids:
             group: GroupEntity = uow.group.get_by_uuid(uuid=group_id)
             message.add_group_restriction(group=group)
Esempio n. 16
0
 def add_tags(message: MessageEntity, tag_ids: List[str],
              uow: AbstractUnitOfWork):
     if tag_ids:
         tags = uow.tag.get_by_uuid_list(tag_ids)
         for tag in tags:
             message.add_tag(tag=tag)
Esempio n. 17
0
 def add_resources(message: MessageEntity, resource_ids: List[str],
                   uow: AbstractUnitOfWork):
     if resource_ids:
         resources = uow.resource.get_by_uuid_list(resource_ids)
         for resource in resources:
             message.add_resource(resource=resource)
Esempio n. 18
0
 def get_all_entries(self) -> List[MessageEntity]:
     entries: List[MessageEntity] = self.messages + \
         [MessageEntity.from_affair(affair=affair) for affair in self.affairs]
     return entries