Пример #1
0
    def test_activate_called_once_on_keypress(
        self,
        mocker,
        enter_key,
        widget_size,
        caption="some user",
        email="some_email",
        user_id=5,
    ):
        user: Dict[str, Any] = {
            "email": email,
            "user_id": user_id,
            "full_name": caption,
        }
        activate = mocker.patch(MODULE + ".UserButton.activate")
        user_button = UserButton(
            user,
            controller=mocker.Mock(),
            view=mocker.Mock(),
            color=mocker.Mock(),
            state_marker="*",
            count=mocker.Mock(),
        )
        size = widget_size(user_button)

        user_button.keypress(size, enter_key)

        assert activate.call_count == 1
Пример #2
0
 def users_view(self, users: Any = None) -> Any:
     reset_default_view_users = False
     if users is None:
         users = self.view.users.copy()
         reset_default_view_users = True
     users_btn_list = list()  # type: List[Any]
     for user in users:
         # Only include `inactive` users in search result.
         if user['status'] == 'inactive' and\
                 not self.view.controller.editor_mode:
             continue
         unread_count = (self.view.model.unread_counts['unread_pms'].get(
             user['user_id'], 0))
         users_btn_list.append(
             UserButton(user,
                        controller=self.view.controller,
                        view=self.view,
                        width=self.width,
                        color=user['status'],
                        count=unread_count))
     user_w = UsersView(users_btn_list)
     # Donot reset them while searching.
     if reset_default_view_users:
         self.users_btn_list = users_btn_list
         self.view.user_w = user_w
     return user_w
Пример #3
0
    def test_activate_called_once_on_keypress(
        self,
        mocker,
        enter_key,
        widget_size,
        caption="some user",
        width=30,
        email='some_email',
        user_id=5,
    ):
        user: Dict[str, Any] = {
            'email': email,
            'user_id': user_id,
            'full_name': caption,
        }
        activate = mocker.patch(BUTTONS + ".UserButton.activate")
        user_button = UserButton(user,
                                 controller=mocker.Mock(),
                                 view=mocker.Mock(),
                                 width=width,
                                 color=mocker.Mock(),
                                 state_marker="*",
                                 count=mocker.Mock())
        size = widget_size(user_button)

        user_button.keypress(size, enter_key)

        assert activate.call_count == 1
Пример #4
0
    def test_text_content(self,
                          mocker,
                          width,
                          count,
                          short_text,
                          caption='caption'):
        mocker.patch(STREAMBUTTON + ".mark_muted")
        user: Dict[str, Any] = {
            'email': 'some_email',  # value unimportant
            'user_id': 5,  # value unimportant
            'full_name': caption,
        }
        user_button = UserButton(
            user,
            controller=mocker.Mock(),
            view=mocker.Mock(),
            width=width,
            color=None,  # FIXME test elsewhere?
            state_marker="*",
            count=count)

        text = user_button._w._original_widget.get_text()
        count_str = '' if count == 0 else str(count)
        expected_text = ' * {}{}{}'.format(
            short_text, (width - 4 - len(short_text) - len(count_str)) * ' ',
            count_str)
        assert len(text[0]) == len(expected_text) == (width - 1)
        assert text[0] == expected_text
Пример #5
0
    def test_activate_called_once_on_keypress(
        self,
        mocker: MockerFixture,
        enter_key: str,
        widget_size: Callable[[Widget], urwid_Size],
        caption: str = "some user",
        email: str = "some_email",
        user_id: int = 5,
    ) -> None:
        user: Dict[str, Any] = {
            "email": email,
            "user_id": user_id,
            "full_name": caption,
        }
        activate = mocker.patch(MODULE + ".UserButton.activate")
        user_button = UserButton(
            user=user,
            controller=mocker.Mock(),
            view=mocker.Mock(),
            color=mocker.Mock(),
            state_marker="*",
            count=mocker.Mock(),
        )
        size = widget_size(user_button)

        user_button.keypress(size, enter_key)

        assert activate.call_count == 1
Пример #6
0
 def users_view(self) -> Any:
     users_btn_list = [
         UserButton(item['full_name'],
                    item['email'],
                    controller=self.controller,
                    view=self,
                    color=item['status']) for item in self.users
     ]
     w = UsersView(urwid.SimpleFocusListWalker(users_btn_list))
     return w
Пример #7
0
def user_button(mocker):
    """
    Mocked User Button.
    """
    return UserButton(user={
        'user_id': 5179,
        'full_name': 'Boo Boo',
        'email': '*****@*****.**',
    },
                      controller=mocker.patch('zulipterminal.core.Controller'),
                      view=mocker.patch('zulipterminal.ui.View'))
Пример #8
0
 def users_view(self) -> Any:
     users_btn_list = list()
     for user in self.users:
         unread_count = self.model.unread_counts.get(user['user_id'], 0)
         users_btn_list.append(
             UserButton(user,
                        controller=self.controller,
                        view=self,
                        color=user['status'],
                        count=unread_count))
     self.user_w = UsersView(urwid.SimpleFocusListWalker(users_btn_list))
     return self.user_w
Пример #9
0
def user_button(mocker):
    """
    Mocked User Button.
    """
    return UserButton(
        user={
            "user_id": 5179,
            "full_name": "Boo Boo",
            "email": "*****@*****.**",
        },
        controller=mocker.patch("zulipterminal.core.Controller"),
        view=mocker.patch("zulipterminal.ui.View"),
        state_marker="*",
    )