~lutostag/ubuntu/trusty/maas/1.5.2+packagefix

« back to all changes in this revision

Viewing changes to src/maasserver/rpc/tests/test_module.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2014-03-28 10:43:53 UTC
  • mto: This revision was merged to the branch mainline in revision 57.
  • Revision ID: package-import@ubuntu.com-20140328104353-ekpolg0pm5xnvq2s
Tags: upstream-1.5+bzr2204
ImportĀ upstreamĀ versionĀ 1.5+bzr2204

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2014 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Tests for the top-level region RPC API."""
 
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 crochet import wait_for_reactor
 
18
from maasserver import (
 
19
    eventloop,
 
20
    rpc,
 
21
    )
 
22
from maastesting.matchers import MockCalledOnceWith
 
23
from maastesting.testcase import MAASTestCase
 
24
from mock import sentinel
 
25
from provisioningserver.rpc import exceptions
 
26
from testtools.matchers import (
 
27
    Equals,
 
28
    Is,
 
29
    )
 
30
 
 
31
 
 
32
class TestFunctions(MAASTestCase):
 
33
 
 
34
    @wait_for_reactor
 
35
    def test_getClientFor_service_not_running(self):
 
36
        self.assertRaises(
 
37
            exceptions.NoConnectionsAvailable,
 
38
            rpc.getClientFor, sentinel.uuid)
 
39
 
 
40
    @wait_for_reactor
 
41
    def test_getClientFor(self):
 
42
        getServiceNamed = self.patch(eventloop.services, "getServiceNamed")
 
43
        getClientFor = getServiceNamed.return_value.getClientFor
 
44
        getClientFor.return_value = sentinel.client
 
45
        self.assertThat(getClientFor(sentinel.uuid), Is(sentinel.client))
 
46
        self.assertThat(getClientFor, MockCalledOnceWith(sentinel.uuid))
 
47
 
 
48
    @wait_for_reactor
 
49
    def test_getAllClients_service_not_running(self):
 
50
        self.assertThat(rpc.getAllClients(), Equals([]))
 
51
 
 
52
    @wait_for_reactor
 
53
    def test_getAllClients(self):
 
54
        getServiceNamed = self.patch(eventloop.services, "getServiceNamed")
 
55
        getAllClients = getServiceNamed.return_value.getAllClients
 
56
        getAllClients.return_value = sentinel.clients
 
57
        self.assertThat(getAllClients(), Is(sentinel.clients))
 
58
        self.assertThat(getAllClients, MockCalledOnceWith())