← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~allenap/maas/rabbit-resource into lp:maas

 

Gavin Panella has proposed merging lp:~allenap/maas/rabbit-resource into lp:maas.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~allenap/maas/rabbit-resource/+merge/89703
-- 
https://code.launchpad.net/~allenap/maas/rabbit-resource/+merge/89703
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~allenap/maas/rabbit-resource into lp:maas.
=== modified file 'buildout.cfg'
--- buildout.cfg	2012-01-20 15:54:20 +0000
+++ buildout.cfg	2012-01-23 15:29:42 +0000
@@ -6,10 +6,11 @@
   sphinx
 versions = versions
 extra-paths =
-  ${buildout:directory}/src/
-  ${buildout:directory}/src/maas/
-  ${buildout:directory}/src/maasserver/
+  ${buildout:directory}/src
 include-site-packages = false
+# Don't always check for newer packages; use `bin/buildout -n` to
+# override this and check explicitly.
+newest = false
 
 [versions]
 django = 1.3.1
@@ -38,7 +39,9 @@
   testtools
 project = maas
 projectegg = maas
-test = maasserver
+test =
+  maasserver
+  maastesting
 extra-paths = ${buildout:extra-paths}
 
 [django-python]

=== modified file 'setup.py'
--- setup.py	2012-01-23 15:03:25 +0000
+++ setup.py	2012-01-23 15:29:42 +0000
@@ -9,9 +9,13 @@
 
 """Distutils installer for maas."""
 
-import os
+from os.path import (
+    dirname,
+    join,
+    )
 
 import distribute_setup
+
 # The version of distribute packaged in precise is not quite at 0.6.24
 # final yet so we need to override the required version here to stop a
 # recipe build from trying to download from pypi.
@@ -23,8 +27,12 @@
     )
 
 
-def read(fname):
-    return open(os.path.join(os.path.dirname(__file__), fname)).read().strip()
+def read(filename):
+    """Return the whitespace-stripped content of `filename`."""
+    path = join(dirname(__file__), filename)
+    with open(path, "rb") as fin:
+        return fin.read().strip()
+
 
 __version__ = "0.1"
 

=== modified file 'src/maas/development.py'
--- src/maas/development.py	2012-01-20 09:26:53 +0000
+++ src/maas/development.py	2012-01-23 15:29:42 +0000
@@ -16,7 +16,7 @@
 
 # Use our custom test runner, which makes sure that a local database
 # cluster is running in the branch.
-TEST_RUNNER = 'maas.testing.runner.TestRunner'
+TEST_RUNNER = 'maastesting.runner.TestRunner'
 
 # Location where python-oops should store errors.
 OOPS_REPOSITORY = 'logs'
@@ -162,6 +162,7 @@
     'django.contrib.admin',
     'django.contrib.admindocs',
     'maasserver',
+    'maastesting',
     'debug_toolbar',
 )
 

=== modified file 'src/maasserver/tests/__init__.py'
--- src/maasserver/tests/__init__.py	2012-01-19 13:56:36 +0000
+++ src/maasserver/tests/__init__.py	2012-01-23 15:29:42 +0000
@@ -11,8 +11,8 @@
 
 from os.path import dirname
 
-from django.utils.unittest import defaultTestLoader
+from django.utils.unittest import TestLoader
 
 
 def suite():
-    return defaultTestLoader.discover(dirname(__file__))
+    return TestLoader().discover(dirname(__file__))

=== modified file 'src/maasserver/tests/test_api.py'
--- src/maasserver/tests/test_api.py	2012-01-19 15:33:19 +0000
+++ src/maasserver/tests/test_api.py	2012-01-23 15:29:42 +0000
@@ -13,12 +13,12 @@
 
 import json
 
-from maas.testing import TestCase
 from maasserver.models import (
     MACAddress,
     Node,
     )
 from maasserver.testing.factory import factory
+from maastesting import TestCase
 
 
 class NodeAPITest(TestCase):

=== modified file 'src/maasserver/tests/test_macaddressfield.py'
--- src/maasserver/tests/test_macaddressfield.py	2012-01-19 13:56:36 +0000
+++ src/maasserver/tests/test_macaddressfield.py	2012-01-23 15:29:42 +0000
@@ -12,10 +12,10 @@
 __all__ = []
 
 from django.core.exceptions import ValidationError
-from maas.testing import TestCase
 from maasserver.macaddress import validate_mac
 from maasserver.models import MACAddress
 from maasserver.testing.factory import factory
+from maastesting import TestCase
 
 
 class TestMACAddressField(TestCase):

=== modified file 'src/maasserver/tests/test_models.py'
--- src/maasserver/tests/test_models.py	2012-01-19 13:56:36 +0000
+++ src/maasserver/tests/test_models.py	2012-01-23 15:29:42 +0000
@@ -12,11 +12,11 @@
 __all__ = []
 
 from django.core.exceptions import ValidationError
-from maas.testing import TestCase
 from maasserver.models import (
     MACAddress,
     Node,
     )
+from maastesting import TestCase
 
 
 class NodeTest(TestCase):

