File: test_mediaserver.py

package info (click to toggle)
quodlibet 4.6.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 18,016 kB
  • sloc: python: 85,817; sh: 385; xml: 110; makefile: 91
file content (75 lines) | stat: -rw-r--r-- 2,176 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Copyright 2013 Christoph Reiter
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

from gi.repository import Gtk

try:
    import dbus
except ImportError:
    dbus = None

from tests import skipUnless
from tests.plugin import PluginTestCase, init_fake_app, destroy_fake_app

from quodlibet import config


@skipUnless(dbus, "no dbus module")
class TMediaServer(PluginTestCase):

    def setUp(self):
        config.init()
        init_fake_app()

        self.plugin = self.plugins["mediaserver"].cls
        self.m = self.plugin()
        self.m.enabled()
        self._replies = []
        self._args = {
            "reply_handler": self._reply,
            "error_handler": self._error
        }

    def tearDown(self):
        bus = dbus.SessionBus()
        self.failUnless(
            bus.name_has_owner("org.gnome.UPnP.MediaServer2.QuodLibet"))
        self.m.disabled()
        self.failIf(
            bus.name_has_owner("org.gnome.UPnP.MediaServer2.QuodLibet"))
        del self.m

        destroy_fake_app()
        config.quit()

    def _reply(self, *args):
        self._replies.append(args)

    def _error(self, *args):
        self.failIf(args)

    def _wait(self):
        while not self._replies:
            Gtk.main_iteration_do(False)
        return self._replies.pop(0)

    def _entry_props_iface(self):
        bus = dbus.SessionBus()
        obj = bus.get_object("org.gnome.UPnP.MediaServer2.QuodLibet",
                             "/org/gnome/UPnP/MediaServer2/QuodLibet")
        return dbus.Interface(
            obj, dbus_interface="org.freedesktop.DBus.Properties")

    def test_entry_name(self):
        iface = self._entry_props_iface()
        iface.Get("org.gnome.UPnP.MediaObject2", "DisplayName", **self._args)
        self.failUnless("Quod Libet" in self._wait()[0])

    def test_name_owner(self):
        bus = dbus.SessionBus()
        self.failUnless(
            bus.name_has_owner("org.gnome.UPnP.MediaServer2.QuodLibet"))