def test_keypress_emoji_button(
        self,
        mocker: MockerFixture,
        key: str,
        emoji: Tuple[str, str, List[str]],
        has_user_reacted: bool,
        is_selected_final: bool,
        widget_size: Callable[[Widget], urwid_Size],
        message_fixture: Message,
        expected_reaction_count: int,
    ) -> None:
        controller = mocker.Mock()
        controller.model.has_user_reacted_to_message = mocker.Mock(
            return_value=has_user_reacted)
        message_fixture.update({
            "reactions": [
                {
                    "emoji_name": "smile",
                    "user": [{
                        "id": 10
                    }]
                },
                {
                    "emoji_name": "+1",
                    "user": [{
                        "id": 52
                    }]
                },
            ],
        })
        emoji_button = EmojiButton(
            controller=controller,
            emoji_unit=emoji,
            message=message_fixture,
            reaction_count=1,
            is_selected=lambda *_: is_selected_final,
            toggle_selection=lambda *_: None,
        )
        size = widget_size(emoji_button)

        emoji_button.keypress(size, key)

        reaction_count = emoji_button.reaction_count
        reaction_count_text = "" if reaction_count == 0 else f"{reaction_count}"
        suffix_text = (f"{CHECK_MARK} " + reaction_count_text
                       if has_user_reacted != is_selected_final else
                       reaction_count_text)
        assert emoji_button.emoji_name == emoji[0]
        assert reaction_count == expected_reaction_count
        assert emoji_button.button_suffix.get_text()[0].strip() == suffix_text
def test_is_muted(
    mocker: MockerFixture,
    msg: Message,
    narrow: List[Any],
    muted_streams: List[int],
    is_muted_topic_return_value: bool,
    muted: bool,
) -> None:
    model = mocker.Mock()
    model.is_muted_stream = mocker.Mock(
        return_value=(msg.get("stream_id", "") in muted_streams))
    model.narrow = narrow
    model.is_muted_topic.return_value = is_muted_topic_return_value
    return_value = is_muted(msg, model)
    assert return_value is muted
Beispiel #3
0
def msg_template_factory(
    msg_id: int,
    msg_type: str,
    timestamp: int,
    *,
    subject: str = "",
    stream_id: Optional[int] = None,
    recipients: Union[str, List[Dict[str, Any]]] = "PTEST",
) -> Message:
    """
    Generate message template for all types of messages(stream/PM/group)
    """
    # TODO: Separate Message into distinct types for stream and private messages.
    message = Message(
        id=msg_id,
        sender_full_name="Foo Foo",
        timestamp=timestamp,
        client="website",
        sender_email="*****@*****.**",
        type=msg_type,
        sender_realm_str="",
        flags=["read"],
        sender_id=5140,
        content_type="text/x-markdown",
        subject=subject,
        reactions=[],
        subject_links=[],
        avatar_url="dummy_avatar_url",
        is_me_message=False,
        content=f"{msg_type} content here.",
        display_recipient=recipients,
    )

    if msg_type == "stream":
        assert isinstance(stream_id, int)
        assert isinstance(recipients, str)
        message["stream_id"] = stream_id
    else:
        assert isinstance(recipients, list)
        for _val in recipients:
            assert isinstance(_val, dict)

    return message
Beispiel #4
0

initial_index = Index(
    pointer=defaultdict(set),
    all_msg_ids=set(),
    starred_msg_ids=set(),
    mentioned_msg_ids=set(),
    private_msg_ids=set(),
    private_msg_ids_by_user_ids=defaultdict(set),
    stream_msg_ids_by_stream_id=defaultdict(set),
    topic_msg_ids=defaultdict(dict),
    edited_messages=set(),
    topics=defaultdict(list),
    search=set(),
    # mypy bug: https://github.com/python/mypy/issues/7217
    messages=defaultdict(lambda: Message()),
)


class UnreadCounts(TypedDict):
    all_msg: int
    all_pms: int
    all_mentions: int
    unread_topics: Dict[Tuple[int, str], int]  # stream_id, topic
    unread_pms: Dict[int, int]  # sender_id
    unread_huddles: Dict[FrozenSet[int], int]  # Group pms
    streams: Dict[int, int]  # stream_id


def asynch(func: Callable[..., None]) -> Callable[..., None]:
    """