~ubuntu-branches/ubuntu/precise/desktopcouch/precise

« back to all changes in this revision

Viewing changes to desktopcouch/application/tests/test_service.py

  • Committer: Bazaar Package Importer
  • Author(s): Chad MILLER
  • Date: 2011-01-12 15:08:25 UTC
  • mfrom: (1.5.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20110112150825-bzvn23kzufr0qdyb
Tags: 1.0.5-0ubuntu1
* New upstream release, skipping a few buggy releases.
* Split code into binary packages:
  - desktopcouch, configuration files and dependencies, but no code.
  - python-desktopcouch: transitional package
  - python-desktopcouch-application: local DB startup and discovery
  - python-desktopcouch-records: library for DB access anywhere
  - python-desktopcouch-recordtypes: support specific data structures
  - desktopcouch-ubuntuone, replication and pairing with cloud service
* Drop patch that some maverick apps incorrectly needed.
  patches/0-items-should-expose-private-data-for-now.patch
* Update package compatibility-version, 6 -> 7.
* Use newer debhelper and use python-support instead of python-central.
* Depend on contemporary python-couchdb, instead of ancient version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Test the desktopcouch service."""
 
2
 
 
3
import logging
 
4
import signal
 
5
 
 
6
from mocker import MockerTestCase, ANY
 
7
 
 
8
from desktopcouch.application.service import (
 
9
    DesktopcouchService)
 
10
 
 
11
logging.basicConfig(level=logging.ERROR)
 
12
 
 
13
 
 
14
def set_up_logging(_):
 
15
    """ Set logging to be silence."""
 
16
    logging.basicConfig(level=logging.ERROR)
 
17
 
 
18
 
 
19
class TestService(MockerTestCase):
 
20
    """Test the class that manages the service."""
 
21
 
 
22
    def setUp(self):
 
23
        super(TestService, self).setUp()
 
24
        # set up the dependencies used by the service object
 
25
        self._pid_result = 32
 
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,
 
42
            ctx=self._ctx,
 
43
            stop_couchdb=self._stop_couchdb,
 
44
            replication_actions=self._replication,
 
45
            advertiser_factory=self._advertiser,
 
46
            set_logging=set_up_logging,
 
47
            fork=self._fork,
 
48
            nice=self._nice,
 
49
            kill=self._kill,
 
50
            sleep=self._sleep)
 
51
 
 
52
    def test_start_new_desktopcouch_no_extensions(self):
 
53
        """Test that desktopcouch is started.
 
54
 
 
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,
 
58
        """
 
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)
 
65
        self._fork()
 
66
        self.mocker.result(234)
 
67
        self._fork()
 
68
        self.mocker.result(234)
 
69
        # XXX: call this?
 
70
        self._mainloop.stop             # pylint: disable=W0104
 
71
        self.mocker.result(ANY)
 
72
        self._advertiser(ANY, self._ctx)
 
73
        self._mainloop.run()
 
74
        self._stop_couchdb(ctx=self._ctx)
 
75
        self._kill(234, signal.SIGTERM)
 
76
        self._sleep(1)
 
77
        self._kill(234, signal.SIGKILL)
 
78
        self.mocker.replay()
 
79
        self._service.start()
 
80
 
 
81
    def test_start_new_desktopcouch_extensions(self):
 
82
        """Test that desktopcouch is started.
 
83
 
 
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,
 
87
        """
 
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)
 
94
        self._fork()
 
95
        self.mocker.result(234)
 
96
        self._fork()
 
97
        self.mocker.result(234)
 
98
        # XXX: call this?
 
99
        self._mainloop.stop             # pylint: disable=W0104
 
100
        self.mocker.result(ANY)
 
101
        self._advertiser(ANY, self._ctx)
 
102
        self._mainloop.run()
 
103
        self._stop_couchdb(ctx=self._ctx)
 
104
        self._kill(234, signal.SIGTERM)
 
105
        self._sleep(1)
 
106
        self._kill(234, signal.SIGKILL)
 
107
        self.mocker.replay()
 
108
        self._service.start()
 
109
 
 
110
    def test_start_desktopcouch_replication(self):
 
111
        """ Test that the repliciation works.
 
112
 
 
113
        We test that when desktopcouch is already running we
 
114
        will not start it again and we will perform the replication.
 
115
        """
 
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)
 
120
        self._fork()
 
121
        self.mocker.result(0)
 
122
        self._nice(10)
 
123
        self._replication.set_up(ANY)
 
124
        self._mainloop.run()
 
125
        self.mocker.replay()
 
126
        self._service.start()
 
127
 
 
128
    def test_start_migrate_data(self):
 
129
        """Test that desktopcouch is started.
 
130
 
 
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,
 
134
        """
 
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)
 
141
        self._fork()
 
142
        self.mocker.result(567)
 
143
        self._fork()
 
144
        self.mocker.result(0)
 
145
 
 
146
        self.mocker.replay()
 
147
        self._service.start()
 
148