=== renamed directory 'src/maas/testing' => 'src/maastesting'
=== added file 'src/maastesting/models.py'
=== added file 'src/maastesting/rabbit.py'
--- src/maastesting/rabbit.py	1970-01-01 00:00:00 +0000
+++ src/maastesting/rabbit.py	2012-01-23 15:29:42 +0000
@@ -0,0 +1,65 @@
+# Copyright 2012 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+from __future__ import (
+    print_function,
+    unicode_literals,
+    )
+
+"""Helpers for testing with RabbitMQ."""
+
+__metaclass__ = type
+__all__ = [
+    "RabbitServerResource",
+    ]
+
+from rabbitfixture.server import RabbitServer
+from testresources import TestResource
+
+
+class RabbitServerResource(TestResource):
+    """A `TestResource` that wraps a `RabbitServer`.
+
+    :ivar server: A `RabbitServer`.
+    """
+
+    def __init__(self, config=None):
+        """See `TestResource.__init__`.
+
+        :param config: An optional instance of
+            `rabbitfixture.server.RabbitServerResources`.
+        """
+        super(RabbitServerResource, self).__init__()
+        self.server = RabbitServer(config)
+
+    def clean(self, resource):
+        """See `TestResource.clean`."""
+        resource.cleanUp()
+
+    def make(self, dependency_resources):
+        """See `TestResource.make`."""
+        self.server.setUp()
+        return self.server
+
+    def isDirty(self):
+        """See `TestResource.isDirty`.
+
+        Always returns ``True`` because it's difficult to figure out if an
+        `RabbitMQ` server has been used, and it will be very quick to reset
+        once we have the management plugin.
+
+        Also, somewhat confusingly, `testresources` uses `self._dirty` to
+        figure out whether or not to recreate the resource in `self.reset`.
+        That's only set by calling `self.dirtied`, which is fiddly from a
+        test. For now we assume that it doesn't matter if it's dirty or not;
+        tests need to ensure they're using uniquely named queues and/or
+        exchanges, or explicity purge things during set-up.
+        """
+        return True
+
+    def reset(self, old_resource, result=None):
+        """See `TestResource.reset`."""
+        # XXX: GavinPanella 2011-01-20 bug=???: When it becomes possible to
+        # install rabbitmq-management on Precise this could be changed to
+        # properly reset the running server.
+        return super(RabbitServerResource, self).reset(old_resource, result)

=== added directory 'src/maastesting/tests'
=== added file 'src/maastesting/tests/__init__.py'
--- src/maastesting/tests/__init__.py	1970-01-01 00:00:00 +0000
+++ src/maastesting/tests/__init__.py	2012-01-23 15:29:42 +0000
@@ -0,0 +1,18 @@
+# Copyright 2012 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+from __future__ import (
+    print_function,
+    unicode_literals,
+    )
+
+__metaclass__ = type
+__all__ = []
+
+from os.path import dirname
+
+from django.utils.unittest import TestLoader
+
+
+def suite():
+    return TestLoader().discover(dirname(__file__))

=== added file 'src/maastesting/tests/test_rabbit.py'
--- src/maastesting/tests/test_rabbit.py	1970-01-01 00:00:00 +0000
+++ src/maastesting/tests/test_rabbit.py	2012-01-23 15:29:42 +0000
@@ -0,0 +1,60 @@
+# Copyright 2012 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+from __future__ import (
+    print_function,
+    unicode_literals,
+    )
+
+"""Tests for `maastesting.rabbit`."""
+
+__metaclass__ = type
+__all__ = []
+
+from maastesting import TestCase
+from maastesting.rabbit import RabbitServerResource
+from rabbitfixture.server import RabbitServer
+
+
+class TestRabbitServerResourceBasics(TestCase):
+
+    def test_cycle(self):
+        """
+        A RabbitMQ server can be successfully brought up and shut-down.
+        """
+        resource = RabbitServerResource()
+        server = resource.make({})
+        try:
+            self.assertIs(resource.server, server)
+            self.assertIsInstance(server, RabbitServer)
+        finally:
+            resource.clean(server)
+
+    def test_reset(self):
+        """
+        Resetting a RabbitMQ server resource when it has not explicitly been
+        marked as dirty - via `RabbitServerResource.dirtied` - is a no-op; the
+        same server is returned.
+        """
+        resource = RabbitServerResource()
+        server = resource.make({})
+        try:
+            server2 = resource.reset(server)
+            self.assertIs(server, server2)
+        finally:
+            resource.clean(server)
+
+
+class TestRabbitServerResource(TestCase):
+
+    resources = [
+        ("rabbit", RabbitServerResource()),
+        ]
+
+    def test_one(self):
+        """The `self.rabbit` resource is made available here."""
+        self.assertIsInstance(self.rabbit, RabbitServer)
+
+    def test_two(self):
+        """The `self.rabbit resource is also made available here."""
+        self.assertIsInstance(self.rabbit, RabbitServer)

=== modified file 'templates/test.py'
--- templates/test.py	2012-01-19 13:56:36 +0000
+++ templates/test.py	2012-01-23 15:29:42 +0000
@@ -11,7 +11,7 @@
 __metaclass__ = type
 __all__ = []
 
-from maas.testing import TestCase
+from maastesting import TestCase
 
 
 class TestSomething(TestCase):