Beispiel #1
0
    def test_handle_action_threaded(self, ProgressDialog):
        ProgressDialog.return_value = mock.Mock()

        resource = mock.MagicMock(status=0,
                                  name='mock',
                                  label='Mock',
                                  reason='Reason',
                                  reason_long='Long reason')
        manager = ResourceStatusManager.get_instance()
        box = ResourceStatusBox(resource, manager)

        action = ResourceStatusAction(Settable(label='baz'),
                                      'foo',
                                      'bar',
                                      lambda: None,
                                      threaded=True)
        btn = box.add_action(action)
        with mock.patch.object(manager, 'handle_action') as handle_action:
            t = mock.Mock()
            t.is_alive.side_effect = [True, False]

            handle_action.return_value = t
            self.click(btn)

            self.assertCalledOnceWith(handle_action, action)
            self.assertCalledOnceWith(
                ProgressDialog,
                'Executing "bar". This might take a while...',
                pulse=True)
Beispiel #2
0
    def test_handle_action(self):
        dialog = StatusDialog()
        manager = ResourceStatusManager.get_instance()

        action = ResourceStatusAction(object(), 'foo', 'bar', lambda: None,
                                      threaded=False)
        with mock.patch.object(manager, 'handle_action') as handle_action:
            dialog._handle_action(action)
            self.assertCalledOnceWith(handle_action, action)
Beispiel #3
0
    def test_handle_action(self):
        dialog = StatusDialog()
        manager = ResourceStatusManager.get_instance()

        action = ResourceStatusAction(object(),
                                      'foo',
                                      'bar',
                                      lambda: None,
                                      threaded=False)
        with mock.patch.object(manager, 'handle_action') as handle_action:
            dialog._handle_action(action)
            self.assertCalledOnceWith(handle_action, action)
Beispiel #4
0
    def __init__(self):
        super(StatusButton, self).__init__()

        self._blink_id = None
        self._imgs = collections.deque()
        self._image = Gtk.Image()
        self.set_image(self._image)

        self._manager = ResourceStatusManager.get_instance()
        self._manager.connect('status-changed',
                              self._on_manager__status_changed)

        self.set_relief(Gtk.ReliefStyle.NONE)
        self._update_status(None)
        self._manager.refresh_and_notify(force=True)
Beispiel #5
0
    def __init__(self):
        super(StatusButton, self).__init__()

        self._blink_id = None
        self._imgs = collections.deque()
        self._image = gtk.Image()
        self.set_image(self._image)

        self._manager = ResourceStatusManager.get_instance()
        self._manager.connect('status-changed',
                              self._on_manager__status_changed)

        self.set_relief(gtk.RELIEF_NONE)
        self._update_status(None)
        self._manager.refresh_and_notify(force=True)
Beispiel #6
0
    def __init__(self, compact=False):
        super(StatusBox, self).__init__()
        self._compact = compact

        self._manager = ResourceStatusManager.get_instance()

        self._widgets = {}
        self._setup_ui()

        self._manager.connect('status-changed',
                              self._on_manager__status_changed)
        self._manager.connect('action-started',
                              self._on_manager__action_started)
        self._manager.connect('action-finished',
                              self._on_manager__action_finished)
Beispiel #7
0
    def test_handle_action(self):
        resource = mock.MagicMock(status=0,
                                  name='mock',
                                  label='Mock',
                                  reason='Reason',
                                  reason_long='Long reason')
        manager = ResourceStatusManager.get_instance()
        box = ResourceStatusBox(resource, manager)

        action = ResourceStatusAction(object(),
                                      'foo',
                                      'bar',
                                      lambda: None,
                                      threaded=False)
        btn = box.add_action(action)
        with mock.patch.object(manager, 'handle_action') as handle_action:
            self.click(btn)
            self.assertCalledOnceWith(handle_action, action)
Beispiel #8
0
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('size', self.size)
        kwargs.setdefault('title', self.title)

        super(StatusDialog, self).__init__(*args, **kwargs)

        self._manager = ResourceStatusManager.get_instance()
        self._manager.connect('status-changed',
                              self._on_manager__status_changed)
        self._manager.connect('action-finished',
                              self._on_manager__action_finished)

        with api.new_store() as store:
            user = api.get_current_user(store)
            self._is_admin = user.profile.check_app_permission(u'admin')

        self._widgets = {}
        self._setup_ui()
