Exemplo n.º 1
0
class TestStreamInfoView:
    @pytest.fixture(autouse=True)
    def mock_external_classes(self, mocker, monkeypatch):
        self.controller = mocker.Mock()
        mocker.patch.object(self.controller,
                            'maximum_popup_dimensions',
                            return_value=(64, 64))
        self.controller.model.is_muted_stream.return_value = False
        self.controller.model.is_pinned_stream.return_value = False
        mocker.patch(VIEWS + ".urwid.SimpleFocusListWalker", return_value=[])
        stream_id = 10
        self.controller.model.stream_dict = {
            stream_id: {
                'name': 'books',
                'description': 'hey'
            }
        }
        self.stream_info_view = StreamInfoView(self.controller, stream_id)

    @pytest.mark.parametrize(
        'key',
        {*keys_for_command('GO_BACK'), *keys_for_command('STREAM_DESC')})
    def test_keypress_exit_popup(self, key, widget_size):
        size = widget_size(self.stream_info_view)
        self.stream_info_view.keypress(size, key)
        assert self.controller.exit_popup.called

    def test_keypress_navigation(self, mocker, widget_size,
                                 navigation_key_expected_key_pair):
        key, expected_key = navigation_key_expected_key_pair
        size = widget_size(self.stream_info_view)
        super_keypress = mocker.patch(VIEWS + '.urwid.ListBox.keypress')
        self.stream_info_view.keypress(size, key)
        super_keypress.assert_called_once_with(size, expected_key)

    @pytest.mark.parametrize('key', (*keys_for_command('ENTER'), ' '))
    def test_checkbox_toggle_mute_stream(self, mocker, key, widget_size):
        mute_checkbox = self.stream_info_view.widgets[3]
        toggle_mute_status = self.controller.model.toggle_stream_muted_status
        stream_id = self.stream_info_view.stream_id
        size = widget_size(mute_checkbox)

        mute_checkbox.keypress(size, key)

        toggle_mute_status.assert_called_once_with(stream_id)

    @pytest.mark.parametrize('key', (*keys_for_command('ENTER'), ' '))
    def test_checkbox_toggle_pin_stream(self, mocker, key, widget_size):
        pin_checkbox = self.stream_info_view.widgets[4]
        toggle_pin_status = self.controller.model.toggle_stream_pinned_status
        stream_id = self.stream_info_view.stream_id
        size = widget_size(pin_checkbox)

        pin_checkbox.keypress(size, key)

        toggle_pin_status.assert_called_once_with(stream_id)
