~ubuntu-branches/ubuntu/utopic/maas/utopic-security

« back to all changes in this revision

Viewing changes to src/maastesting/tests/test_matchers.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez, Jeroen Vermeulen, Andres Rodriguez, Jason Hobbs, Raphaël Badin, Louis Bouchard, Gavin Panella
  • Date: 2014-08-21 19:36:30 UTC
  • mfrom: (1.3.1)
  • Revision ID: package-import@ubuntu.com-20140821193630-kertpu5hd8yyss8h
Tags: 1.7.0~beta7+bzr3266-0ubuntu1
* New Upstream Snapshot, Beta 7 bzr3266

[ Jeroen Vermeulen ]
* debian/extras/99-maas-sudoers
  debian/maas-dhcp.postinst
  debian/rules
  - Add second DHCP server instance for IPv6.
* debian/maas-region-controller-min.install
  debian/maas-region-controller-min.lintian-overrides
  - Install deployment user-data: maas_configure_interfaces.py script.
* debian/maas-cluster-controller.links
  debian/maas-cluster-controller.install
  debian/maas-cluster-controller.postinst
  - Reflect Celery removal changes made in trunk r3067.
  - Don't install celeryconfig_cluster.py any longer. 
  - Don't install maas_local_celeryconfig_cluster.py any longer.
  - Don't symlink maas_local_celeryconfig_cluster.py from /etc to /usr.
  - Don't insert UUID into maas_local_celeryconfig_cluster.py.

[ Andres Rodriguez ]
* debian/maas-region-controller-min.postrm: Cleanup lefover files.
* debian/maas-dhcp.postrm: Clean leftover configs.
* Provide new maas-proxy package that replaces the usage of
  squid-deb-proxy:
  - debian/control: New maas-proxy package that replaces the usage
    of squid-deb-proxy; Drop depends on squid-deb-proxy.
  - Add upstrart job.
  - Ensure squid3 is stopped as maas-proxy uses a caching proxy.
* Remove Celery references to cluster controller:
  - Rename upstart job from maas-pserv to maas-cluster; rename
    maas-cluster-celery to maas-cluster-register. Ensure services
    are stopped on upgrade.
  - debian/maintscript: Cleanup config files.
  - Remove all references to the MAAS celery daemon and config
    files as we don't use it like that anymore
* Move some entries in debian/maintscript to
  debian/maas-cluster-controller.maintscript
* Remove usage of txlongpoll and rabbitmq-server. Handle upgrades
  to ensure these are removed correctly.

[ Jason Hobbs ]
* debian/maas-region-controller-min.install: Install
  maas-generate-winrm-cert script.