Beispiel #9
0
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('size', self.size)
        kwargs.setdefault('title', self.title)

        super(StatusDialog, self).__init__(*args, **kwargs)

        self._manager = ResourceStatusManager.get_instance()
        self._manager.connect('status-changed',
                              self._on_manager__status_changed)
        self._manager.connect('action-finished',
                              self._on_manager__action_finished)

        with api.new_store() as store:
            user = api.get_current_user(store)
            self._is_admin = user.profile.check_app_permission(u'admin')

        self._widgets = {}
        self._setup_ui()
Beispiel #10
0
    def test_resource_boxes(self):
        action = ResourceStatusAction(object(),
                                      'foo',
                                      'bar',
                                      lambda: None,
                                      threaded=False)
        resource = mock.MagicMock(status=0,
                                  name='mock',
                                  label='Mock',
                                  reason='Reason',
                                  reason_long=None)
        resource.get_actions.return_value = [action]
        manager = ResourceStatusManager.get_instance()

        # Compact
        box = ResourceStatusBox(resource, manager, compact=True)
        box.update_ui()
        self.check_widget(box, 'status-box-resource-compact')

        # Normal
        box = ResourceStatusBox(resource, manager, compact=False)
        box.update_ui()
        self.check_widget(box, 'status-box-resource-not-compact')

        # Long reason
        resource.long_reason = 'Long reason'
        box = ResourceStatusBox(resource, manager, compact=False)
        box.update_ui()
        self.check_widget(box, 'status-box-resource-long-reason')

        # Running
        manager.running_action = action
        box = ResourceStatusBox(resource, manager)
        box.update_ui()
        self.check_widget(box, 'status-box-resource-running')
        manager.running_action = None

        # admin user
        action.admin_only = True
        box = ResourceStatusBox(resource, manager)
        box._is_admin = False
        box.update_ui()
        self.check_widget(box, 'status-box-resource-admin')
Beispiel #11
0
    def test_handle_action_threaded(self, ProgressDialog):
        ProgressDialog.return_value = mock.Mock()

        dialog = StatusDialog()
        manager = ResourceStatusManager.get_instance()

        action = ResourceStatusAction(Settable(label='baz'), 'foo', 'bar',
                                      lambda: None, threaded=True)
        with mock.patch.object(manager, 'handle_action') as handle_action:
            t = mock.Mock()
            t.is_alive.return_value = False

            handle_action.return_value = t
            dialog._handle_action(action)

            self.assertCalledOnceWith(handle_action, action)
            self.assertCalledOnceWith(
                ProgressDialog,
                'Executing "bar". This might take a while...', pulse=True)
Beispiel #12
0
    def __init__(self, widget, count=0, blink=False):
        if isinstance(widget, Gtk.Button):
            # For buttons, put the notification *inside* the button, otherwise buttons
            # that are in a 'linked' box will be draw incorrectly.
            # Buttons have a style padding that must be removed so that the notification
            # appears as close to the border as possible.
            context = widget.get_style_context()
            padding = context.get_padding(Gtk.StateFlags.NORMAL)

            # But we must add that padding to the child (as margin), so that its not too
            # tight
            widget = widget.get_child()
            widget.props.margin_top = padding.top
            widget.props.margin_left = padding.left
            widget.props.margin_right = padding.right
            widget.props.margin_bottom = padding.bottom
            context.add_class('no-padding')

        super(NotificationCounter, self).__init__()
        replace_widget(widget, self)
        self.add(widget)

        label = Gtk.Label.new()
        label.get_style_context().add_class('warning_count')
        label.set_use_markup(True)
        if blink:
            label.get_style_context().add_class('blink')

        # Maybe add other positional options
        label.props.margin_top = 2
        label.props.margin_right = 2
        label.set_halign(Gtk.Align.END)
        label.set_valign(Gtk.Align.START)

        self.add_overlay(label)
        self.set_overlay_pass_through(label, True)
        self.label = label
        self.show()

        self.set_count(count)
        self.status = ResourceStatusManager.get_instance()
        self.status.connect('status-changed', self._on__status_changed)
