Skip to content

Please help me mock libnotify notifications#249

Description

@mbridon

I had originally opened #230, but then due to health issues I spent a few months without ever answering @martinpitt in that issue. 馃槥

So now I did manage to to get a machine id in my CI. 馃槈

Now what I need is to mock org.freedesktop.Notifications so the tests can send notifications while there is a dbus session service running to catch those.

I think I can do that as follows:

import dbus
import dbusmock
import subprocess


class TestMyProgram(dbusmock.DBusTestCase):
    @classmethod
    def setUpClass(cls):
        cls.start_session_bus()
        cls.dbus_con = cls.get_dbus(session_bus=True)

    def setUp(self):
        self.p_mock = self.spawn_server('org.freedesktop.Notification',
                                        '/org/freedesktop/Notification',
                                        'org.freedesktop.Notification',
                                        session_bus=True,
                                        stdout=subprocess.PIPE)

        # Get a proxy for the UPower object's Mock interface
        self.dbus_notification_mock = dbus.Interface(self.dbus_con.get_object(
            'org.freedesktop.Notification', '/org/freedesktop/Notification'),
            dbusmock.MOCK_IFACE)

        self.dbus_upower_mock.AddMethod('', 'Notify', '', '', '')

    def tearDown(self):
        self.p_mock.stdout.close()
        self.p_mock.terminate()
        self.p_mock.wait()

    def test_suspend_on_idle(self):
        # That's where I suppose I can run the tests which would send notifications, right? 馃 

        # now check the log that we got one Suspend() call
        self.assertRegex(self.p_mock.stdout.readline(), b'^[0-9.]+ Suspend$')

Again, my apologies for not having given any sign of life, I'll try harder next time, I promise. 馃檱

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions