Ejemplo n.º 1
0
    def streams_view(self) -> Any:
        streams_btn_list = [
                StreamButton(
                    stream,
                    controller=self.controller,
                    view=self.view,
                    width=self.width,
                    count=self.model.unread_counts['streams'].get(stream[1], 0)
                ) for stream in self.view.pinned_streams]

        if len(streams_btn_list):
            streams_btn_list += [StreamsViewDivider()]

        streams_btn_list += [
                StreamButton(
                    stream,
                    controller=self.controller,
                    view=self.view,
                    width=self.width,
                    count=self.model.unread_counts['streams'].get(stream[1], 0)
                ) for stream in self.view.unpinned_streams]

        self.view.stream_id_to_button = {stream.stream_id: stream
                                         for stream in streams_btn_list
                                         if hasattr(stream, 'stream_id')}

        self.view.stream_w = StreamsView(streams_btn_list, self.view)
        w = urwid.LineBox(
            self.view.stream_w, title="Streams",
            tlcorner='━', tline='━', lline='',
            trcorner='━', blcorner='', rline='',
            bline='', brcorner='─'
            )
        return w
Ejemplo n.º 2
0
    def test_keypress_ENTER_TOGGLE_TOPIC(
        self,
        mocker: MockerFixture,
        stream_button: StreamButton,
        key: str,
        widget_size: Callable[[Widget], urwid_Size],
    ) -> None:
        size = widget_size(stream_button)
        stream_button.view.left_panel = mocker.Mock()
        stream_button.keypress(size, key)

        stream_button.view.left_panel.show_topic_view.assert_called_once_with(
            stream_button)
Ejemplo n.º 3
0
 def test_keypress_TOGGLE_MUTE_STREAM(
     self,
     mocker: MockerFixture,
     key: str,
     widget_size: Callable[[Widget], urwid_Size],
     stream_button: StreamButton,
     stream_id: int = 205,
     stream_name: str = "PTEST",
 ) -> None:
     size = widget_size(stream_button)
     pop_up = mocker.patch(
         "zulipterminal.core.Controller.stream_muting_confirmation_popup")
     stream_button.keypress(size, key)
     pop_up.assert_called_once_with(stream_id, stream_name)
Ejemplo n.º 4
0
    def streams_view(self) -> Any:
        streams_btn_list = [
            StreamButton(stream,
                         controller=self.controller,
                         view=self.view,
                         width=self.width,
                         count=self.model.unread_counts['streams'].get(
                             stream[1], 0))
            for stream in self.view.pinned_streams
        ]

        if len(streams_btn_list):
            unpinned_divider = urwid.Divider("-")

            # FIXME Necessary since the divider is treated as a StreamButton
            # NOTE: This is specifically for stream search to work correctly
            unpinned_divider.stream_id = -1
            unpinned_divider.stream_name = ''

            streams_btn_list += [unpinned_divider]

        streams_btn_list += [
            StreamButton(stream,
                         controller=self.controller,
                         view=self.view,
                         width=self.width,
                         count=self.model.unread_counts['streams'].get(
                             stream[1], 0))
            for stream in self.view.unpinned_streams
        ]

        self.view.stream_id_to_button = {
            stream.stream_id: stream
            for stream in streams_btn_list if hasattr(stream, 'stream_id')
        }

        self.view.stream_w = StreamsView(streams_btn_list, self.view)
        w = urwid.LineBox(self.view.stream_w,
                          title="Streams",
                          tlcorner=u'━',
                          tline=u'━',
                          lline=u'',
                          trcorner=u'━',
                          blcorner=u'',
                          rline=u'',
                          bline=u'',
                          brcorner=u'─')
        return w
