~lutostag/ubuntu/trusty/maas/1.5.4

« back to all changes in this revision

Viewing changes to src/maasserver/tests/test_views_longpoll.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2014-02-15 12:08:23 UTC
  • mto: This revision was merged to the branch mainline in revision 48.
  • Revision ID: package-import@ubuntu.com-20140215120823-u7dkitfy0h8tbruh
Tags: upstream-1.5+bzr1948
ImportĀ upstreamĀ versionĀ 1.5+bzr1948

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2013 Canonical Ltd.  This software is licensed under the
2
 
# GNU Affero General Public License version 3 (see the file LICENSE).
3
 
 
4
 
"""Longpoll-related views tests."""
5
 
 
6
 
from __future__ import (
7
 
    absolute_import,
8
 
    print_function,
9
 
    unicode_literals,
10
 
    )
11
 
 
12
 
str = None
13
 
 
14
 
__metaclass__ = type
15
 
__all__ = []
16
 
 
17
 
from unittest import skip
18
 
 
19
 
from django.conf import settings
20
 
from maasserver import messages
21
 
from maasserver.exceptions import NoRabbit
22
 
from maasserver.testing.factory import factory
23
 
from maasserver.testing.rabbit import uses_rabbit_fixture
24
 
from maasserver.testing.testcase import MAASServerTestCase
25
 
from maasserver.views.nodes import get_longpoll_context
26
 
 
27
 
 
28
 
class TestGetLongpollContext(MAASServerTestCase):
29
 
 
30
 
    def test_get_longpoll_context_empty_if_rabbitmq_publish_is_none(self):
31
 
        self.patch(settings, 'RABBITMQ_PUBLISH', None)
32
 
        messages.MESSAGING.reset()
33
 
        self.assertEqual({}, get_longpoll_context())
34
 
 
35
 
    def test_get_longpoll_context_returns_empty_if_rabbit_not_running(self):
36
 
 
37
 
        class FakeMessaging:
38
 
            """Fake :class:`RabbitMessaging`: fail with `NoRabbit`."""
39
 
 
40
 
            def getQueue(self, *args, **kwargs):
41
 
                raise NoRabbit("Pretending not to have a rabbit.")
42
 
 
43
 
        self.patch(messages.MESSAGING, '_cached_messaging', FakeMessaging())
44
 
        self.assertEqual({}, get_longpoll_context())
45
 
 
46
 
    def test_get_longpoll_context_empty_if_longpoll_url_is_None(self):
47
 
        self.patch(settings, 'LONGPOLL_PATH', None)
48
 
        messages.MESSAGING.reset()
49
 
        self.assertEqual({}, get_longpoll_context())
50
 
 
51
 
    @skip(
52
 
        "XXX: GavinPanella 2012-09-27 bug=1057250: Causes test "
53
 
        "failures in unrelated parts of the test suite.")
54
 
    @uses_rabbit_fixture
55
 
    def test_get_longpoll_context(self):
56
 
        longpoll = factory.getRandomString()
57
 
        self.patch(settings, 'LONGPOLL_PATH', longpoll)
58
 
        self.patch(settings, 'RABBITMQ_PUBLISH', True)
59
 
        messages.MESSAGING.reset()
60
 
        context = get_longpoll_context()
61
 
        self.assertItemsEqual(
62
 
            ['LONGPOLL_PATH', 'longpoll_queue'], context)
63
 
        self.assertEqual(longpoll, context['LONGPOLL_PATH'])