Exemplo n.º 2
0
class TestStreamInfoView:
    @pytest.fixture(autouse=True)
    def mock_external_classes(self, mocker, monkeypatch):
        self.controller = mocker.Mock()
        mocker.patch.object(self.controller,
                            'maximum_popup_dimensions',
                            return_value=(64, 64))
        self.controller.model.is_muted_stream.return_value = False
        self.controller.model.is_pinned_stream.return_value = False
        mocker.patch(VIEWS + ".urwid.SimpleFocusListWalker", return_value=[])
        self.stream_id = 10
        self.controller.model.stream_dict = {
            self.stream_id: {
                'name': 'books',
                'invite_only': False,
                'rendered_description': '<p>Hey</p>',
                'subscribers': [],
                'stream_weekly_traffic': 123,
            }
        }
        self.stream_info_view = StreamInfoView(self.controller, self.stream_id)

    def test_keypress_any_key(self, widget_size):
        key = "a"
        size = widget_size(self.stream_info_view)
        self.stream_info_view.keypress(size, key)
        assert not self.controller.exit_popup.called

    @pytest.mark.parametrize('key', keys_for_command('STREAM_MEMBERS'))
    def test_keypress_stream_members(self, mocker, key, widget_size):
        size = widget_size(self.stream_info_view)
        self.stream_info_view.keypress(size, key)
        self.controller.show_stream_members.assert_called_once_with(
            stream_id=self.stream_id, )

    @pytest.mark.parametrize('rendered_description, expected_markup', [
        (
            '<p>Simple</p>',
            (None, ['', '', 'Simple']),
        ),
        (
            '<p>A city in Italy <a href="http://genericlink.com">ABC</a>'
            '<strong>Bold</strong>',
            (None, [
                '', '', 'A city in Italy ', ('msg_link', 'ABC'), ' ',
                ('msg_link_index', '[1]'), ('msg_bold', 'Bold')
            ]),
        ),
    ])
    def test_markup_descrption(self,
                               rendered_description,
                               expected_markup,
                               stream_id=10):
        self.controller.model.stream_dict = {
            stream_id: {
                'name': 'ZT',
                'invite_only': False,
                'subscribers': [],
                'stream_weekly_traffic': 123,
                'rendered_description': rendered_description,
            }
        }

        stream_info_view = StreamInfoView(self.controller, stream_id)

        assert stream_info_view.markup_desc == expected_markup

    @pytest.mark.parametrize(
        [
            'message_links', 'expected_text', 'expected_attrib',
            'expected_footlinks_width'
        ],
        [
            (OrderedDict([
                ('https://example.com', ('Example', 1, True)),
                ('https://generic.com', ('Generic', 2, True)),
            ]), '1: https://example.com\n2: https://generic.com', [
                ('msg_link_index', 2), (None, 1), ('msg_link', 19), (None, 1),
                ('msg_link_index', 2), (None, 1), ('msg_link', 19)
            ], 22),
        ],
    )
    def test_footlinks(self, message_links, expected_text, expected_attrib,
                       expected_footlinks_width):
        footlinks, footlinks_width = MessageBox.footlinks_view(
            message_links,
            maximum_footlinks=10,
            padded=False,
            wrap='space',
        )

        assert footlinks.text == expected_text
        assert footlinks.attrib == expected_attrib
        assert footlinks_width == expected_footlinks_width

    @pytest.mark.parametrize(
        'key',
        {*keys_for_command('GO_BACK'), *keys_for_command('STREAM_DESC')})
    def test_keypress_exit_popup(self, key, widget_size):
        size = widget_size(self.stream_info_view)
        self.stream_info_view.keypress(size, key)
        assert self.controller.exit_popup.called

    def test_keypress_navigation(self, mocker, widget_size,
                                 navigation_key_expected_key_pair):
        key, expected_key = navigation_key_expected_key_pair
        size = widget_size(self.stream_info_view)
        super_keypress = mocker.patch(VIEWS + '.urwid.ListBox.keypress')
        self.stream_info_view.keypress(size, key)
        super_keypress.assert_called_once_with(size, expected_key)

    @pytest.mark.parametrize('key', (*keys_for_command('ENTER'), ' '))
    def test_checkbox_toggle_mute_stream(self, mocker, key, widget_size):
        mute_checkbox = self.stream_info_view.widgets[7]
        toggle_mute_status = self.controller.model.toggle_stream_muted_status
        stream_id = self.stream_info_view.stream_id
        size = widget_size(mute_checkbox)

        mute_checkbox.keypress(size, key)

        toggle_mute_status.assert_called_once_with(stream_id)

    @pytest.mark.parametrize('key', (*keys_for_command('ENTER'), ' '))
    def test_checkbox_toggle_pin_stream(self, mocker, key, widget_size):
        pin_checkbox = self.stream_info_view.widgets[8]
        toggle_pin_status = self.controller.model.toggle_stream_pinned_status
        stream_id = self.stream_info_view.stream_id
        size = widget_size(pin_checkbox)

        pin_checkbox.keypress(size, key)

        toggle_pin_status.assert_called_once_with(stream_id)