Ejemplo n.º 5
0
    def test_text_content(self, mocker,
                          is_private, expected_prefix,
                          width, count, short_text, caption='caption'):
        controller = mocker.Mock()
        controller.model.is_muted_stream.return_value = False
        controller.model.muted_streams = {}
        properties = {'name': caption, 'id': 5, 'color': '#ffffff',
                      'invite_only': is_private,
                      'description': 'Some Stream Description'}

        view_mock = mocker.Mock()
        view_mock.palette = [(None, 'black', 'white')]
        stream_button = StreamButton(properties,
                                     controller=controller,
                                     view=view_mock,
                                     width=width,
                                     count=count)

        text = stream_button._w._original_widget.get_text()
        count_str = '' if count == 0 else str(count)
        expected_text = ' {} {}{}{}'.format(
                expected_prefix, 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
Ejemplo n.º 6
0
def stream_button(mocker):
    """
    Mocked stream button.
    """
    button = StreamButton(
        properties=['PTEST', 205, '#bfd56f'],
        controller=mocker.patch('zulipterminal.core.Controller'),
        view=mocker.patch('zulipterminal.ui.View'))
    return button
Ejemplo n.º 7
0
    def streams_view(self) -> Any:
        streams_btn_list = [
            StreamButton(stream,
                         controller=self.controller,
                         view=self.view,
                         width=self.width,
                         count=self.model.unread_counts['streams'].get(
                             stream[1], 0))
            for stream in self.view.pinned_streams
        ]

        if len(streams_btn_list):
            unpinned_divider = urwid.Divider("-")

            # FIXME Necessary since the divider is treated as a StreamButton
            unpinned_divider.stream_id = -1
            unpinned_divider.caption = ''

            streams_btn_list += [unpinned_divider]

        streams_btn_list += [
            StreamButton(stream,
                         controller=self.controller,
                         view=self.view,
                         width=self.width,
                         count=self.model.unread_counts['streams'].get(
                             stream[1], 0))
            for stream in self.view.unpinned_streams
        ]

        self.view.stream_w = StreamsView(streams_btn_list, self.view)
        w = urwid.LineBox(self.view.stream_w,
                          title="Streams",
                          tlcorner=u'─',
                          tline=u'─',
                          lline=u'',
                          trcorner=u'─',
                          blcorner=u'',
                          rline=u'',
                          bline=u'',
                          brcorner=u'─')
        return w
Ejemplo n.º 8
0
 def streams_view(self) -> Any:
     streams_btn_list = [
         StreamButton(
             item,
             controller=self.controller,
             view=self,
         ) for item in self.streams
     ]
     w = StreamsView(streams_btn_list)
     w = urwid.LineBox(w, title="Streams")
     return w
Ejemplo n.º 9
0
def stream_button(mocker):
    """
    Mocked stream button.
    """
    view_mock = mocker.Mock()
    view_mock.palette = [(None, 'black', 'white')]
    button = StreamButton(
        properties=['PTEST', 205, '#bfd56f', False, "Test stream description"],
        controller=mocker.patch('zulipterminal.core.Controller'),
        width=40,
        view=view_mock,
        count=30)
    return button
Ejemplo n.º 10
0
 def streams_view(self) -> Any:
     streams_btn_list = list()
     for stream in self.streams:
         unread_count = self.model.unread_counts.get(stream[1], 0)
         streams_btn_list.append(
             StreamButton(
                 stream,
                 controller=self.controller,
                 view=self,
                 count=unread_count,
             ))
     self.stream_w = StreamsView(streams_btn_list)
     w = urwid.LineBox(self.stream_w, title="Streams")
     return w
Ejemplo n.º 11
0
def stream_button(mocker):
    """
    Mocked stream button.
    """
    view_mock = mocker.Mock()
    view_mock.palette = [(None, 'black', 'white')]
    button = StreamButton(
        properties={'name': 'PTEST', 'id': 205,
                    'color': '#bfd56f', 'invite_only': False,
                    'description': "Test stream description"},
        controller=mocker.patch('zulipterminal.core.Controller'),
        width=40,
        view=view_mock,
        count=30
    )
    return button
Ejemplo n.º 12
0
def stream_button(mocker):
    """
    Mocked stream button.
    """
    view_mock = mocker.Mock()
    view_mock.palette = [(None, "black", "white")]
    button = StreamButton(
        properties={
            "name": "PTEST",
            "id": 205,
            "color": "#bfd56f",
            "invite_only": False,
            "description": "Test stream description",
        },
        controller=mocker.patch("zulipterminal.core.Controller"),
        view=view_mock,
        count=30,
    )
    return button
Ejemplo n.º 13
0
 def streams_view(self) -> Any:
     streams_btn_list = list()
     for stream in self.view.streams:
         unread_count = self.model.unread_counts.get(stream[1], 0)
         streams_btn_list.append(
             StreamButton(
                 stream,
                 controller=self.controller,
                 view=self.view,
                 count=unread_count,
             )
         )
     self.view.stream_w = StreamsView(streams_btn_list, self.view)
     w = urwid.LineBox(
         self.view.stream_w, title="Streams",
         tlcorner=u'─', tline=u'─', lline=u'',
         trcorner=u'─', blcorner=u'', rline=u'',
         bline=u'', brcorner=u'─'
         )
     return w
Ejemplo n.º 14
0
    def test_text_content(
        self,
        mocker,
        is_private,
        expected_prefix,
        width,
        count,
        short_text,
        caption="caption",
    ):
        controller = mocker.Mock()
        controller.model.is_muted_stream.return_value = False
        controller.model.muted_streams = {}
        properties = {
            "name": caption,
            "id": 5,
            "color": "#ffffff",
            "invite_only": is_private,
            "description": "Some Stream Description",
        }

        view_mock = mocker.Mock()
        view_mock.palette = [(None, "black", "white")]
        stream_button = StreamButton(properties,
                                     controller=controller,
                                     view=view_mock,
                                     width=width,
                                     count=count)

        text = stream_button._w._original_widget.get_text()
        count_str = "" if count == 0 else str(count)
        expected_text = " {} {}{}{}".format(
            expected_prefix,
            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