1
"""Test the desktopcouch service."""
6
from mocker import MockerTestCase, ANY
8
from desktopcouch.application.service import (
11
logging.basicConfig(level=logging.ERROR)
14
def set_up_logging(_):
15
""" Set logging to be silence."""
16
logging.basicConfig(level=logging.ERROR)
19
class TestService(MockerTestCase):
20
"""Test the class that manages the service."""
23
super(TestService, self).setUp()
24
# set up the dependencies used by the service object
26
self._port_result = 32323
27
self._mainloop = self.mocker.mock()
28
self._pid_finder = self.mocker.mock()
29
self._port_finder = self.mocker.mock()
30
self._ctx = self.mocker.mock()
31
self._stop_couchdb = self.mocker.mock()
32
self._fork = self.mocker.mock()
33
self._nice = self.mocker.mock()
34
self._kill = self.mocker.mock()
35
self._sleep = self.mocker.mock()
36
self._replication = self.mocker.mock()
37
self._advertiser = self.mocker.mock()
38
self._resources = self.mocker.mock()
39
self._service = DesktopcouchService(self._mainloop,
40
pid_finder=self._pid_finder,
41
port_finder=self._port_finder,
43
stop_couchdb=self._stop_couchdb,
44
replication_actions=self._replication,
45
advertiser_factory=self._advertiser,
46
set_logging=set_up_logging,
52
def test_start_new_desktopcouch_no_extensions(self):
53
"""Test that desktopcouch is started.
55
We test that when the pid cannot be found we ensure
56
that the desktopcouch instance is started and that the
57
start as the dbus service,
59
self._pid_finder(start_if_not_running=False, ctx=self._ctx)
60
self.mocker.result(None)
61
self._pid_finder(start_if_not_running=True, ctx=self._ctx)
62
self.mocker.result(self._pid_result)
63
self._port_finder(pid=self._pid_result, ctx=self._ctx)
64
self.mocker.result(self._port_result)
66
self.mocker.result(234)
68
self.mocker.result(234)
70
self._mainloop.stop # pylint: disable=W0104
71
self.mocker.result(ANY)
72
self._advertiser(ANY, self._ctx)
74
self._stop_couchdb(ctx=self._ctx)
75
self._kill(234, signal.SIGTERM)
77
self._kill(234, signal.SIGKILL)
81
def test_start_new_desktopcouch_extensions(self):
82
"""Test that desktopcouch is started.
84
We test that when the pid cannot be found we ensure
85
that the desktopcouch instance is started and that the
86
start as the dbus service,
88
self._pid_finder(start_if_not_running=False, ctx=self._ctx)
89
self.mocker.result(None)
90
self._pid_finder(start_if_not_running=True, ctx=self._ctx)
91
self.mocker.result(self._pid_result)
92
self._port_finder(pid=self._pid_result, ctx=self._ctx)
93
self.mocker.result(self._port_result)
95
self.mocker.result(234)
97
self.mocker.result(234)
99
self._mainloop.stop # pylint: disable=W0104
100
self.mocker.result(ANY)
101
self._advertiser(ANY, self._ctx)
103
self._stop_couchdb(ctx=self._ctx)
104
self._kill(234, signal.SIGTERM)
106
self._kill(234, signal.SIGKILL)
108
self._service.start()
110
def test_start_desktopcouch_replication(self):
111
""" Test that the repliciation works.
113
We test that when desktopcouch is already running we
114
will not start it again and we will perform the replication.
116
self._pid_finder(start_if_not_running=False, ctx=self._ctx)
117
self.mocker.result(self._pid_result)
118
self._port_finder(pid=self._pid_result, ctx=self._ctx)
119
self.mocker.result(self._port_result)
121
self.mocker.result(0)
123
self._replication.set_up(ANY)
126
self._service.start()
128
def test_start_migrate_data(self):
129
"""Test that desktopcouch is started.
131
We test that when the pid cannot be found we ensure
132
that the desktopcouch instance is started and that the
133
start as the dbus service,
135
self._pid_finder(start_if_not_running=False, ctx=self._ctx)
136
self.mocker.result(None)
137
self._pid_finder(start_if_not_running=True, ctx=self._ctx)
138
self.mocker.result(self._pid_result)
139
self._port_finder(pid=self._pid_result, ctx=self._ctx)
140
self.mocker.result(self._port_result)
142
self.mocker.result(567)
144
self.mocker.result(0)
147
self._service.start()