Exemplo n.º 3
0
class TestStreamInfoView:
    @pytest.fixture(autouse=True)
    def mock_external_classes(self, mocker, monkeypatch):
        self.controller = mocker.Mock()
        mocker.patch.object(self.controller,
                            "maximum_popup_dimensions",
                            return_value=(64, 64))
        self.controller.model.is_muted_stream.return_value = False
        self.controller.model.is_pinned_stream.return_value = False
        mocker.patch(VIEWS + ".urwid.SimpleFocusListWalker", return_value=[])
        self.stream_id = 10
        self.controller.model.stream_dict = {
            self.stream_id: {
                "name": "books",
                "invite_only": False,
                "rendered_description": "<p>Hey</p>",
                "subscribers": [],
                "stream_weekly_traffic": 123,
            }
        }
        self.stream_info_view = StreamInfoView(self.controller, self.stream_id)

    def test_keypress_any_key(self, widget_size):
        key = "a"
        size = widget_size(self.stream_info_view)
        self.stream_info_view.keypress(size, key)
        assert not self.controller.exit_popup.called

    @pytest.mark.parametrize("key", keys_for_command("STREAM_MEMBERS"))
    def test_keypress_stream_members(self, mocker, key, widget_size):
        size = widget_size(self.stream_info_view)
        self.stream_info_view.keypress(size, key)
        self.controller.show_stream_members.assert_called_once_with(
            stream_id=self.stream_id, )

    @pytest.mark.parametrize(
        "rendered_description, expected_markup",
        [
            (
                "<p>Simple</p>",
                (None, ["", "", "Simple"]),
            ),
            (
                '<p>A city in Italy <a href="http://genericlink.com">ABC</a>'
                "<strong>Bold</strong>",
                (
                    None,
                    [
                        "",
                        "",
                        "A city in Italy ",
                        ("msg_link", "ABC"),
                        " ",
                        ("msg_link_index", "[1]"),
                        ("msg_bold", "Bold"),
                    ],
                ),
            ),
        ],
    )
    def test_markup_descrption(self,
                               rendered_description,
                               expected_markup,
                               stream_id=10):
        self.controller.model.stream_dict = {
            stream_id: {
                "name": "ZT",
                "invite_only": False,
                "subscribers": [],
                "stream_weekly_traffic": 123,
                "rendered_description": rendered_description,
            }
        }

        stream_info_view = StreamInfoView(self.controller, stream_id)

        assert stream_info_view.markup_desc == expected_markup

    @pytest.mark.parametrize(
        "message_links, expected_text, expected_attrib, expected_footlinks_width",
        [
            (
                OrderedDict([
                    ("https://example.com", ("Example", 1, True)),
                    ("https://generic.com", ("Generic", 2, True)),
                ]),
                "1: https://example.com\n2: https://generic.com",
                [
                    ("msg_link_index", 2),
                    (None, 1),
                    ("msg_link", 19),
                    (None, 1),
                    ("msg_link_index", 2),
                    (None, 1),
                    ("msg_link", 19),
                ],
                22,
            ),
        ],
    )
    def test_footlinks(self, message_links, expected_text, expected_attrib,
                       expected_footlinks_width):
        footlinks, footlinks_width = MessageBox.footlinks_view(
            message_links,
            maximum_footlinks=10,
            padded=False,
            wrap="space",
        )

        assert footlinks.text == expected_text
        assert footlinks.attrib == expected_attrib
        assert footlinks_width == expected_footlinks_width

    @pytest.mark.parametrize(
        "key",
        {*keys_for_command("GO_BACK"), *keys_for_command("STREAM_DESC")})
    def test_keypress_exit_popup(self, key, widget_size):
        size = widget_size(self.stream_info_view)
        self.stream_info_view.keypress(size, key)
        assert self.controller.exit_popup.called

    def test_keypress_navigation(self, mocker, widget_size,
                                 navigation_key_expected_key_pair):
        key, expected_key = navigation_key_expected_key_pair
        size = widget_size(self.stream_info_view)
        super_keypress = mocker.patch(VIEWS + ".urwid.ListBox.keypress")
        self.stream_info_view.keypress(size, key)
        super_keypress.assert_called_once_with(size, expected_key)

    @pytest.mark.parametrize("key", (*keys_for_command("ENTER"), " "))
    def test_checkbox_toggle_mute_stream(self, mocker, key, widget_size):
        mute_checkbox = self.stream_info_view.widgets[7]
        toggle_mute_status = self.controller.model.toggle_stream_muted_status
        stream_id = self.stream_info_view.stream_id
        size = widget_size(mute_checkbox)

        mute_checkbox.keypress(size, key)

        toggle_mute_status.assert_called_once_with(stream_id)

    @pytest.mark.parametrize("key", (*keys_for_command("ENTER"), " "))
    def test_checkbox_toggle_pin_stream(self, mocker, key, widget_size):
        pin_checkbox = self.stream_info_view.widgets[8]
        toggle_pin_status = self.controller.model.toggle_stream_pinned_status
        stream_id = self.stream_info_view.stream_id
        size = widget_size(pin_checkbox)

        pin_checkbox.keypress(size, key)

        toggle_pin_status.assert_called_once_with(stream_id)