Beispiel #13
0
    def test_pixbuf(self):
        btn = StatusButton()

        manager = ResourceStatusManager.get_instance()
        for status, stock in [
            (ResourceStatus.STATUS_NA, STOQ_STATUS_NA),
            (ResourceStatus.STATUS_OK, STOQ_STATUS_OK),
            (ResourceStatus.STATUS_WARNING, STOQ_STATUS_WARNING),
            (ResourceStatus.STATUS_ERROR, STOQ_STATUS_ERROR)
        ]:
            pixbuf = btn.render_icon(stock, Gtk.IconSize.MENU)
            with contextlib.nested(
                    mock.patch.object(btn, 'render_icon'),
                    mock.patch.object(btn._image,
                                      'set_from_pixbuf')) as (ri, sfp):
                ri.return_value = pixbuf

                manager.emit('status-changed', status)

                self.assertCalledOnceWith(ri, stock, Gtk.IconSize.MENU)
                self.assertCalledOnceWith(sfp, pixbuf)
Beispiel #14
0
    def test_pixbuf(self):
        btn = StatusButton()

        icon_map = {
            ResourceStatus.STATUS_NA: 'stoq-status-na',
            ResourceStatus.STATUS_OK: 'stoq-status-ok',
            ResourceStatus.STATUS_WARNING: 'stoq-status-warning',
            ResourceStatus.STATUS_ERROR: 'stoq-status-error',
        }

        manager = ResourceStatusManager.get_instance()
        for status, stock in [
            (ResourceStatus.STATUS_NA, STOQ_STATUS_NA),
            (ResourceStatus.STATUS_OK, STOQ_STATUS_OK),
            (ResourceStatus.STATUS_WARNING, STOQ_STATUS_WARNING),
            (ResourceStatus.STATUS_ERROR, STOQ_STATUS_ERROR)
        ]:
            with contextlib.nested(
                    mock.patch.object(btn._image,
                                      'set_from_icon_name')) as (sfp, ):
                manager.emit('status-changed', status)
                self.assertCalledOnceWith(sfp, icon_map[status],
                                          Gtk.IconSize.MENU)
Beispiel #15
0
    def test_handle_action_threaded(self, ProgressDialog):
        ProgressDialog.return_value = mock.Mock()

        dialog = StatusDialog()
        manager = ResourceStatusManager.get_instance()

        action = ResourceStatusAction(Settable(label='baz'),
                                      'foo',
                                      'bar',
                                      lambda: None,
                                      threaded=True)
        with mock.patch.object(manager, 'handle_action') as handle_action:
            t = mock.Mock()
            t.is_alive.return_value = False

            handle_action.return_value = t
            dialog._handle_action(action)

            self.assertCalledOnceWith(handle_action, action)
            self.assertCalledOnceWith(
                ProgressDialog,
                'Executing "bar". This might take a while...',
                pulse=True)
Beispiel #16
0
    def test_pixbuf(self):
        btn = StatusButton()

        manager = ResourceStatusManager.get_instance()
        for status, stock in [
                (ResourceStatus.STATUS_NA,
                 STOQ_STATUS_NA),
                (ResourceStatus.STATUS_OK,
                 STOQ_STATUS_OK),
                (ResourceStatus.STATUS_WARNING,
                 STOQ_STATUS_WARNING),
                (ResourceStatus.STATUS_ERROR,
                 STOQ_STATUS_ERROR)]:
            pixbuf = btn.render_icon(stock, gtk.ICON_SIZE_MENU)
            with contextlib.nested(
                    mock.patch.object(btn, 'render_icon'),
                    mock.patch.object(btn._image, 'set_from_pixbuf')) as (ri, sfp):
                ri.return_value = pixbuf

                manager.emit('status-changed', status)

                self.assertCalledOnceWith(ri, stock, gtk.ICON_SIZE_MENU)
                self.assertCalledOnceWith(sfp, pixbuf)