Esempio n. 1
0
class TestSummaryItemWidget(unittest.TestCase):
    def setUp(self):
        self.controller = mock.Mock()
        self.controller.open_view = mock.Mock(side_effect=self._open_view)

        self.context = mock.Mock()
        self.context.config.keys = dict()

        self.action_a = mock.Mock()
        self.displayer_context = DisplayerContext(
            None, self, Actions([("a", "aaaa", self.action_a)]))

        self.widget = SummaryItemWidget(
            "message", "summary", self.displayer_context, controller=self.controller,
            context=self.context)

        self.new_widget = None

    def get_views(self):
        return [("view", self.view1)]

    def view1(self, message):
        return View([])

    def _open_view(self, widget, **kwargs):
        self.new_widget = widget

    def test_render(self):
        self.assertEqual(
            render_to_content(self.widget, (7,)),
            render_widgets_to_content(
                [urwid.AttrMap(urwid.Text("summary"), "summary")],
                (7, 1))
        )

    def test_keypress_enter(self):
        self.assertIsNone(self.widget.keypress(None, "enter"))
        self.assertIsNotNone(self.new_widget)
        self.assertIsInstance(self.new_widget, DetailWidget)

    def test_keypress_custom_action(self):
        self.assertIsNone(self.widget.keypress(None, "a"))
        self.action_a.assert_called_with(self.controller, "message", self.widget)

    def test_set_title(self):
        self.widget.set_title("hahaha")
        self.assertEqual(self.widget.get_title_as_plain_text(), "hahaha")
Esempio n. 2
0
    def setUp(self):
        self.controller = mock.Mock()
        self.controller.open_view = mock.Mock(side_effect=self._open_view)

        self.context = mock.Mock()
        self.context.config.keys = dict()

        self.action_a = mock.Mock()
        self.displayer_context = DisplayerContext(
            None, self, Actions([("a", "aaaa", self.action_a)]))

        self.widget = SummaryItemWidget(
            "message", "summary", self.displayer_context, controller=self.controller,
            context=self.context)

        self.new_widget = None