[ Raphaël Badin ]
* debian/extras/maas-region-admin: Bypass django-admin as it prints
  spurious messages to stdout (LP: #1365130).

[Louis Bouchard]
* debian/maas-cluster-controller.postinst:
  - Exclude /var/log/maas/rsyslog when changing ownership
    (LP: #1346703)

[Gavin Panella]
* debian/maas-cluster-controller.maas-clusterd.upstart:
  - Don't start-up the cluster controller unless a shared-secret has
    been installed.
* debian/maas-cluster-controller.maas-cluster-register.upstart: Drop.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
__all__ = []
16
16
 
17
17
from maastesting import matchers
 
18
from maastesting.factory import factory
18
19
from maastesting.matchers import (
 
20
    HasAttribute,
19
21
    IsCallable,
 
22
    IsCallableMock,
 
23
    IsFiredDeferred,
 
24
    IsUnfiredDeferred,
20
25
    MockAnyCall,
21
26
    MockCalledOnceWith,
22
27
    MockCalledWith,
26
31
from maastesting.testcase import MAASTestCase
27
32
from mock import (
28
33
    call,
 
34
    create_autospec,
29
35
    Mock,
 
36
    NonCallableMock,
30
37
    sentinel,
31
38
    )
32
39
from testtools.matchers import (
33
40
    MatchesStructure,
34
41
    Mismatch,
35
42
    )
 
43
from twisted.internet import defer
36
44
 
37
45
 
38
46
class TestIsCallable(MAASTestCase):
222
230
    def test_has_useful_string_representation(self):
223
231
        matcher = MockNotCalled()
224
232
        self.assertEqual("MockNotCalled", matcher.__str__())
 
233
 
 
234
 
 
235
class TestHasAttribute(MAASTestCase, MockTestMixin):
 
236
 
 
237
    def test__returns_none_if_attribute_exists(self):
 
238
        attribute = factory.make_string(3, prefix="attr")
 
239
        setattr(self, attribute, factory.make_name("value"))
 
240
        matcher = HasAttribute(attribute)
 
241
        result = matcher.match(self)
 
242
        self.assertIsNone(result)
 
243
 
 
244
    def test__returns_mismatch_if_attribute_does_not_exist(self):
 
245
        attribute = factory.make_string(3, prefix="attr")
 
246
        matcher = HasAttribute(attribute)
 
247
        result = matcher.match(self)
 
248
        self.assertMismatch(
 
249
            result, " does not have a %r attribute" % attribute)
 
250
 
 
251
 
 
252
class TestIsCallableMock(MAASTestCase, MockTestMixin):
 
253
 
 
254
    def test__returns_none_when_its_a_callable_mock(self):
 
255
        mock = Mock()
 
256
        matcher = IsCallableMock()
 
257
        result = matcher.match(mock)
 
258
        self.assertIsNone(result)
 
259
 
 
260
    def test__returns_none_when_its_a_callable_autospec(self):
 
261
        mock = create_autospec(lambda: None)
 
262
        matcher = IsCallableMock()
 
263
        result = matcher.match(mock)
 
264
        self.assertIsNone(result)
 
265
 
 
266
    def test__returns_mismatch_when_its_a_non_callable_mock(self):
 
267
        mock = NonCallableMock()
 
268
        matcher = IsCallableMock()
 
269
        result = matcher.match(mock)
 
270
        self.assertMismatch(
 
271
            result, " is not callable")
 
272
 
 
273
    def test__returns_mismatch_when_its_a_non_callable_autospec(self):
 
274
        mock = create_autospec(None)
 
275
        matcher = IsCallableMock()
 
276
        result = matcher.match(mock)
 
277
        self.assertMismatch(
 
278
            result, " is not callable")
 
279
 
 
280
    def test__returns_mismatch_when_its_a_non_callable_object(self):
 
281
        matcher = IsCallableMock()
 
282
        result = matcher.match(object())
 
283
        self.assertMismatch(
 
284
            result, " is not callable")
 
285
 
 
286
 
 
287
class TestIsFiredDeferred(MAASTestCase, MockTestMixin):
 
288
 
 
289
    def test__matches_fired_deferred(self):
 
290
        d = defer.Deferred()
 
291
        d.callback(None)
 
292
        self.assertThat(d, IsFiredDeferred())
 
293
 
 
294
    def test__does_not_match_unfired_deferred(self):
 
295
        d = defer.Deferred()
 
296
        self.assertMismatch(
 
297
            IsFiredDeferred().match(d),
 
298
            " has not been called")
 
299
 
 
300
    def test__does_not_match_non_deferred(self):
 
301
        self.assertMismatch(
 
302
            IsFiredDeferred().match(object()),
 
303
            " is not a Deferred")
 
304
 
 
305
 
 
306
class TestIsUnfiredDeferred(MAASTestCase, MockTestMixin):
 
307
 
 
308
    def test__matches_unfired_deferred(self):
 
309
        d = defer.Deferred()
 
310
        self.assertThat(d, IsUnfiredDeferred())
 
311
 
 
312
    def test__does_not_match_fired_deferred(self):
 
313
        d = defer.Deferred()
 
314
        d.callback(None)
 
315
        self.assertMismatch(
 
316
            IsUnfiredDeferred().match(d),
 
317
            " has been called (result=None)")
 
318
 
 
319
    def test__does_not_match_non_deferred(self):
 
320
        self.assertMismatch(
 
321
            IsUnfiredDeferred().match(object()),
 
322
            " is not a Deferred")