~townsend/libertine/1.4.3-release

« back to all changes in this revision

Viewing changes to tests/unit/test_launcher_with_dbus.py

  • Committer: Chris Townsend
  • Author(s): Chris Townsend, Larry Price, Stephen M. Webb
  • Date: 2016-10-31 17:20:44 UTC
  • mfrom: (94.157.50 devel)
  • Revision ID: christopher.townsend@canonical.com-20161031172044-74b8604iab6nw1t2
* Use libertine-lxc-manager when starting/stopping a container for libertine-container-manager operations if the session DBus is available.  If not, fallback to l-c-m starting/stopping the container. (LP: #1628587)
* Add a new entry to ContainersConfig for keeping track of running processes in a container. (LP: #1632729)
* libertine-launch: refactored core components of application session management.
* Split out Xmir helper apps into their own package.
* Add support for starting pasted and matchbox for snap based/ containerless apps in U8. (LP: #1637535)
* Add implementation for libertine gui as a system-settings plugin. (LP: #1623946)
* Manually require archive name during archive configuration.
* Add a warning to the top of ContainersConfig.json advising users not to edit the file.
* Missing error dialogs in PackageInfoView when fetching version results in an error.
* Avoid searching for apps based on empty directories.
* Bump version to 1.4.3. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2016 Canonical Ltd.
 
2
#
 
3
# This program is free software: you can redistribute it and/or modify it
 
4
# under the terms of the GNU General Public License version 3, as published
 
5
# by the Free Software Foundation.
 
6
#
 
7
# This program is distributed in the hope that it will be useful, but
 
8
# WITHOUT ANY WARRANTY; without even the implied warranties of
 
9
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
10
# PURPOSE.  See the GNU General Public License for more details.
 
11
#
 
12
# You should have received a copy of the GNU General Public License along
 
13
# with this program.  If not, see <http://www.gnu.org/licenses/>.
 
14
 
 
15
import dbus
 
16
import dbusmock
 
17
import os
 
18
import subprocess
 
19
 
 
20
from libertine import launcher
 
21
 
 
22
from testtools import TestCase
 
23
from testtools.matchers import Equals, Contains
 
24
from unittest.mock import patch
 
25
 
 
26
 
 
27
 
 
28
class MockDBusServer(object):
 
29
    """
 
30
    A mock object that proxies a mock D-Bus server, for testing things that do
 
31
    D-Bus operations in the background.
 
32
    """
 
33
 
 
34
    def __init__(self, maliit_server_address):
 
35
        dbusmock.DBusTestCase.start_session_bus()
 
36
        self.maliit_server_address = maliit_server_address
 
37
        self._dbus_connection = dbusmock.DBusTestCase.get_dbus(system_bus=False)
 
38
 
 
39
    def setUp(self):
 
40
        self._dbus_mock_server = dbusmock.DBusTestCase.spawn_server(
 
41
                'org.maliit.server',
 
42
                '/org/maliit/server/address',
 
43
                'org.maliit.Server.Address',
 
44
                system_bus=False,
 
45
                stdout=subprocess.PIPE)
 
46
        self._mock_interface = self._get_mock_interface()
 
47
        self._mock_interface.AddProperty('', 'address', self.maliit_server_address)
 
48
 
 
49
    def cleanUp(self):
 
50
        self._dbus_mock_server.terminate()
 
51
        self._dbus_mock_server.wait()
 
52
 
 
53
    def getDetails(self):
 
54
        return { }
 
55
 
 
56
    def _get_mock_interface(self):
 
57
        return dbus.Interface(
 
58
                self._dbus_connection.get_object(
 
59
                    'org.maliit.server',
 
60
                    '/org/maliit/server/address',
 
61
                    'org.maliit.Server.Address'),
 
62
                dbusmock.MOCK_IFACE)
 
63
 
 
64
 
 
65
class TestLauncherConfigUsingDBus(TestCase):
 
66
    """
 
67
    Verifies the defined behaviour of the Libertine Launcher Config class with
 
68
    reference to a D-Bus server.
 
69
    """
 
70
    def setUp(self):
 
71
        """
 
72
        Need to save and restore the os.environ for each test in case they
 
73
        change things.  That's a global that propagates between tests.
 
74
        """
 
75
        super().setUp()
 
76
        fake_maliit_host_address = 'unix:abstract=/tmp/maliit-host-socket'
 
77
        self._dbus_server = self.useFixture(MockDBusServer(maliit_server_address=fake_maliit_host_address))
 
78
        self._cli = [ '-i', self.getUniqueString(), self.getUniqueString() ]
 
79
 
 
80
    def test_maliit_socket_bridge_from_dbus(self):
 
81
        """
 
82
        Make sure the Maliit socket bridge gets configured.
 
83
 
 
84
        The Maliit service advertizes it's socket on the D-Bus, although the
 
85
        environment variable, if present, overrides that so to test the D-Bus
 
86
        advert the environment variable must be clear.
 
87
        """
 
88
        maliit_bridge = None
 
89
        with patch.dict('os.environ'):
 
90
            if 'MALIIT_SERVER_ADDRESS' in os.environ:
 
91
                del os.environ['MALIIT_SERVER_ADDRESS']
 
92
 
 
93
            config = launcher.Config(self._cli[:])
 
94
 
 
95
            for bridge in config.socket_bridges:
 
96
                if bridge.env_var == 'MALIIT_SERVER_ADDRESS':
 
97
                    maliit_bridge = bridge
 
98
 
 
99
            self.assertIsNotNone(maliit_bridge)
 
100
            self.assertThat(maliit_bridge.host_address, Equals(self._dbus_server.maliit_server_address))
 
101
            self.assertThat(maliit_bridge.session_address, Contains('maliit'))
 
102
            self.assertThat(maliit_bridge.session_address, Contains(config.id))
 
103