1
# Copyright 2014 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Tests for the top-level region RPC API."""
6
from __future__ import (
17
from crochet import wait_for_reactor
18
from maasserver import (
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 (
32
class TestFunctions(MAASTestCase):
35
def test_getClientFor_service_not_running(self):
37
exceptions.NoConnectionsAvailable,
38
rpc.getClientFor, sentinel.uuid)
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))
49
def test_getAllClients_service_not_running(self):
50
self.assertThat(rpc.getAllClients(), Equals([]))
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())