~launchpad-pqm/launchpad/devel

14032.1.1 by Raphael Badin
Add TxLongPollServer.
1
# Copyright 2011 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
4
"""Tests for lp.services.rabbit.TxLongPollServer."""
5
6
__metaclass__ = type
7
8
from ConfigParser import SafeConfigParser
14032.2.5 by Raphael Badin
Poke in the right path for txlongpoll binary.
9
import os
14032.1.1 by Raphael Badin
Add TxLongPollServer.
10
from StringIO import StringIO
11
14032.2.5 by Raphael Badin
Poke in the right path for txlongpoll binary.
12
from canonical.config import config
14032.1.2 by Raphael Badin
Don't use RabbitServer in TxLongPollServer.
13
from canonical.testing.layers import RabbitMQLayer
14032.1.1 by Raphael Badin
Add TxLongPollServer.
14
from lp.services.txlongpoll.server import TxLongPollServer
15
from lp.testing import TestCase
16
17
18
class TestTxLongPollServer(TestCase):
19
14032.1.2 by Raphael Badin
Don't use RabbitServer in TxLongPollServer.
20
    layer = RabbitMQLayer
14032.1.1 by Raphael Badin
Add TxLongPollServer.
21
22
    def test_service_config(self):
14032.2.6 by Raphael Badin
Poke the config into an attribute.
23
        # TxLongPollServer pokes some .ini configuration into its
24
        # service_config attributes.
14098.1.1 by Gavin Panella
Depend on txlongpoll 0.2.8 and txlongpollfixture 0.1.3.
25
        twistd_bin = os.path.join(
26
            config.root, 'bin', 'twistd-for-txlongpoll')
14032.1.1 by Raphael Badin
Add TxLongPollServer.
27
        fixture = self.useFixture(TxLongPollServer(
28
            broker_user='guest', broker_password='guest', broker_vhost='/',
14032.2.5 by Raphael Badin
Poke in the right path for txlongpoll binary.
29
            broker_port=123, frontend_port=None,
14098.1.1 by Gavin Panella
Depend on txlongpoll 0.2.8 and txlongpollfixture 0.1.3.
30
            twistd_bin=twistd_bin))
14032.1.1 by Raphael Badin
Add TxLongPollServer.
31
        service_config = SafeConfigParser()
14032.2.6 by Raphael Badin
Poke the config into an attribute.
32
        service_config.readfp(StringIO(getattr(fixture, 'service_config')))
14032.1.5 by Raphael Badin
Fix generated configuration.
33
        self.assertEqual(["txlongpoll"], service_config.sections())
14032.1.1 by Raphael Badin
Add TxLongPollServer.
34
        # txlongpoll section
35
        expected = {
14032.2.6 by Raphael Badin
Poke the config into an attribute.
36
            "frontend_port": "%d" % fixture.config.frontend_port,
14032.1.1 by Raphael Badin
Add TxLongPollServer.
37
            }
38
        observed = dict(service_config.items("txlongpoll"))
39
        self.assertEqual(expected, observed)